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

View File

@@ -33,7 +33,17 @@ class CheckAttribute(object):
def __get__(self, instance, owner): def __get__(self, instance, owner):
# This might raise an AttributeError. That's wanted. # 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) return partial(self.func, instance)

View File

@@ -256,6 +256,11 @@ class str():
def __init__(self, obj): def __init__(self, obj):
pass pass
def strip(self):
return str()
def split(self):
return [str()]
class type(): class type():
def mro(): def mro():

View File

@@ -237,7 +237,8 @@ class Comprehension(AbstractSequence):
@memoize_default() @memoize_default()
def _get_comp_for_context(self, parent_context, comp_for): def _get_comp_for_context(self, parent_context, comp_for):
return parent_context.create_context(comp_for) # TODO shouldn't this be part of create_context?
return CompForContext.from_comp_for(parent_context, comp_for)
def _nested(self, comp_fors, parent_context=None): def _nested(self, comp_fors, parent_context=None):
evaluator = self.evaluator evaluator = self.evaluator

View File

@@ -89,6 +89,9 @@ b = [b for arr in [[[1.0]]] for a in arr for b in a]
#? float() #? float()
b[0] b[0]
#? str()
[x for x in 'chr'][0]
# jedi issue #26 # jedi issue #26
#? list() #? list()
a = [[int(v) for v in line.strip().split() if v] for line in ["123", "123", "123"] if line] a = [[int(v) for v in line.strip().split() if v] for line in ["123", "123", "123"] if line]