mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 14:34:31 +08:00
Some refactoring in the stdlib plugin
This commit is contained in:
@@ -50,35 +50,19 @@ _NAMEDTUPLE_INIT = """
|
|||||||
class StdlibPlugin(BasePlugin):
|
class StdlibPlugin(BasePlugin):
|
||||||
def execute(self, callback):
|
def execute(self, callback):
|
||||||
def wrapper(context, arguments):
|
def wrapper(context, arguments):
|
||||||
debug.dbg('execute: %s %s', context, arguments)
|
if isinstance(context, BoundMethod):
|
||||||
try:
|
|
||||||
# Some stdlib functions like super(), namedtuple(), etc. have been
|
|
||||||
# hard-coded in Jedi to support them.
|
|
||||||
return execute(self._evaluator, context, arguments)
|
|
||||||
except _NotInStdLib:
|
|
||||||
pass
|
|
||||||
return callback(context, arguments)
|
return callback(context, arguments)
|
||||||
|
|
||||||
return wrapper
|
debug.dbg('execute: %s %s', context, arguments)
|
||||||
|
|
||||||
|
|
||||||
class _NotInStdLib(LookupError):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def execute(evaluator, obj, arguments):
|
|
||||||
if isinstance(obj, BoundMethod):
|
|
||||||
raise _NotInStdLib()
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
obj_name = obj.name.string_name
|
obj_name = context.name.string_name
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
if obj.parent_context == evaluator.builtins_module:
|
if context.parent_context == self._evaluator.builtins_module:
|
||||||
module_name = 'builtins'
|
module_name = 'builtins'
|
||||||
elif isinstance(obj.parent_context, ModuleContext):
|
elif isinstance(context.parent_context, ModuleContext):
|
||||||
module_name = obj.parent_context.name.string_name
|
module_name = context.parent_context.name.string_name
|
||||||
else:
|
else:
|
||||||
module_name = ''
|
module_name = ''
|
||||||
|
|
||||||
@@ -88,8 +72,10 @@ def execute(evaluator, obj, arguments):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
return func(evaluator, obj, arguments)
|
return func(self._evaluator, context, arguments)
|
||||||
raise _NotInStdLib()
|
return callback(context, arguments)
|
||||||
|
|
||||||
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
def _follow_param(evaluator, arguments, index):
|
def _follow_param(evaluator, arguments, index):
|
||||||
|
|||||||
Reference in New Issue
Block a user