From 885f7cb06873ca30ed483e80816ec724399de49e Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 17 Jan 2016 16:45:12 +0100 Subject: [PATCH] fix for iterators -- should start working when py__iter__ gets fixed: https://github.com/davidhalter/jedi/pull/663\#issuecomment-172317854 --- jedi/evaluate/jedi_typing.py | 22 ++++++++++++++++++---- test/completion/pep0484_typing.py | 20 ++++++++++++++++++++ 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/jedi/evaluate/jedi_typing.py b/jedi/evaluate/jedi_typing.py index e34ee989..2fd0e0d8 100644 --- a/jedi/evaluate/jedi_typing.py +++ b/jedi/evaluate/jedi_typing.py @@ -13,7 +13,8 @@ except ImportError: def factory(typing_name, indextypes): class Iterable(abc.Iterable): def __iter__(self): - yield indextypes[0]() + while True: + yield indextypes[0]() class Iterator(Iterable, abc.Iterator): def next(self): @@ -23,10 +24,14 @@ def factory(typing_name, indextypes): def __next__(self): return indextypes[0]() - class Sequence(Iterable, abc.Sequence): + class Sequence(abc.Sequence): def __getitem__(self, index): return indextypes[0]() + def __len__(self): + import sys + return sys.maxint + class MutableSequence(Sequence, abc.MutableSequence): pass @@ -42,6 +47,13 @@ def factory(typing_name, indextypes): else: return indextypes[index]() + def __len__(self): + if indextypes[1] == ...: + import sys + return sys.maxint + else: + return len(indextypes) + class AbstractSet(Iterable, abc.Set): pass @@ -53,11 +65,13 @@ def factory(typing_name, indextypes): class ValuesView(abc.ValuesView): def __iter__(self): - yield indextypes[1]() + while True: + yield indextypes[1]() class ItemsView(abc.ItemsView): def __iter__(self): - yield Tuple() + while True: + yield Tuple() class Mapping(Iterable, abc.Mapping): def __getitem__(self, item): diff --git a/test/completion/pep0484_typing.py b/test/completion/pep0484_typing.py index 74a99e51..b3fe6055 100644 --- a/test/completion/pep0484_typing.py +++ b/test/completion/pep0484_typing.py @@ -47,6 +47,16 @@ def iterators( p #? next(ps) + a, b = ps + #? int() + a + ##? int() --- TODO fix support for tuple assignment + # https://github.com/davidhalter/jedi/pull/663#issuecomment-172317854 + # test below is just to make sure that in case it gets fixed by accident + # these tests will be fixed as well the way they should be + #? + b + for q in qs: #? str() q @@ -93,8 +103,12 @@ def tuple( #? int() i ##? str() --- TODO fix support for tuple assignment + # https://github.com/davidhalter/jedi/pull/663#issuecomment-172317854 + #? s ##? float() --- TODO fix support for tuple assignment + # https://github.com/davidhalter/jedi/pull/663#issuecomment-172317854 + #? f class Key: @@ -136,11 +150,15 @@ def mapping( #? Key() key ##? Value() --- TODO fix support for tuple assignment + # https://github.com/davidhalter/jedi/pull/663#issuecomment-172317854 + #? value for key, value in p.items(): #? Key() key ##? Value() --- TODO fix support for tuple assignment + # https://github.com/davidhalter/jedi/pull/663#issuecomment-172317854 + #? value for key in r: #? Key() @@ -152,6 +170,8 @@ def mapping( #? Key() key ##? Value() --- TODO fix support for tuple assignment + # https://github.com/davidhalter/jedi/pull/663#issuecomment-172317854 + #? value def union(