mirror of
https://github.com/davidhalter/parso.git
synced 2026-08-12 19:11:34 +08:00
Move a few imports out of functions.
This commit is contained in:
@@ -5,6 +5,7 @@ import re
|
|||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
|
|
||||||
from parso.normalizer import Normalizer, NormalizerConfig, Issue
|
from parso.normalizer import Normalizer, NormalizerConfig, Issue
|
||||||
|
from parso.python.tree import search_ancestor
|
||||||
|
|
||||||
_BLOCK_STMTS = ('if_stmt', 'while_stmt', 'for_stmt', 'try_stmt', 'with_stmt')
|
_BLOCK_STMTS = ('if_stmt', 'while_stmt', 'for_stmt', 'try_stmt', 'with_stmt')
|
||||||
_STAR_EXPR_PARENTS = ('testlist_star_expr', 'testlist_comp', 'exprlist')
|
_STAR_EXPR_PARENTS = ('testlist_star_expr', 'testlist_comp', 'exprlist')
|
||||||
@@ -260,7 +261,6 @@ class ErrorFinder(Normalizer):
|
|||||||
self._version = self._grammar.version_info
|
self._version = self._grammar.version_info
|
||||||
|
|
||||||
def initialize(self, node):
|
def initialize(self, node):
|
||||||
from parso.python.tree import search_ancestor
|
|
||||||
allowed = 'classdef', 'funcdef', 'file_input'
|
allowed = 'classdef', 'funcdef', 'file_input'
|
||||||
if node.type in allowed:
|
if node.type in allowed:
|
||||||
parent_scope = node
|
parent_scope = node
|
||||||
@@ -380,7 +380,6 @@ class ErrorFinder(Normalizer):
|
|||||||
message = "iterable unpacking cannot be used in comprehension"
|
message = "iterable unpacking cannot be used in comprehension"
|
||||||
self._add_syntax_error(message, node)
|
self._add_syntax_error(message, node)
|
||||||
if self._version <= (3, 4):
|
if self._version <= (3, 4):
|
||||||
from parso.python.tree import search_ancestor
|
|
||||||
n = search_ancestor(node, 'for_stmt', 'expr_stmt')
|
n = search_ancestor(node, 'for_stmt', 'expr_stmt')
|
||||||
found_definition = False
|
found_definition = False
|
||||||
if n is not None:
|
if n is not None:
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ from contextlib import contextmanager
|
|||||||
|
|
||||||
from parso.python.normalizer import ErrorFinder, ErrorFinderConfig
|
from parso.python.normalizer import ErrorFinder, ErrorFinderConfig
|
||||||
from parso.normalizer import Rule
|
from parso.normalizer import Rule
|
||||||
|
from parso.python.tree import search_ancestor, Flow, Scope
|
||||||
|
|
||||||
|
|
||||||
_IMPORT_TYPES = ('import_name', 'import_from')
|
_IMPORT_TYPES = ('import_name', 'import_from')
|
||||||
@@ -122,7 +123,6 @@ class BackslashNode(IndentationNode):
|
|||||||
type = IndentationTypes.BACKSLASH
|
type = IndentationTypes.BACKSLASH
|
||||||
|
|
||||||
def __init__(self, config, parent_indentation, containing_leaf, spacing, parent=None):
|
def __init__(self, config, parent_indentation, containing_leaf, spacing, parent=None):
|
||||||
from parso.python.tree import search_ancestor
|
|
||||||
expr_stmt = search_ancestor(containing_leaf, 'expr_stmt')
|
expr_stmt = search_ancestor(containing_leaf, 'expr_stmt')
|
||||||
if expr_stmt is not None:
|
if expr_stmt is not None:
|
||||||
equals = expr_stmt.children[-2]
|
equals = expr_stmt.children[-2]
|
||||||
@@ -224,7 +224,6 @@ class PEP8Normalizer(ErrorFinder):
|
|||||||
#if module.type == 'simple_stmt':
|
#if module.type == 'simple_stmt':
|
||||||
if module.type == 'file_input':
|
if module.type == 'file_input':
|
||||||
index = module.children.index(simple_stmt)
|
index = module.children.index(simple_stmt)
|
||||||
from parso.python.tree import Flow
|
|
||||||
for child in module.children[:index]:
|
for child in module.children[:index]:
|
||||||
children = [child]
|
children = [child]
|
||||||
if child.type == 'simple_stmt':
|
if child.type == 'simple_stmt':
|
||||||
@@ -641,7 +640,6 @@ class PEP8Normalizer(ErrorFinder):
|
|||||||
else:
|
else:
|
||||||
self.add_issuadd_issue(741, message % 'variables', leaf)
|
self.add_issuadd_issue(741, message % 'variables', leaf)
|
||||||
elif leaf.value == ':':
|
elif leaf.value == ':':
|
||||||
from parso.python.tree import Flow, Scope
|
|
||||||
if isinstance(leaf.parent, (Flow, Scope)) and leaf.parent.type != 'lambdef':
|
if isinstance(leaf.parent, (Flow, Scope)) and leaf.parent.type != 'lambdef':
|
||||||
next_leaf = leaf.get_next_leaf()
|
next_leaf = leaf.get_next_leaf()
|
||||||
if next_leaf.type != 'newline':
|
if next_leaf.type != 'newline':
|
||||||
@@ -687,7 +685,6 @@ class PEP8Normalizer(ErrorFinder):
|
|||||||
self.add_issue(391, 'Blank line at end of file', leaf)
|
self.add_issue(391, 'Blank line at end of file', leaf)
|
||||||
|
|
||||||
def add_issue(self, code, message, node):
|
def add_issue(self, code, message, node):
|
||||||
from parso.python.tree import search_ancestor
|
|
||||||
if self._previous_leaf is not None:
|
if self._previous_leaf is not None:
|
||||||
if search_ancestor(self._previous_leaf, 'error_node') is not None:
|
if search_ancestor(self._previous_leaf, 'error_node') is not None:
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user