mirror of
https://github.com/davidhalter/jedi.git
synced 2026-02-22 04:28:27 +08:00
Rewrite the next function.
This commit is contained in:
@@ -93,6 +93,7 @@ class Evaluator(object):
|
|||||||
self.analysis = []
|
self.analysis = []
|
||||||
self.dynamic_params_depth = 0
|
self.dynamic_params_depth = 0
|
||||||
self.is_analysis = False
|
self.is_analysis = False
|
||||||
|
self.python_version = sys.version_info[:2]
|
||||||
|
|
||||||
if sys_path is None:
|
if sys_path is None:
|
||||||
sys_path = sys.path
|
sys_path = sys.path
|
||||||
|
|||||||
@@ -6,17 +6,6 @@ possible for the auto completion.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
def next(iterator, default=None):
|
|
||||||
if random.choice([0, 1]):
|
|
||||||
if hasattr("next"):
|
|
||||||
return iterator.next()
|
|
||||||
else:
|
|
||||||
return iterator.__next__()
|
|
||||||
else:
|
|
||||||
if default is not None:
|
|
||||||
return default
|
|
||||||
|
|
||||||
|
|
||||||
def iter(collection, sentinel=None):
|
def iter(collection, sentinel=None):
|
||||||
if sentinel:
|
if sentinel:
|
||||||
yield collection()
|
yield collection()
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ def has_builtin_methods(cls):
|
|||||||
|
|
||||||
def register_builtin_method(method_name, python_version_match=None):
|
def register_builtin_method(method_name, python_version_match=None):
|
||||||
def wrapper(func):
|
def wrapper(func):
|
||||||
if python_version_match and python_version_match + int(is_py3) == 3:
|
if python_version_match and python_version_match == 2 + int(is_py3):
|
||||||
# Some functions do only apply to certain versions.
|
# Some functions do only apply to certain versions.
|
||||||
return func
|
return func
|
||||||
dct = func.__dict__.setdefault('registered_builtin_methods', {})
|
dct = func.__dict__.setdefault('registered_builtin_methods', {})
|
||||||
|
|||||||
@@ -106,6 +106,25 @@ def argument_clinic(string, want_obj=False, want_context=False, want_arguments=F
|
|||||||
return f
|
return f
|
||||||
|
|
||||||
|
|
||||||
|
@argument_clinic('iterator[, default], /')
|
||||||
|
def builtins_next(evaluator, iterators, defaults):
|
||||||
|
if evaluator.python_version[0] == 2:
|
||||||
|
name = 'next'
|
||||||
|
else:
|
||||||
|
name = '__next__'
|
||||||
|
|
||||||
|
types = set()
|
||||||
|
for iterator in iterators:
|
||||||
|
if isinstance(iterator, AbstractInstanceContext):
|
||||||
|
for filter in iterator.get_filters(include_self_names=True):
|
||||||
|
for n in filter.get(name):
|
||||||
|
for context in n.infer():
|
||||||
|
types |= context.execute_evaluated()
|
||||||
|
if types:
|
||||||
|
return types
|
||||||
|
return defaults
|
||||||
|
|
||||||
|
|
||||||
@argument_clinic('object, name[, default], /')
|
@argument_clinic('object, name[, default], /')
|
||||||
def builtins_getattr(evaluator, objects, names, defaults=None):
|
def builtins_getattr(evaluator, objects, names, defaults=None):
|
||||||
# follow the first param
|
# follow the first param
|
||||||
@@ -249,6 +268,7 @@ def _return_first_param(evaluator, firsts):
|
|||||||
|
|
||||||
_implemented = {
|
_implemented = {
|
||||||
'builtins': {
|
'builtins': {
|
||||||
|
'next': builtins_next,
|
||||||
'getattr': builtins_getattr,
|
'getattr': builtins_getattr,
|
||||||
'type': builtins_type,
|
'type': builtins_type,
|
||||||
'super': builtins_super,
|
'super': builtins_super,
|
||||||
|
|||||||
Reference in New Issue
Block a user