forked from VimPlug/jedi
Rename SubModule to Module, because that's a more fitting description. There were reasons for the name before the new fast parser, but those don't exist anymore.
This commit is contained in:
@@ -156,10 +156,6 @@ def get_module_names(module, all_scopes):
|
|||||||
return chain.from_iterable(dct.values())
|
return chain.from_iterable(dct.values())
|
||||||
|
|
||||||
|
|
||||||
class FakeSubModule():
|
|
||||||
line_offset = 0
|
|
||||||
|
|
||||||
|
|
||||||
class FakeImport(pr.Import):
|
class FakeImport(pr.Import):
|
||||||
def __init__(self, name, parent, level=0):
|
def __init__(self, name, parent, level=0):
|
||||||
super(FakeImport, self).__init__([])
|
super(FakeImport, self).__init__([])
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ class Parser(object):
|
|||||||
'expr_stmt': pt.ExprStmt,
|
'expr_stmt': pt.ExprStmt,
|
||||||
'classdef': pt.Class,
|
'classdef': pt.Class,
|
||||||
'funcdef': pt.Function,
|
'funcdef': pt.Function,
|
||||||
'file_input': pt.SubModule,
|
'file_input': pt.Module,
|
||||||
'import_name': pt.ImportName,
|
'import_name': pt.ImportName,
|
||||||
'import_from': pt.ImportFrom,
|
'import_from': pt.ImportFrom,
|
||||||
'break_stmt': pt.KeywordStatement,
|
'break_stmt': pt.KeywordStatement,
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ from jedi._compatibility import use_metaclass, unicode
|
|||||||
from jedi import settings
|
from jedi import settings
|
||||||
from jedi.parser import Parser
|
from jedi.parser import Parser
|
||||||
from jedi.parser import tree as pr
|
from jedi.parser import tree as pr
|
||||||
from jedi.parser import tokenize
|
|
||||||
from jedi import cache
|
from jedi import cache
|
||||||
from jedi import debug
|
from jedi import debug
|
||||||
from jedi.parser.tokenize import (source_tokens, NEWLINE,
|
from jedi.parser.tokenize import (source_tokens, NEWLINE,
|
||||||
@@ -19,7 +18,7 @@ from jedi.parser.tokenize import (source_tokens, NEWLINE,
|
|||||||
FLOWS = ['if', 'else', 'elif', 'while', 'with', 'try', 'except', 'finally', 'for']
|
FLOWS = ['if', 'else', 'elif', 'while', 'with', 'try', 'except', 'finally', 'for']
|
||||||
|
|
||||||
|
|
||||||
class FastModule(pr.SubModule):
|
class FastModule(pr.Module):
|
||||||
type = 'file_input'
|
type = 'file_input'
|
||||||
|
|
||||||
def __init__(self, module_path):
|
def __init__(self, module_path):
|
||||||
|
|||||||
@@ -11,16 +11,16 @@ By using `get_code` on a module, you can get back the 1-to-1 representation of
|
|||||||
the input given to the parser. This is important if you are using refactoring.
|
the input given to the parser. This is important if you are using refactoring.
|
||||||
|
|
||||||
The easiest way to play with this module is to use :class:`parsing.Parser`.
|
The easiest way to play with this module is to use :class:`parsing.Parser`.
|
||||||
:attr:`parsing.Parser.module` holds an instance of :class:`SubModule`:
|
:attr:`parsing.Parser.module` holds an instance of :class:`Module`:
|
||||||
|
|
||||||
>>> from jedi._compatibility import u
|
>>> from jedi._compatibility import u
|
||||||
>>> from jedi.parser import Parser, load_grammar
|
>>> from jedi.parser import Parser, load_grammar
|
||||||
>>> parser = Parser(load_grammar(), u('import os'), 'example.py')
|
>>> parser = Parser(load_grammar(), u('import os'), 'example.py')
|
||||||
>>> submodule = parser.module
|
>>> submodule = parser.module
|
||||||
>>> submodule
|
>>> submodule
|
||||||
<SubModule: example.py@1-1>
|
<Module: example.py@1-1>
|
||||||
|
|
||||||
Any subclasses of :class:`Scope`, including :class:`SubModule` has an attribute
|
Any subclasses of :class:`Scope`, including :class:`Module` has an attribute
|
||||||
:attr:`imports <Scope.imports>`:
|
:attr:`imports <Scope.imports>`:
|
||||||
|
|
||||||
>>> submodule.imports
|
>>> submodule.imports
|
||||||
@@ -63,7 +63,7 @@ class DocstringMixin(object):
|
|||||||
@property
|
@property
|
||||||
def raw_doc(self):
|
def raw_doc(self):
|
||||||
""" Returns a cleaned version of the docstring token. """
|
""" Returns a cleaned version of the docstring token. """
|
||||||
if isinstance(self, SubModule):
|
if isinstance(self, Module):
|
||||||
stmt = self.children[0]
|
stmt = self.children[0]
|
||||||
else:
|
else:
|
||||||
stmt = self.children[self.children.index(':') + 1]
|
stmt = self.children[self.children.index(':') + 1]
|
||||||
@@ -589,17 +589,7 @@ class Scope(Simple, DocstringMixin):
|
|||||||
r = r.next
|
r = r.next
|
||||||
|
|
||||||
|
|
||||||
class Module(Base):
|
class Module(Scope):
|
||||||
"""
|
|
||||||
For isinstance checks. fast_parser.Module also inherits from this.
|
|
||||||
"""
|
|
||||||
__slots__ = ()
|
|
||||||
|
|
||||||
def is_scope(self):
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
class SubModule(Scope, Module):
|
|
||||||
"""
|
"""
|
||||||
The top scope, which is always a module.
|
The top scope, which is always a 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
|
||||||
@@ -611,14 +601,14 @@ class SubModule(Scope, Module):
|
|||||||
|
|
||||||
def __init__(self, children):
|
def __init__(self, children):
|
||||||
"""
|
"""
|
||||||
Initialize :class:`SubModule`.
|
Initialize :class:`Module`.
|
||||||
|
|
||||||
:type path: str
|
:type path: str
|
||||||
:arg path: File path to this module.
|
:arg path: File path to this module.
|
||||||
|
|
||||||
.. todo:: Document `top_module`.
|
.. todo:: Document `top_module`.
|
||||||
"""
|
"""
|
||||||
super(SubModule, self).__init__(children)
|
super(Module, self).__init__(children)
|
||||||
self.path = None # Set later.
|
self.path = None # Set later.
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|||||||
Reference in New Issue
Block a user