From e7315d2c2810d3894450b2af000ee438f3c3a0bb Mon Sep 17 00:00:00 2001 From: Jimmy Lai Date: Tue, 19 Nov 2019 13:56:48 -0800 Subject: [PATCH] remove unused import and run tox -e autofix --- libcst/_nodes/base.py | 16 +-------- libcst/matchers/_matcher_base.py | 2 +- libcst/matchers/tests/test_extract.py | 50 ++++++++++++--------------- 3 files changed, 25 insertions(+), 43 deletions(-) diff --git a/libcst/_nodes/base.py b/libcst/_nodes/base.py index 4cd1f14e..ec6b258e 100644 --- a/libcst/_nodes/base.py +++ b/libcst/_nodes/base.py @@ -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"] = () diff --git a/libcst/matchers/_matcher_base.py b/libcst/matchers/_matcher_base.py index 917ed3bd..7b6197ea 100644 --- a/libcst/matchers/_matcher_base.py +++ b/libcst/matchers/_matcher_base.py @@ -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 { diff --git a/libcst/matchers/tests/test_extract.py b/libcst/matchers/tests/test_extract.py index 78920f81..42c7e0b2 100644 --- a/libcst/matchers/tests/test_extract.py +++ b/libcst/matchers/tests/test_extract.py @@ -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})