mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-18 19:45:57 +08:00
Fix some next() stuff.
This commit is contained in:
@@ -6,6 +6,17 @@ 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()
|
||||||
|
|||||||
@@ -213,14 +213,18 @@ class CompiledInstanceName(compiled.CompiledName):
|
|||||||
self._instance = instance
|
self._instance = instance
|
||||||
|
|
||||||
def infer(self):
|
def infer(self):
|
||||||
for v in super(CompiledInstanceName, self).infer():
|
for result_context in super(CompiledInstanceName, self).infer():
|
||||||
if isinstance(v, er.FunctionContext):
|
if isinstance(result_context, er.FunctionContext):
|
||||||
|
parent_context = result_context.parent_context
|
||||||
|
while parent_context.is_class():
|
||||||
|
parent_context = parent_context.parent_context
|
||||||
|
|
||||||
yield BoundMethod(
|
yield BoundMethod(
|
||||||
v.evaluator, self._instance, self.parent_context,
|
result_context.evaluator, self._instance, self.parent_context,
|
||||||
v.parent_context, v.funcdef
|
parent_context, result_context.funcdef
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
yield v
|
yield result_context
|
||||||
|
|
||||||
|
|
||||||
class CompiledInstanceClassFilter(compiled.CompiledObjectFilter):
|
class CompiledInstanceClassFilter(compiled.CompiledObjectFilter):
|
||||||
@@ -282,7 +286,7 @@ class LazyInstanceClassName(LazyInstanceName):
|
|||||||
# functions. Only other functions and modules will resolve
|
# functions. Only other functions and modules will resolve
|
||||||
# those things.
|
# those things.
|
||||||
parent_context = result_context.parent_context
|
parent_context = result_context.parent_context
|
||||||
while isinstance(parent_context, er.ClassContext):
|
while parent_context.is_class():
|
||||||
parent_context = parent_context.parent_context
|
parent_context = parent_context.parent_context
|
||||||
|
|
||||||
yield BoundMethod(
|
yield BoundMethod(
|
||||||
|
|||||||
@@ -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 == 2 + int(is_py3):
|
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', {})
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ from jedi.common import unite
|
|||||||
from jedi.evaluate import compiled
|
from jedi.evaluate import compiled
|
||||||
from jedi.evaluate import representation as er
|
from jedi.evaluate import representation as er
|
||||||
from jedi.evaluate.instance import InstanceFunctionExecution, \
|
from jedi.evaluate.instance import InstanceFunctionExecution, \
|
||||||
AbstractInstanceContext, CompiledInstance
|
AbstractInstanceContext, CompiledInstance, BoundMethod
|
||||||
from jedi.evaluate import iterable
|
from jedi.evaluate import iterable
|
||||||
from jedi.parser import ParserWithRecovery
|
from jedi.parser import ParserWithRecovery
|
||||||
from jedi import debug
|
from jedi import debug
|
||||||
@@ -31,6 +31,9 @@ class NotInStdLib(LookupError):
|
|||||||
|
|
||||||
|
|
||||||
def execute(evaluator, obj, arguments):
|
def execute(evaluator, obj, arguments):
|
||||||
|
if isinstance(obj, BoundMethod):
|
||||||
|
raise NotInStdLib()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
obj_name = obj.name.string_name
|
obj_name = obj.name.string_name
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
@@ -108,6 +111,10 @@ def argument_clinic(string, want_obj=False, want_context=False, want_arguments=F
|
|||||||
|
|
||||||
@argument_clinic('iterator[, default], /')
|
@argument_clinic('iterator[, default], /')
|
||||||
def builtins_next(evaluator, iterators, defaults):
|
def builtins_next(evaluator, iterators, defaults):
|
||||||
|
"""
|
||||||
|
TODO this function is currently not used. It's a stab at implementing next
|
||||||
|
in a different way than fake objects. This would be a bit more flexible.
|
||||||
|
"""
|
||||||
if evaluator.python_version[0] == 2:
|
if evaluator.python_version[0] == 2:
|
||||||
name = 'next'
|
name = 'next'
|
||||||
else:
|
else:
|
||||||
@@ -268,7 +275,6 @@ 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