mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 22:44:27 +08:00
Need py__bool__ on generators as well as any other object.
This commit is contained in:
@@ -69,6 +69,9 @@ class GeneratorMixin(object):
|
|||||||
"""
|
"""
|
||||||
return [self.iter_content()[index]]
|
return [self.iter_content()[index]]
|
||||||
|
|
||||||
|
def py__bool__(self):
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
class Generator(use_metaclass(CachedMetaClass, IterableWrapper, GeneratorMixin)):
|
class Generator(use_metaclass(CachedMetaClass, IterableWrapper, GeneratorMixin)):
|
||||||
"""Handling of `yield` functions."""
|
"""Handling of `yield` functions."""
|
||||||
@@ -161,6 +164,9 @@ class ArrayMixin(object):
|
|||||||
scope = self._evaluator.execute(scope, (AlreadyEvaluated((self,)),))[0]
|
scope = self._evaluator.execute(scope, (AlreadyEvaluated((self,)),))[0]
|
||||||
return scope.names_dicts(search_global)
|
return scope.names_dicts(search_global)
|
||||||
|
|
||||||
|
def py__bool__(self):
|
||||||
|
return None # We don't know the length, because of appends.
|
||||||
|
|
||||||
|
|
||||||
class ListComprehension(Comprehension, ArrayMixin):
|
class ListComprehension(Comprehension, ArrayMixin):
|
||||||
type = 'list'
|
type = 'list'
|
||||||
@@ -203,9 +209,6 @@ class Array(IterableWrapper, ArrayMixin):
|
|||||||
def name(self):
|
def name(self):
|
||||||
return helpers.FakeName(self.type, parent=self)
|
return helpers.FakeName(self.type, parent=self)
|
||||||
|
|
||||||
def py__bool__(self):
|
|
||||||
return None # We don't know the length, because of appends.
|
|
||||||
|
|
||||||
@memoize_default()
|
@memoize_default()
|
||||||
def get_index_types(self, evaluator, index=()):
|
def get_index_types(self, evaluator, index=()):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -24,6 +24,13 @@ next(gen_ret(1))
|
|||||||
#? []
|
#? []
|
||||||
next(gen_ret())
|
next(gen_ret())
|
||||||
|
|
||||||
|
# generators evaluate to true if cast by bool.
|
||||||
|
a = ''
|
||||||
|
if gen_ret():
|
||||||
|
a = 3
|
||||||
|
#? int()
|
||||||
|
a
|
||||||
|
|
||||||
|
|
||||||
# -----------------
|
# -----------------
|
||||||
# generators should not be indexable
|
# generators should not be indexable
|
||||||
|
|||||||
Reference in New Issue
Block a user