mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 06:24:27 +08:00
Move has_absolute_import to SubModule class
This commit is contained in:
@@ -155,7 +155,6 @@ class Scope(Simple, IsScope):
|
|||||||
# returns will be in "normal" modules.
|
# returns will be in "normal" modules.
|
||||||
self.returns = []
|
self.returns = []
|
||||||
self.is_generator = False
|
self.is_generator = False
|
||||||
self._explicit_absolute_imports = None
|
|
||||||
|
|
||||||
def add_scope(self, sub, decorators):
|
def add_scope(self, sub, decorators):
|
||||||
sub.parent = self.use_as_parent
|
sub.parent = self.use_as_parent
|
||||||
@@ -295,24 +294,6 @@ class Scope(Simple, IsScope):
|
|||||||
if p:
|
if p:
|
||||||
return p
|
return p
|
||||||
|
|
||||||
@property
|
|
||||||
def has_explicit_absolute_import(self):
|
|
||||||
"""
|
|
||||||
Checks if imports in this scope are explicitly absolute, i.e. there
|
|
||||||
is a ``__future__`` import.
|
|
||||||
|
|
||||||
The result of this property is cached; the first time it is
|
|
||||||
called will cause it to walk through all the imports in the
|
|
||||||
parse tree.
|
|
||||||
|
|
||||||
"""
|
|
||||||
if self._explicit_absolute_imports is not None:
|
|
||||||
return self._explicit_absolute_imports
|
|
||||||
|
|
||||||
has_import = any(_enables_absolute_import(i) for i in self.imports)
|
|
||||||
self._explicit_absolute_imports = has_import
|
|
||||||
return has_import
|
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
try:
|
try:
|
||||||
name = self.path
|
name = self.path
|
||||||
@@ -350,7 +331,6 @@ class SubModule(Scope, Module):
|
|||||||
Depending on the underlying parser this may be a full module or just a part
|
Depending on the underlying parser this may be a full module or just a part
|
||||||
of a module.
|
of a module.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, path, start_pos=(1, 0), top_module=None):
|
def __init__(self, path, start_pos=(1, 0), top_module=None):
|
||||||
"""
|
"""
|
||||||
Initialize :class:`SubModule`.
|
Initialize :class:`SubModule`.
|
||||||
@@ -371,6 +351,8 @@ class SubModule(Scope, Module):
|
|||||||
|
|
||||||
self.use_as_parent = top_module or self
|
self.use_as_parent = top_module or self
|
||||||
|
|
||||||
|
self._explicit_absolute_imports = None
|
||||||
|
|
||||||
def add_global(self, name):
|
def add_global(self, name):
|
||||||
"""
|
"""
|
||||||
Global means in these context a function (subscope) which has a global
|
Global means in these context a function (subscope) which has a global
|
||||||
@@ -409,6 +391,19 @@ class SubModule(Scope, Module):
|
|||||||
def is_builtin(self):
|
def is_builtin(self):
|
||||||
return not (self.path is None or self.path.endswith('.py'))
|
return not (self.path is None or self.path.endswith('.py'))
|
||||||
|
|
||||||
|
@property
|
||||||
|
def has_explicit_absolute_import(self):
|
||||||
|
"""
|
||||||
|
Checks if imports in this module are explicitly absolute, i.e. there
|
||||||
|
is a ``__future__`` import.
|
||||||
|
"""
|
||||||
|
if self._explicit_absolute_imports is not None:
|
||||||
|
return self._explicit_absolute_imports
|
||||||
|
|
||||||
|
has_import = any(_enables_absolute_import(i) for i in self.imports)
|
||||||
|
self._explicit_absolute_imports = has_import
|
||||||
|
return has_import
|
||||||
|
|
||||||
|
|
||||||
class Class(Scope):
|
class Class(Scope):
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user