From 40e19ac4576796c405b03fc305e5cb865df89384 Mon Sep 17 00:00:00 2001 From: Jennifer Taylor Date: Wed, 8 Jan 2020 15:27:33 -0800 Subject: [PATCH] Remove deprecated ExtSlice. --- docs/source/nodes.rst | 3 +- libcst/__init__.py | 6 - libcst/_nodes/expression.py | 33 +-- libcst/_typed_visitor.py | 45 +-- libcst/codegen/gather.py | 4 - libcst/codegen/gen_matcher_classes.py | 36 +-- libcst/codegen/gen_visitor_functions.py | 56 ---- libcst/codegen/transforms.py | 12 +- libcst/matchers/__init__.py | 360 ++++-------------------- libcst/tests/test_deprecate_extslice.py | 122 -------- 10 files changed, 86 insertions(+), 591 deletions(-) delete mode 100644 libcst/tests/test_deprecate_extslice.py diff --git a/docs/source/nodes.rst b/docs/source/nodes.rst index cd6352ba..fdd81673 100644 --- a/docs/source/nodes.rst +++ b/docs/source/nodes.rst @@ -153,8 +153,7 @@ Subscripts and Slices .. autoclass:: libcst.Subscript .. autoclass:: libcst.Index .. autoclass:: libcst.Slice -.. autoclass:: libcst.ExtSlice - +.. autoclass:: libcst.SubscriptElement Parenthesis, Brackets, and Braces ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/libcst/__init__.py b/libcst/__init__.py index 93f63dfa..724ccb6c 100644 --- a/libcst/__init__.py +++ b/libcst/__init__.py @@ -196,11 +196,6 @@ from libcst.metadata.base_provider import ( from libcst.metadata.wrapper import MetadataWrapper -# TODO: Remove this once we completely remove ExtSlice. -# Provide a backwards-compatible reference to deprecated ExtSlice -ExtSlice = SubscriptElement - - __all__ = [ "BatchableCSTVisitor", "CodePosition", # Deprecated export, import from libcst.metadata instead @@ -254,7 +249,6 @@ __all__ = [ "DictElement", "Element", "Ellipsis", - "ExtSlice", "Float", "FormattedString", "FormattedStringExpression", diff --git a/libcst/_nodes/expression.py b/libcst/_nodes/expression.py index 38832b5d..778d16a6 100644 --- a/libcst/_nodes/expression.py +++ b/libcst/_nodes/expression.py @@ -1365,7 +1365,7 @@ class SubscriptElement(CSTNode): `_. """ - #: A slice or index that is part of the extslice. + #: A slice or index that is part of a subscript. slice: Union[Index, Slice] #: A separating comma, with any whitespace it owns. @@ -1400,9 +1400,8 @@ class Subscript(BaseAssignTargetExpression, BaseDelTargetExpression): #: ``x`` in ``x[2]``. value: BaseExpression - #: The :class:`Index`, :class:`Slice`, or :class:`SubscriptElement` to extract from the - #: ``value``. - slice: Union[Index, Slice, Sequence[SubscriptElement]] + #: The :class:`SubscriptElement` to extract from the ``value``. + slice: Sequence[SubscriptElement] lbracket: LeftSquareBracket = LeftSquareBracket.field() #: Brackets after the ``value`` surrounding the ``slice``. @@ -1417,14 +1416,11 @@ class Subscript(BaseAssignTargetExpression, BaseDelTargetExpression): def _validate(self) -> None: super(Subscript, self)._validate() - slc = self.slice - if isinstance(slc, Sequence): - # Validate valid commas - if len(slc) < 1: - raise CSTValidationError("Cannot have empty SubscriptElement.") + # Validate valid commas + if len(self.slice) < 1: + raise CSTValidationError("Cannot have empty SubscriptElement.") def _visit_and_replace_children(self, visitor: CSTVisitorT) -> "Subscript": - slice = self.slice return Subscript( lpar=visit_sequence(self, "lpar", self.lpar, visitor), value=visit_required(self, "value", self.value, visitor), @@ -1432,9 +1428,7 @@ class Subscript(BaseAssignTargetExpression, BaseDelTargetExpression): self, "whitespace_after_value", self.whitespace_after_value, visitor ), lbracket=visit_required(self, "lbracket", self.lbracket, visitor), - slice=visit_required(self, "slice", slice, visitor) - if isinstance(slice, (Index, Slice)) - else visit_sequence(self, "slice", slice, visitor), + slice=visit_sequence(self, "slice", self.slice, visitor), rbracket=visit_required(self, "rbracket", self.rbracket, visitor), rpar=visit_sequence(self, "rpar", self.rpar, visitor), ) @@ -1453,16 +1447,9 @@ class Subscript(BaseAssignTargetExpression, BaseDelTargetExpression): self.value._codegen(state) self.whitespace_after_value._codegen(state) self.lbracket._codegen(state) - slc = self.slice - if isinstance(slc, (Index, Slice)): - slc._codegen(state) - elif isinstance(slc, Sequence): - lastslice = len(slc) - 1 - for i, slice in enumerate(slc): - slice._codegen(state, default_comma=(i != lastslice)) - else: - # We can make pyre happy this way! - raise Exception("Logic error!") + lastslice = len(self.slice) - 1 + for i, slice in enumerate(self.slice): + slice._codegen(state, default_comma=(i != lastslice)) self.rbracket._codegen(state) diff --git a/libcst/_typed_visitor.py b/libcst/_typed_visitor.py index 1d75aeb5..5e4e960a 100644 --- a/libcst/_typed_visitor.py +++ b/libcst/_typed_visitor.py @@ -178,8 +178,6 @@ if TYPE_CHECKING: ) from libcst._nodes.module import Module # noqa: F401 - ExtSlice = SubscriptElement - class CSTTypedBaseFunctions: @mark_no_op @@ -4282,39 +4280,24 @@ class CSTTypedBaseFunctions: def leave_Subscript_whitespace_after_value(self, node: "Subscript") -> None: pass + @mark_no_op def visit_SubscriptElement(self, node: "SubscriptElement") -> Optional[bool]: - return self.visit_ExtSlice(node) + pass + @mark_no_op def visit_SubscriptElement_slice(self, node: "SubscriptElement") -> None: - self.visit_ExtSlice_slice(node) + pass + @mark_no_op def leave_SubscriptElement_slice(self, node: "SubscriptElement") -> None: - self.leave_ExtSlice_slice(node) + pass + @mark_no_op def visit_SubscriptElement_comma(self, node: "SubscriptElement") -> None: - self.visit_ExtSlice_comma(node) + pass + @mark_no_op def leave_SubscriptElement_comma(self, node: "SubscriptElement") -> None: - self.leave_ExtSlice_comma(node) - - @mark_no_op - def visit_ExtSlice(self, node: "ExtSlice") -> Optional[bool]: - pass - - @mark_no_op - def visit_ExtSlice_slice(self, node: "ExtSlice") -> None: - pass - - @mark_no_op - def leave_ExtSlice_slice(self, node: "ExtSlice") -> None: - pass - - @mark_no_op - def visit_ExtSlice_comma(self, node: "ExtSlice") -> None: - pass - - @mark_no_op - def leave_ExtSlice_comma(self, node: "ExtSlice") -> None: pass @mark_no_op @@ -5199,11 +5182,8 @@ class CSTTypedVisitorFunctions(CSTTypedBaseFunctions): def leave_Subscript(self, original_node: "Subscript") -> None: pass - def leave_SubscriptElement(self, original_node: "SubscriptElement") -> None: - self.leave_ExtSlice(original_node) - @mark_no_op - def leave_ExtSlice(self, original_node: "ExtSlice") -> None: + def leave_SubscriptElement(self, original_node: "SubscriptElement") -> None: pass @mark_no_op @@ -6017,11 +5997,6 @@ class CSTTypedTransformerFunctions(CSTTypedBaseFunctions): @mark_no_op def leave_SubscriptElement( self, original_node: "SubscriptElement", updated_node: "SubscriptElement" - ) -> Union["SubscriptElement", RemovalSentinel]: - return self.leave_ExtSlice(original_node, updated_node) - - def leave_ExtSlice( - self, original_node: "ExtSlice", updated_node: "ExtSlice" ) -> Union["SubscriptElement", RemovalSentinel]: return updated_node diff --git a/libcst/codegen/gather.py b/libcst/codegen/gather.py index f9f34c1c..59f007d9 100644 --- a/libcst/codegen/gather.py +++ b/libcst/codegen/gather.py @@ -43,10 +43,6 @@ def _get_nodes() -> Generator[Type[cst.CSTNode], None, None]: continue if name == "CSTNode": continue - # TODO: Remove this once we completely remove ExtSlice. - if name == "ExtSlice": - # We're deprecating this, so don't generate code with it. - continue node = getattr(cst, name) try: diff --git a/libcst/codegen/gen_matcher_classes.py b/libcst/codegen/gen_matcher_classes.py index c8bd204d..4df2454a 100644 --- a/libcst/codegen/gen_matcher_classes.py +++ b/libcst/codegen/gen_matcher_classes.py @@ -201,14 +201,12 @@ class AddWildcardsToSequenceUnions(cst.CSTTransformer): # We don't want to add AtLeastN/AtMostN inside MatchIfTrue # type blocks, even for sequence types. return - slc = node.slice - # TODO: We can remove the instance check after ExtSlice is deprecated. - if not isinstance(slc, Sequence) or len(slc) != 1: + if len(node.slice) != 1: raise Exception( "Unexpected number of sequence elements inside Sequence type " + "annotation!" ) - nodeslice = slc[0].slice + nodeslice = node.slice[0].slice if isinstance(nodeslice, cst.Index): possibleunion = nodeslice.value if isinstance(possibleunion, cst.Subscript): @@ -303,13 +301,10 @@ def _get_alias_name(node: cst.CSTNode) -> Optional[str]: return f"{_get_raw_name(node)}MatchType" elif isinstance(node, cst.Subscript): if node.value.deep_equals(cst.Name("Union")): - slc = node.slice - # TODO: This instance check can go away once we deprecate ExtSlice - if isinstance(slc, Sequence): - names = [_get_raw_name(s) for s in slc] - if any(n is None for n in names): - return None - return "Or".join(n for n in names if n is not None) + "MatchType" + names = [_get_raw_name(s) for s in node.slice] + if any(n is None for n in names): + return None + return "Or".join(n for n in names if n is not None) + "MatchType" return None @@ -357,8 +352,6 @@ def _get_clean_type_from_union( name = _get_alias_name(typecst) value = typecst.with_changes( slice=[ - # pyre-ignore We know .slice is a sequence. This can go away once we - # deprecate ExtSlice. *[_maybe_fix_sequence_in_union(aliases, slc) for slc in typecst.slice], _get_match_metadata(), _get_match_if_true(typecst), @@ -372,14 +365,9 @@ def _get_clean_type_from_subscript( ) -> cst.BaseExpression: if typecst.value.deep_equals(cst.Name("Sequence")): # Lets attempt to widen the sequence type and alias it. - slc = typecst.slice - # TODO: This instance check can go away once we deprecate ExtSlice - if not isinstance(slc, Sequence): - raise Exception("Logic error, expected Sequence to have children!") - - if len(slc) != 1: + if len(typecst.slice) != 1: raise Exception("Logic error, Sequence shouldn't have more than one param!") - inner_type = slc[0].slice + inner_type = typecst.slice[0].slice if not isinstance(inner_type, cst.Index): raise Exception("Logic error, expecting Index for only Sequence element!") inner_type = inner_type.value @@ -576,14 +564,6 @@ for node in all_libcst_nodes: ) -# TODO: Remove this once we completely remove ExtSlice. -# Allow old ExtSlice notation so that we don't break existing code -generated_code.append("") -generated_code.append("") -generated_code.append("ExtSlice = SubscriptElement") -all_exports.add("ExtSlice") - - # Make sure to add an __all__ for flake8 and compatibility with "from libcst.matchers import *" generated_code.append(f"__all__ = {repr(sorted(list(all_exports)))}") diff --git a/libcst/codegen/gen_visitor_functions.py b/libcst/codegen/gen_visitor_functions.py index 100802d8..2385eb29 100644 --- a/libcst/codegen/gen_visitor_functions.py +++ b/libcst/codegen/gen_visitor_functions.py @@ -36,8 +36,6 @@ for module, objects in imports.items(): generated_code.append(f" from {module} import ( # noqa: F401") generated_code.append(f" {', '.join(sorted(list(objects)))}") generated_code.append(" )") -# TODO: Remove this once we completely remove ExtSlice. -generated_code.append(" ExtSlice = SubscriptElement") # Generate the base visit_ methods @@ -48,33 +46,6 @@ for node in sorted(nodebases.keys(), key=lambda node: node.__name__): name = node.__name__ if name.startswith("Base"): continue - # TODO: Remove this hack once we completely remove ExtSlice. - if name == "SubscriptElement": - # HACK! Point SubscriptElement visitors at ExtSlice visitors for now, - # so that deprecated visitors still work. This requires us to drop the - # optimization @mark_no_op for the time being. - generated_code.append("") - generated_code.append( - f' def visit_SubscriptElement(self, node: "SubscriptElement") -> Optional[bool]:' - ) - generated_code.append(" return self.visit_ExtSlice(node)") - for field in fields(node) or []: - if field.name == "_metadata": - continue - generated_code.append("") - generated_code.append( - f' def visit_SubscriptElement_{field.name}(self, node: "SubscriptElement") -> None:' - ) - generated_code.append(f" self.visit_ExtSlice_{field.name}(node)") - generated_code.append("") - generated_code.append( - f' def leave_SubscriptElement_{field.name}(self, node: "SubscriptElement") -> None:' - ) - generated_code.append(f" self.leave_ExtSlice_{field.name}(node)") - - # HACK: Pretend we didn't output code and change the name to ExtSlice, - # so we can use the common code below. - name = "ExtSlice" generated_code.append("") generated_code.append(" @mark_no_op") @@ -106,19 +77,6 @@ for node in sorted(nodebases.keys(), key=lambda node: node.__name__): name = node.__name__ if name.startswith("Base"): continue - # TODO: Remove this hack once we completely remove ExtSlice. - if name == "SubscriptElement": - # HACK! Point SubscriptElement visitors at ExtSlice visitors for now, - # so that deprecated visitors still work. This requires us to drop the - # optimization @mark_no_op for the time being. - generated_code.append("") - generated_code.append( - f' def leave_SubscriptElement(self, original_node: "SubscriptElement") -> None:' - ) - generated_code.append(" self.leave_ExtSlice(original_node)") - # HACK: Pretend we didn't output code and change the name to ExtSlice, - # so we can use the common code below. - name = "ExtSlice" generated_code.append("") generated_code.append(" @mark_no_op") @@ -150,20 +108,6 @@ for node in sorted(nodebases.keys(), key=lambda node: node.__name__): or base_uses.sequence ): valid_return_types.append("RemovalSentinel") - # TODO: Remove this hack once we completely remove ExtSlice. - if name == "SubscriptElement": - # HACK! Point SubscriptElement visitors at ExtSlice visitors for now, - # so that deprecated visitors still work. This requires us to drop the - # optimization @mark_no_op for the time being. - generated_code.append( - f' def leave_SubscriptElement(self, original_node: "SubscriptElement", updated_node: "SubscriptElement") -> Union[{", ".join(valid_return_types)}]:' - ) - generated_code.append( - " return self.leave_ExtSlice(original_node, updated_node)" - ) - # HACK: Pretend we didn't output code and change the name to ExtSlice, - # so we can use the common code below. - name = "ExtSlice" generated_code.append( f' def leave_{name}(self, original_node: "{name}", updated_node: "{name}") -> Union[{", ".join(valid_return_types)}]:' diff --git a/libcst/codegen/transforms.py b/libcst/codegen/transforms.py index 436a8459..ffeaed12 100644 --- a/libcst/codegen/transforms.py +++ b/libcst/codegen/transforms.py @@ -24,15 +24,9 @@ class SimplifyUnionsTransformer(m.MatcherDecoratableTransformer): def _leave_union( self, original_node: cst.Subscript, updated_node: cst.Subscript ) -> cst.BaseExpression: - slc = updated_node.slice - # TODO: We can remove the instance check after ExtSlice is deprecated. - if isinstance(slc, (cst.Slice, cst.Index)): - # This is deprecated, so lets not support it. - raise Exception("Unexpected Slice in Union!") - if len(slc) == 1: - # This is a Union[SimpleType,] which is equivalent to - # just SimpleType - return cst.ensure_type(slc[0].slice, cst.Index).value + if len(updated_node.slice) == 1: + # This is a Union[SimpleType,] which is equivalent to just SimpleType + return cst.ensure_type(updated_node.slice[0].slice, cst.Index).value return updated_node diff --git a/libcst/matchers/__init__.py b/libcst/matchers/__init__.py index ae0b38d1..1c7b26b2 100644 --- a/libcst/matchers/__init__.py +++ b/libcst/matchers/__init__.py @@ -11485,332 +11485,82 @@ class Subscript( AllOf[BaseExpressionMatchType], ] = DoNotCare() slice: Union[ - "Index", - "Slice", - Union[ - Sequence[ - Union[ - SubscriptElementMatchType, - DoNotCareSentinel, - OneOf[SubscriptElementMatchType], - AllOf[SubscriptElementMatchType], - AtLeastN[ - Union[ - SubscriptElementMatchType, - DoNotCareSentinel, - OneOf[SubscriptElementMatchType], - AllOf[SubscriptElementMatchType], - ] - ], - AtMostN[ - Union[ - SubscriptElementMatchType, - DoNotCareSentinel, - OneOf[SubscriptElementMatchType], - AllOf[SubscriptElementMatchType], - ] - ], - ] - ], - DoNotCareSentinel, - MatchIfTrue[Callable[[Sequence[cst.SubscriptElement]], bool]], - OneOf[ - Union[ - Sequence[ - Union[ - SubscriptElementMatchType, - OneOf[SubscriptElementMatchType], - AllOf[SubscriptElementMatchType], - AtLeastN[ - Union[ - SubscriptElementMatchType, - OneOf[SubscriptElementMatchType], - AllOf[SubscriptElementMatchType], - ] - ], - AtMostN[ - Union[ - SubscriptElementMatchType, - OneOf[SubscriptElementMatchType], - AllOf[SubscriptElementMatchType], - ] - ], - ] - ], - MatchIfTrue[Callable[[Sequence[cst.SubscriptElement]], bool]], - ] - ], - AllOf[ - Union[ - Sequence[ - Union[ - SubscriptElementMatchType, - OneOf[SubscriptElementMatchType], - AllOf[SubscriptElementMatchType], - AtLeastN[ - Union[ - SubscriptElementMatchType, - OneOf[SubscriptElementMatchType], - AllOf[SubscriptElementMatchType], - ] - ], - AtMostN[ - Union[ - SubscriptElementMatchType, - OneOf[SubscriptElementMatchType], - AllOf[SubscriptElementMatchType], - ] - ], - ] - ], - MatchIfTrue[Callable[[Sequence[cst.SubscriptElement]], bool]], - ] - ], - ], - MetadataMatchType, - MatchIfTrue[ - Callable[ - [ + Sequence[ + Union[ + SubscriptElementMatchType, + DoNotCareSentinel, + OneOf[SubscriptElementMatchType], + AllOf[SubscriptElementMatchType], + AtLeastN[ Union[ - cst.Index, - cst.Slice, - Sequence[cst.SubscriptElement], - OneOf[ - Union[cst.Index, cst.Slice, Sequence[cst.SubscriptElement]] - ], - AllOf[ - Union[cst.Index, cst.Slice, Sequence[cst.SubscriptElement]] - ], + SubscriptElementMatchType, + DoNotCareSentinel, + OneOf[SubscriptElementMatchType], + AllOf[SubscriptElementMatchType], + ] + ], + AtMostN[ + Union[ + SubscriptElementMatchType, + DoNotCareSentinel, + OneOf[SubscriptElementMatchType], + AllOf[SubscriptElementMatchType], ] ], - bool, ] ], DoNotCareSentinel, + MatchIfTrue[Callable[[Sequence[cst.SubscriptElement]], bool]], OneOf[ Union[ - "Index", - "Slice", - Union[ - Sequence[ - Union[ - SubscriptElementMatchType, - OneOf[SubscriptElementMatchType], - AllOf[SubscriptElementMatchType], - AtLeastN[ - Union[ - SubscriptElementMatchType, - OneOf[SubscriptElementMatchType], - AllOf[SubscriptElementMatchType], - ] - ], - AtMostN[ - Union[ - SubscriptElementMatchType, - OneOf[SubscriptElementMatchType], - AllOf[SubscriptElementMatchType], - ] - ], - ] - ], - MatchIfTrue[Callable[[Sequence[cst.SubscriptElement]], bool]], - OneOf[ - Union[ - Sequence[ - Union[ - SubscriptElementMatchType, - OneOf[SubscriptElementMatchType], - AllOf[SubscriptElementMatchType], - AtLeastN[ - Union[ - SubscriptElementMatchType, - OneOf[SubscriptElementMatchType], - AllOf[SubscriptElementMatchType], - ] - ], - AtMostN[ - Union[ - SubscriptElementMatchType, - OneOf[SubscriptElementMatchType], - AllOf[SubscriptElementMatchType], - ] - ], - ] - ], - MatchIfTrue[ - Callable[[Sequence[cst.SubscriptElement]], bool] - ], - ] - ], - AllOf[ - Union[ - Sequence[ - Union[ - SubscriptElementMatchType, - OneOf[SubscriptElementMatchType], - AllOf[SubscriptElementMatchType], - AtLeastN[ - Union[ - SubscriptElementMatchType, - OneOf[SubscriptElementMatchType], - AllOf[SubscriptElementMatchType], - ] - ], - AtMostN[ - Union[ - SubscriptElementMatchType, - OneOf[SubscriptElementMatchType], - AllOf[SubscriptElementMatchType], - ] - ], - ] - ], - MatchIfTrue[ - Callable[[Sequence[cst.SubscriptElement]], bool] - ], - ] - ], - ], - MetadataMatchType, - MatchIfTrue[ - Callable[ - [ + Sequence[ + Union[ + SubscriptElementMatchType, + OneOf[SubscriptElementMatchType], + AllOf[SubscriptElementMatchType], + AtLeastN[ Union[ - cst.Index, - cst.Slice, - Sequence[cst.SubscriptElement], - OneOf[ - Union[ - cst.Index, - cst.Slice, - Sequence[cst.SubscriptElement], - ] - ], - AllOf[ - Union[ - cst.Index, - cst.Slice, - Sequence[cst.SubscriptElement], - ] - ], + SubscriptElementMatchType, + OneOf[SubscriptElementMatchType], + AllOf[SubscriptElementMatchType], + ] + ], + AtMostN[ + Union[ + SubscriptElementMatchType, + OneOf[SubscriptElementMatchType], + AllOf[SubscriptElementMatchType], ] ], - bool, ] ], + MatchIfTrue[Callable[[Sequence[cst.SubscriptElement]], bool]], ] ], AllOf[ Union[ - "Index", - "Slice", - Union[ - Sequence[ - Union[ - SubscriptElementMatchType, - OneOf[SubscriptElementMatchType], - AllOf[SubscriptElementMatchType], - AtLeastN[ - Union[ - SubscriptElementMatchType, - OneOf[SubscriptElementMatchType], - AllOf[SubscriptElementMatchType], - ] - ], - AtMostN[ - Union[ - SubscriptElementMatchType, - OneOf[SubscriptElementMatchType], - AllOf[SubscriptElementMatchType], - ] - ], - ] - ], - MatchIfTrue[Callable[[Sequence[cst.SubscriptElement]], bool]], - OneOf[ - Union[ - Sequence[ - Union[ - SubscriptElementMatchType, - OneOf[SubscriptElementMatchType], - AllOf[SubscriptElementMatchType], - AtLeastN[ - Union[ - SubscriptElementMatchType, - OneOf[SubscriptElementMatchType], - AllOf[SubscriptElementMatchType], - ] - ], - AtMostN[ - Union[ - SubscriptElementMatchType, - OneOf[SubscriptElementMatchType], - AllOf[SubscriptElementMatchType], - ] - ], - ] - ], - MatchIfTrue[ - Callable[[Sequence[cst.SubscriptElement]], bool] - ], - ] - ], - AllOf[ - Union[ - Sequence[ - Union[ - SubscriptElementMatchType, - OneOf[SubscriptElementMatchType], - AllOf[SubscriptElementMatchType], - AtLeastN[ - Union[ - SubscriptElementMatchType, - OneOf[SubscriptElementMatchType], - AllOf[SubscriptElementMatchType], - ] - ], - AtMostN[ - Union[ - SubscriptElementMatchType, - OneOf[SubscriptElementMatchType], - AllOf[SubscriptElementMatchType], - ] - ], - ] - ], - MatchIfTrue[ - Callable[[Sequence[cst.SubscriptElement]], bool] - ], - ] - ], - ], - MetadataMatchType, - MatchIfTrue[ - Callable[ - [ + Sequence[ + Union[ + SubscriptElementMatchType, + OneOf[SubscriptElementMatchType], + AllOf[SubscriptElementMatchType], + AtLeastN[ Union[ - cst.Index, - cst.Slice, - Sequence[cst.SubscriptElement], - OneOf[ - Union[ - cst.Index, - cst.Slice, - Sequence[cst.SubscriptElement], - ] - ], - AllOf[ - Union[ - cst.Index, - cst.Slice, - Sequence[cst.SubscriptElement], - ] - ], + SubscriptElementMatchType, + OneOf[SubscriptElementMatchType], + AllOf[SubscriptElementMatchType], + ] + ], + AtMostN[ + Union[ + SubscriptElementMatchType, + OneOf[SubscriptElementMatchType], + AllOf[SubscriptElementMatchType], ] ], - bool, ] ], + MatchIfTrue[Callable[[Sequence[cst.SubscriptElement]], bool]], ] ], ] = DoNotCare() @@ -13278,7 +13028,6 @@ class Yield(BaseExpression, BaseMatcherNode): ] = DoNotCare() -ExtSlice = SubscriptElement __all__ = [ "Add", "AddAssign", @@ -13362,7 +13111,6 @@ __all__ = [ "Equal", "ExceptHandler", "Expr", - "ExtSlice", "Finally", "Float", "FloorDivide", diff --git a/libcst/tests/test_deprecate_extslice.py b/libcst/tests/test_deprecate_extslice.py deleted file mode 100644 index 6e1036b0..00000000 --- a/libcst/tests/test_deprecate_extslice.py +++ /dev/null @@ -1,122 +0,0 @@ -# Copyright (c) Facebook, Inc. and its affiliates. -# -# This source code is licensed under the MIT license found in the -# LICENSE file in the root directory of this source tree. -from typing import Set - -import libcst as cst -import libcst.matchers as m -from libcst.testing.utils import UnitTest - - -# TODO: Remove this once we completely remove ExtSlice. -class ExtSliceDeprecatedUseTest(UnitTest): - """ - Test that various code which refers to "SubscriptElement" as "ExtSlice" continues - to operate as expected. - """ - - def test_deprecated_construction(self) -> None: - module = cst.Module( - body=[ - cst.SimpleStatementLine( - body=[ - cst.Expr( - value=cst.Subscript( - value=cst.Name(value="foo"), - slice=[ - cst.ExtSlice( - slice=cst.Index(value=cst.Integer(value="1")) - ), - cst.ExtSlice( - slice=cst.Index(value=cst.Integer(value="2")) - ), - ], - ) - ) - ] - ) - ] - ) - - self.assertEqual(module.code, "foo[1, 2]\n") - - def test_deprecated_non_element_construction(self) -> None: - module = cst.Module( - body=[ - cst.SimpleStatementLine( - body=[ - cst.Expr( - value=cst.Subscript( - value=cst.Name(value="foo"), - slice=cst.Index(value=cst.Integer(value="1")), - ) - ) - ] - ) - ] - ) - - self.assertEqual(module.code, "foo[1]\n") - - def test_deprecated_matching(self) -> None: - class DeprecatedDecoratorTest(m.MatcherDecoratableVisitor): - def __init__(self) -> None: - super().__init__() - self.calls: Set[str] = set() - - @m.visit(m.ExtSlice()) - def _deprecated_visitor(self, node: cst.ExtSlice) -> None: - if m.matches(node, m.ExtSlice(m.Index(m.Integer("2")))): - self.calls.add("called") - - module = cst.parse_module("foo[1, 2]\n") - visitor = DeprecatedDecoratorTest() - module.visit(visitor) - self.assertEqual(visitor.calls, {"called"}) - - def test_deprecated_visiting(self) -> None: - class DeprecatedDecoratorTest(m.MatcherDecoratableVisitor): - def __init__(self) -> None: - super().__init__() - self.visits: Set[str] = set() - self.leaves: Set[str] = set() - - def visit_ExtSlice(self, node: cst.ExtSlice) -> None: - self.visits.add( - "node " - + cst.ensure_type( - cst.ensure_type(node.slice, cst.Index).value, cst.Integer - ).value - ) - - def visit_ExtSlice_slice(self, node: cst.ExtSlice) -> None: - self.visits.add( - "attr " - + cst.ensure_type( - cst.ensure_type(node.slice, cst.Index).value, cst.Integer - ).value - ) - - def leave_ExtSlice(self, original_node: cst.ExtSlice) -> None: - self.leaves.add( - "node " - + cst.ensure_type( - cst.ensure_type(original_node.slice, cst.Index).value, - cst.Integer, - ).value - ) - - def leave_ExtSlice_slice(self, node: cst.ExtSlice) -> None: - self.leaves.add( - "attr " - + cst.ensure_type( - cst.ensure_type(node.slice, cst.Index).value, cst.Integer - ).value - ) - - module = cst.parse_module("foo[1, 2]\n") - visitor = DeprecatedDecoratorTest() - module.visit(visitor) - self.assertEqual(visitor.visits, {"node 1", "node 2", "attr 1", "attr 2"}) - self.assertEqual(visitor.leaves, {"node 1", "node 2", "attr 1", "attr 2"})