1
0
forked from VimPlug/jedi

Fix python 2 string iterators.

This commit is contained in:
Dave Halter
2016-12-03 02:08:40 +01:00
parent ba8a3215f2
commit da1a163da7
4 changed files with 21 additions and 2 deletions
+11 -1
View File
@@ -33,7 +33,17 @@ class CheckAttribute(object):
def __get__(self, instance, owner):
# This might raise an AttributeError. That's wanted.
getattr(instance.obj, self.check_name)
if self.check_name == '__iter__':
# Python iterators are a bit strange, because there's no need for
# the __iter__ function as long as __getitem__ is defined (it will
# just start with __getitem__(0). This is especially true for
# Python 2 strings, where `str.__iter__` is not even defined.
try:
iter(instance.obj)
except TypeError:
raise AttributeError
else:
getattr(instance.obj, self.check_name)
return partial(self.func, instance)