remove unused import and run tox -e autofix

This commit is contained in:
Jimmy Lai 2019-11-19 13:56:48 -08:00 committed by jimmylai
parent 337abb26c9
commit e7315d2c28
3 changed files with 25 additions and 43 deletions

View file

@ -6,17 +6,7 @@
from abc import ABC, abstractmethod
from copy import deepcopy
from dataclasses import dataclass, field, fields, replace
from typing import (
TYPE_CHECKING,
Any,
Dict,
List,
Mapping,
Sequence,
TypeVar,
Union,
cast,
)
from typing import Any, Dict, List, Mapping, Sequence, TypeVar, Union, cast
from libcst._nodes.internal import CodegenState
from libcst._removal_sentinel import RemovalSentinel
@ -25,10 +15,6 @@ from libcst._types import CSTNodeT
from libcst._visitors import CSTTransformer, CSTVisitor, CSTVisitorT
if TYPE_CHECKING:
from libcst.metadata.base_provider import BaseMetadataProvider # noqa: F401
_T = TypeVar("_T")
_CSTNodeSelfT = TypeVar("_CSTNodeSelfT", bound="CSTNode")
_EMPTY_SEQUENCE: Sequence["CSTNode"] = ()

View file

@ -1027,7 +1027,7 @@ def _sequence_matches( # noqa: C901
elif isinstance(matcher, _ExtractMatchingNode):
# See if the raw matcher matches. If it does, capture the sequence we matched and store it.
sequence_capture = _sequence_matches(
nodes, [matcher.matcher, *matchers[1:]], metadata_lookup,
nodes, [matcher.matcher, *matchers[1:]], metadata_lookup
)
if sequence_capture is not None:
return {

View file

@ -39,9 +39,7 @@ class MatchersExtractTest(UnitTest):
nodes = m.extract(
expression,
m.SaveMatchedNode(
m.Tuple(
elements=[m.Element(m.BinaryOperation(),), m.Element(m.Call(),),]
),
m.Tuple(elements=[m.Element(m.BinaryOperation()), m.Element(m.Call())]),
name="node",
),
)
@ -57,7 +55,7 @@ class MatchersExtractTest(UnitTest):
m.Element(
m.BinaryOperation(left=m.SaveMatchedNode(m.Name(), "left"))
),
m.Element(m.Call(),),
m.Element(m.Call()),
]
),
)
@ -75,7 +73,7 @@ class MatchersExtractTest(UnitTest):
m.Element(
m.BinaryOperation(left=m.SaveMatchedNode(m.Subscript(), "left"))
),
m.Element(m.Call(),),
m.Element(m.Call()),
]
),
)
@ -99,7 +97,7 @@ class MatchersExtractTest(UnitTest):
cst.BinaryOperation,
).left
extracted_node_func = cst.ensure_type(
cst.ensure_type(expression, cst.Tuple).elements[1].value, cst.Call,
cst.ensure_type(expression, cst.Tuple).elements[1].value, cst.Call
).func
self.assertEqual(
nodes, {"left": extracted_node_left, "func": extracted_node_func}
@ -128,7 +126,7 @@ class MatchersExtractTest(UnitTest):
cst.BinaryOperation,
).left
extracted_node_func = cst.ensure_type(
cst.ensure_type(expression, cst.Tuple).elements[1].value, cst.Call,
cst.ensure_type(expression, cst.Tuple).elements[1].value, cst.Call
).func
self.assertEqual(
nodes, {"left": extracted_node_left, "func": extracted_node_func}
@ -156,7 +154,7 @@ class MatchersExtractTest(UnitTest):
cst.BinaryOperation,
).left
extracted_node_attr = cst.ensure_type(
cst.ensure_type(expression, cst.Tuple).elements[1].value, cst.Call,
cst.ensure_type(expression, cst.Tuple).elements[1].value, cst.Call
).func
self.assertEqual(
nodes, {"left": extracted_node_left, "attr": extracted_node_attr}
@ -188,7 +186,7 @@ class MatchersExtractTest(UnitTest):
)
)
),
m.Element(m.Call(),),
m.Element(m.Call()),
]
),
metadata_resolver=wrapper,
@ -217,7 +215,7 @@ class MatchersExtractTest(UnitTest):
)
)
),
m.Element(m.Call(),),
m.Element(m.Call()),
]
),
metadata_resolver=wrapper,
@ -237,10 +235,10 @@ class MatchersExtractTest(UnitTest):
args=[
m.Arg(m.SaveMatchedNode(m.Name(), "name")),
m.DoNotCare(),
],
]
),
"name",
),
)
),
]
),
@ -260,7 +258,7 @@ class MatchersExtractTest(UnitTest):
args=[
m.Arg(m.SaveMatchedNode(m.DoNotCare(), "arg")),
m.Arg(m.SaveMatchedNode(m.DoNotCare(), "arg")),
],
]
)
),
]
@ -268,7 +266,7 @@ class MatchersExtractTest(UnitTest):
)
extracted_node = (
cst.ensure_type(
cst.ensure_type(expression, cst.Tuple).elements[1].value, cst.Call,
cst.ensure_type(expression, cst.Tuple).elements[1].value, cst.Call
)
.args[1]
.value
@ -287,8 +285,8 @@ class MatchersExtractTest(UnitTest):
args=[
m.ZeroOrMore(
m.Arg(m.SaveMatchedNode(m.DoNotCare(), "arg"))
),
],
)
]
)
),
]
@ -296,7 +294,7 @@ class MatchersExtractTest(UnitTest):
)
extracted_node = (
cst.ensure_type(
cst.ensure_type(expression, cst.Tuple).elements[1].value, cst.Call,
cst.ensure_type(expression, cst.Tuple).elements[1].value, cst.Call
)
.args[1]
.value
@ -315,9 +313,9 @@ class MatchersExtractTest(UnitTest):
args=[
m.ZeroOrMore(),
m.ZeroOrOne(
m.Arg(m.SaveMatchedNode(m.Attribute(), "arg")),
m.Arg(m.SaveMatchedNode(m.Attribute(), "arg"))
),
],
]
)
),
]
@ -338,9 +336,9 @@ class MatchersExtractTest(UnitTest):
m.DoNotCare(),
m.DoNotCare(),
m.ZeroOrOne(
m.Arg(m.SaveMatchedNode(m.Attribute(), "arg")),
m.Arg(m.SaveMatchedNode(m.Attribute(), "arg"))
),
],
]
)
),
]
@ -348,7 +346,7 @@ class MatchersExtractTest(UnitTest):
)
extracted_node = (
cst.ensure_type(
cst.ensure_type(expression, cst.Tuple).elements[1].value, cst.Call,
cst.ensure_type(expression, cst.Tuple).elements[1].value, cst.Call
)
.args[2]
.value
@ -362,14 +360,12 @@ class MatchersExtractTest(UnitTest):
m.Tuple(
elements=[
m.DoNotCare(),
m.Element(
m.Call(args=m.SaveMatchedNode([m.ZeroOrMore(),], "args"),)
),
m.Element(m.Call(args=m.SaveMatchedNode([m.ZeroOrMore()], "args"))),
]
),
)
extracted_seq = cst.ensure_type(
cst.ensure_type(expression, cst.Tuple).elements[1].value, cst.Call,
cst.ensure_type(expression, cst.Tuple).elements[1].value, cst.Call
).args
self.assertEqual(nodes, {"args": extracted_seq})
@ -386,7 +382,7 @@ class MatchersExtractTest(UnitTest):
),
)
extracted_seq = cst.ensure_type(
cst.ensure_type(expression, cst.Tuple).elements[1].value, cst.Call,
cst.ensure_type(expression, cst.Tuple).elements[1].value, cst.Call
).args
self.assertEqual(nodes, {"args": extracted_seq})