diff --git a/src/pylib/builtins/list.nim b/src/pylib/builtins/list.nim index 26de3cd2c..c56f8c90e 100644 --- a/src/pylib/builtins/list.nim +++ b/src/pylib/builtins/list.nim @@ -109,6 +109,7 @@ func sorted*[T](self: PyList[T], reverse=false): PyList[T] = ## sorted(list, reverse=False) newPyList self.asSeq.sorted(order=rev2ord(reverse)) +func list*[T](x: openArray[T]): PyList[T] = newPyList @x # Impl end # the following does nothing with how PyList is implemented. diff --git a/src/pylib/collections_abc.nim b/src/pylib/collections_abc.nim index 165392473..4fc98a48b 100644 --- a/src/pylib/collections_abc.nim +++ b/src/pylib/collections_abc.nim @@ -1,11 +1,19 @@ +const SupportIteratorHit = (NimMajor, NimMinor, NimPatch) >= (2, 1, 2) type Iterable*[T] = concept self ## Mimic Pythons Iterable. But not checks `iter` #for value in self: value is T # Above may cause inner error when JS backend on older Nim T # see below - typeof(self.items, typeOfIter) is T + when SupportIteratorHit: + iterator items(self): T + else: + #typeof(self.items(), typeOfIter) is T + when defined(js): + typeof(self.items(), typeOfIter) is T + else: + for value in self: value is T Sized* = concept self len(self) is int diff --git a/tests/tset.nim b/tests/tset.nim index 4a77a440c..f58516057 100644 --- a/tests/tset.nim +++ b/tests/tset.nim @@ -3,7 +3,7 @@ test "set": def fun(): s = pyset([2, 3]) check(len(s.union([1]))==3) - check(len(s.intersection([1,2,3]))==2) + check(len(s.intersection(@[1,2,3]))==2) fun() def op(): s = pyset([2, 3])