diff --git a/libcst/codegen/gen_matcher_classes.py b/libcst/codegen/gen_matcher_classes.py index b0657890d..7bb7120d3 100644 --- a/libcst/codegen/gen_matcher_classes.py +++ b/libcst/codegen/gen_matcher_classes.py @@ -3,6 +3,7 @@ # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. +import re from dataclasses import dataclass, fields from typing import Generator, List, Optional, Sequence, Set, Tuple, Type, Union @@ -12,6 +13,8 @@ CST_DIR: Set[str] = set(dir(cst)) +CLASS_RE = r"" +OPTIONAL_RE = r"typing\.Union\[([^,]*?), NoneType]" class CleanseFullTypeNames(cst.CSTTransformer): @@ -396,8 +399,8 @@ def _get_clean_type_and_aliases( # First, get the type as a parseable expression. typestr = repr(typeobj) - if typestr.startswith(""): - typestr = typestr[8:-2] + typestr = re.sub(CLASS_RE, r"\1", typestr) + typestr = re.sub(OPTIONAL_RE, r"typing.Optional[\1]", typestr) # Now, parse the expression with LibCST. cleanser = CleanseFullTypeNames() @@ -457,7 +460,7 @@ def _get_fields(node: Type[cst.CSTNode]) -> Generator[Field, None, None]: generated_code.append("") generated_code.append("# This file was generated by libcst.codegen.gen_matcher_classes") generated_code.append("from dataclasses import dataclass") -generated_code.append("from typing import Callable, Sequence, Union") +generated_code.append("from typing import Callable, Optional, Sequence, Union") generated_code.append("from typing_extensions import Literal") generated_code.append("import libcst as cst") generated_code.append("") diff --git a/libcst/matchers/__init__.py b/libcst/matchers/__init__.py index 73b3e7f26..8b7ba63f2 100644 --- a/libcst/matchers/__init__.py +++ b/libcst/matchers/__init__.py @@ -6,7 +6,7 @@ # This file was generated by libcst.codegen.gen_matcher_classes from dataclasses import dataclass -from typing import Callable, Sequence, Union +from typing import Callable, Optional, Sequence, Union from typing_extensions import Literal @@ -231,12 +231,6 @@ class And(BaseBooleanOp, BaseMatcherNode): AnnotationMatchType = Union[ "Annotation", MetadataMatchType, MatchIfTrue[Callable[[cst.Annotation], bool]] ] -BaseExpressionOrNoneMatchType = Union[ - "BaseExpression", - None, - MetadataMatchType, - MatchIfTrue[Callable[[Union[cst.BaseExpression, None]], bool]], -] AssignEqualMatchType = Union[ "AssignEqual", MetadataMatchType, MatchIfTrue[Callable[[cst.AssignEqual], bool]] ] @@ -260,10 +254,24 @@ class AnnAssign(BaseSmallStatement, BaseMatcherNode): AllOf[AnnotationMatchType], ] = DoNotCare() value: Union[ - BaseExpressionOrNoneMatchType, + Optional["BaseExpression"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.BaseExpression]], bool]], DoNotCareSentinel, - OneOf[BaseExpressionOrNoneMatchType], - AllOf[BaseExpressionOrNoneMatchType], + OneOf[ + Union[ + Optional["BaseExpression"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.BaseExpression]], bool]], + ] + ], + AllOf[ + Union[ + Optional["BaseExpression"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.BaseExpression]], bool]], + ] + ], ] = DoNotCare() equal: Union[ AssignEqualMatchType, @@ -320,12 +328,6 @@ class Annotation(BaseMatcherNode): ] = DoNotCare() -NameOrNoneMatchType = Union[ - "Name", - None, - MetadataMatchType, - MatchIfTrue[Callable[[Union[cst.Name, None]], bool]], -] CommaMatchType = Union[ "Comma", MetadataMatchType, MatchIfTrue[Callable[[cst.Comma], bool]] ] @@ -340,10 +342,24 @@ class Arg(BaseMatcherNode): AllOf[BaseExpressionMatchType], ] = DoNotCare() keyword: Union[ - NameOrNoneMatchType, + Optional["Name"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.Name]], bool]], DoNotCareSentinel, - OneOf[NameOrNoneMatchType], - AllOf[NameOrNoneMatchType], + OneOf[ + Union[ + Optional["Name"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.Name]], bool]], + ] + ], + AllOf[ + Union[ + Optional["Name"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.Name]], bool]], + ] + ], ] = DoNotCare() equal: Union[ AssignEqualMatchType, @@ -447,10 +463,24 @@ class Assert(BaseSmallStatement, BaseMatcherNode): AllOf[BaseExpressionMatchType], ] = DoNotCare() msg: Union[ - BaseExpressionOrNoneMatchType, + Optional["BaseExpression"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.BaseExpression]], bool]], DoNotCareSentinel, - OneOf[BaseExpressionOrNoneMatchType], - AllOf[BaseExpressionOrNoneMatchType], + OneOf[ + Union[ + Optional["BaseExpression"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.BaseExpression]], bool]], + ] + ], + AllOf[ + Union[ + Optional["BaseExpression"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.BaseExpression]], bool]], + ] + ], ] = DoNotCare() comma: Union[ CommaMatchType, DoNotCareSentinel, OneOf[CommaMatchType], AllOf[CommaMatchType] @@ -2385,18 +2415,6 @@ class Comment(BaseMatcherNode): CompIfMatchType = Union[ "CompIf", MetadataMatchType, MatchIfTrue[Callable[[cst.CompIf], bool]] ] -CompForOrNoneMatchType = Union[ - "CompFor", - None, - MetadataMatchType, - MatchIfTrue[Callable[[Union[cst.CompFor, None]], bool]], -] -AsynchronousOrNoneMatchType = Union[ - "Asynchronous", - None, - MetadataMatchType, - MatchIfTrue[Callable[[Union[cst.Asynchronous, None]], bool]], -] @dataclass(frozen=True, eq=False, unsafe_hash=False) @@ -2494,16 +2512,44 @@ class CompFor(BaseMatcherNode): ], ] = DoNotCare() inner_for_in: Union[ - CompForOrNoneMatchType, + Optional["CompFor"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.CompFor]], bool]], DoNotCareSentinel, - OneOf[CompForOrNoneMatchType], - AllOf[CompForOrNoneMatchType], + OneOf[ + Union[ + Optional["CompFor"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.CompFor]], bool]], + ] + ], + AllOf[ + Union[ + Optional["CompFor"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.CompFor]], bool]], + ] + ], ] = DoNotCare() asynchronous: Union[ - AsynchronousOrNoneMatchType, + Optional["Asynchronous"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.Asynchronous]], bool]], DoNotCareSentinel, - OneOf[AsynchronousOrNoneMatchType], - AllOf[AsynchronousOrNoneMatchType], + OneOf[ + Union[ + Optional["Asynchronous"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.Asynchronous]], bool]], + ] + ], + AllOf[ + Union[ + Optional["Asynchronous"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.Asynchronous]], bool]], + ] + ], ] = DoNotCare() whitespace_before: Union[ BaseParenthesizableWhitespaceMatchType, @@ -4126,12 +4172,6 @@ class Else(BaseMatcherNode): boolMatchType = Union[bool, MetadataMatchType, MatchIfTrue[Callable[[bool], bool]]] -CommentOrNoneMatchType = Union[ - "Comment", - None, - MetadataMatchType, - MatchIfTrue[Callable[[Union[cst.Comment, None]], bool]], -] NewlineMatchType = Union[ "Newline", MetadataMatchType, MatchIfTrue[Callable[[cst.Newline], bool]] ] @@ -4149,10 +4189,24 @@ class EmptyLine(BaseMatcherNode): AllOf[SimpleWhitespaceMatchType], ] = DoNotCare() comment: Union[ - CommentOrNoneMatchType, + Optional["Comment"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.Comment]], bool]], DoNotCareSentinel, - OneOf[CommentOrNoneMatchType], - AllOf[CommentOrNoneMatchType], + OneOf[ + Union[ + Optional["Comment"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.Comment]], bool]], + ] + ], + AllOf[ + Union[ + Optional["Comment"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.Comment]], bool]], + ] + ], ] = DoNotCare() newline: Union[ NewlineMatchType, @@ -4190,14 +4244,6 @@ class Equal(BaseCompOp, BaseMatcherNode): ] = DoNotCare() -AsNameOrNoneMatchType = Union[ - "AsName", - None, - MetadataMatchType, - MatchIfTrue[Callable[[Union[cst.AsName, None]], bool]], -] - - @dataclass(frozen=True, eq=False, unsafe_hash=False) class ExceptHandler(BaseMatcherNode): body: Union[ @@ -4207,16 +4253,44 @@ class ExceptHandler(BaseMatcherNode): AllOf[BaseSuiteMatchType], ] = DoNotCare() type: Union[ - BaseExpressionOrNoneMatchType, + Optional["BaseExpression"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.BaseExpression]], bool]], DoNotCareSentinel, - OneOf[BaseExpressionOrNoneMatchType], - AllOf[BaseExpressionOrNoneMatchType], + OneOf[ + Union[ + Optional["BaseExpression"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.BaseExpression]], bool]], + ] + ], + AllOf[ + Union[ + Optional["BaseExpression"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.BaseExpression]], bool]], + ] + ], ] = DoNotCare() name: Union[ - AsNameOrNoneMatchType, + Optional["AsName"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.AsName]], bool]], DoNotCareSentinel, - OneOf[AsNameOrNoneMatchType], - AllOf[AsNameOrNoneMatchType], + OneOf[ + Union[ + Optional["AsName"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.AsName]], bool]], + ] + ], + AllOf[ + Union[ + Optional["AsName"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.AsName]], bool]], + ] + ], ] = DoNotCare() leading_lines: Union[ Sequence[ @@ -4659,14 +4733,6 @@ class FloorDivideAssign(BaseAugOp, BaseMatcherNode): ] = DoNotCare() -ElseOrNoneMatchType = Union[ - "Else", - None, - MetadataMatchType, - MatchIfTrue[Callable[[Union[cst.Else, None]], bool]], -] - - @dataclass(frozen=True, eq=False, unsafe_hash=False) class For(BaseCompoundStatement, BaseStatement, BaseMatcherNode): target: Union[ @@ -4688,16 +4754,44 @@ class For(BaseCompoundStatement, BaseStatement, BaseMatcherNode): AllOf[BaseSuiteMatchType], ] = DoNotCare() orelse: Union[ - ElseOrNoneMatchType, + Optional["Else"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.Else]], bool]], DoNotCareSentinel, - OneOf[ElseOrNoneMatchType], - AllOf[ElseOrNoneMatchType], + OneOf[ + Union[ + Optional["Else"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.Else]], bool]], + ] + ], + AllOf[ + Union[ + Optional["Else"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.Else]], bool]], + ] + ], ] = DoNotCare() asynchronous: Union[ - AsynchronousOrNoneMatchType, + Optional["Asynchronous"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.Asynchronous]], bool]], DoNotCareSentinel, - OneOf[AsynchronousOrNoneMatchType], - AllOf[AsynchronousOrNoneMatchType], + OneOf[ + Union[ + Optional["Asynchronous"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.Asynchronous]], bool]], + ] + ], + AllOf[ + Union[ + Optional["Asynchronous"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.Asynchronous]], bool]], + ] + ], ] = DoNotCare() leading_lines: Union[ Sequence[ @@ -5091,17 +5185,6 @@ class FormattedString(BaseExpression, BaseString, BaseMatcherNode): ] = DoNotCare() -strOrNoneMatchType = Union[ - str, None, MetadataMatchType, MatchIfTrue[Callable[[Union[str, None]], bool]] -] -AssignEqualOrNoneMatchType = Union[ - "AssignEqual", - None, - MetadataMatchType, - MatchIfTrue[Callable[[Union[cst.AssignEqual, None]], bool]], -] - - @dataclass(frozen=True, eq=False, unsafe_hash=False) class FormattedStringExpression(BaseFormattedStringContent, BaseMatcherNode): expression: Union[ @@ -5111,335 +5194,47 @@ class FormattedStringExpression(BaseFormattedStringContent, BaseMatcherNode): AllOf[BaseExpressionMatchType], ] = DoNotCare() conversion: Union[ - strOrNoneMatchType, + Optional[str], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[str]], bool]], DoNotCareSentinel, - OneOf[strOrNoneMatchType], - AllOf[strOrNoneMatchType], + OneOf[ + Union[ + Optional[str], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[str]], bool]], + ] + ], + AllOf[ + Union[ + Optional[str], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[str]], bool]], + ] + ], ] = DoNotCare() format_spec: Union[ - Union[ - Sequence[ - Union[ - BaseFormattedStringContentMatchType, - DoNotCareSentinel, - OneOf[BaseFormattedStringContentMatchType], - AllOf[BaseFormattedStringContentMatchType], - AtLeastN[ - Union[ - BaseFormattedStringContentMatchType, - DoNotCareSentinel, - OneOf[BaseFormattedStringContentMatchType], - AllOf[BaseFormattedStringContentMatchType], - ] - ], - AtMostN[ - Union[ - BaseFormattedStringContentMatchType, - DoNotCareSentinel, - OneOf[BaseFormattedStringContentMatchType], - AllOf[BaseFormattedStringContentMatchType], - ] - ], - ] - ], - DoNotCareSentinel, - MatchIfTrue[Callable[[Sequence[cst.BaseFormattedStringContent]], bool]], - OneOf[ - Union[ - Sequence[ - Union[ - BaseFormattedStringContentMatchType, - OneOf[BaseFormattedStringContentMatchType], - AllOf[BaseFormattedStringContentMatchType], - AtLeastN[ - Union[ - BaseFormattedStringContentMatchType, - OneOf[BaseFormattedStringContentMatchType], - AllOf[BaseFormattedStringContentMatchType], - ] - ], - AtMostN[ - Union[ - BaseFormattedStringContentMatchType, - OneOf[BaseFormattedStringContentMatchType], - AllOf[BaseFormattedStringContentMatchType], - ] - ], - ] - ], - MatchIfTrue[ - Callable[[Sequence[cst.BaseFormattedStringContent]], bool] - ], - ] - ], - AllOf[ - Union[ - Sequence[ - Union[ - BaseFormattedStringContentMatchType, - OneOf[BaseFormattedStringContentMatchType], - AllOf[BaseFormattedStringContentMatchType], - AtLeastN[ - Union[ - BaseFormattedStringContentMatchType, - OneOf[BaseFormattedStringContentMatchType], - AllOf[BaseFormattedStringContentMatchType], - ] - ], - AtMostN[ - Union[ - BaseFormattedStringContentMatchType, - OneOf[BaseFormattedStringContentMatchType], - AllOf[BaseFormattedStringContentMatchType], - ] - ], - ] - ], - MatchIfTrue[ - Callable[[Sequence[cst.BaseFormattedStringContent]], bool] - ], - ] - ], - ], - None, + Optional[Sequence["BaseFormattedStringContent"]], MetadataMatchType, MatchIfTrue[ - Callable[ - [ - Union[ - Sequence[cst.BaseFormattedStringContent], - None, - OneOf[Union[Sequence[cst.BaseFormattedStringContent], None]], - AllOf[Union[Sequence[cst.BaseFormattedStringContent], None]], - ] - ], - bool, - ] + Callable[[Optional[Sequence[cst.BaseFormattedStringContent]]], bool] ], DoNotCareSentinel, OneOf[ Union[ - Union[ - Sequence[ - Union[ - BaseFormattedStringContentMatchType, - OneOf[BaseFormattedStringContentMatchType], - AllOf[BaseFormattedStringContentMatchType], - AtLeastN[ - Union[ - BaseFormattedStringContentMatchType, - OneOf[BaseFormattedStringContentMatchType], - AllOf[BaseFormattedStringContentMatchType], - ] - ], - AtMostN[ - Union[ - BaseFormattedStringContentMatchType, - OneOf[BaseFormattedStringContentMatchType], - AllOf[BaseFormattedStringContentMatchType], - ] - ], - ] - ], - MatchIfTrue[ - Callable[[Sequence[cst.BaseFormattedStringContent]], bool] - ], - OneOf[ - Union[ - Sequence[ - Union[ - BaseFormattedStringContentMatchType, - OneOf[BaseFormattedStringContentMatchType], - AllOf[BaseFormattedStringContentMatchType], - AtLeastN[ - Union[ - BaseFormattedStringContentMatchType, - OneOf[BaseFormattedStringContentMatchType], - AllOf[BaseFormattedStringContentMatchType], - ] - ], - AtMostN[ - Union[ - BaseFormattedStringContentMatchType, - OneOf[BaseFormattedStringContentMatchType], - AllOf[BaseFormattedStringContentMatchType], - ] - ], - ] - ], - MatchIfTrue[ - Callable[ - [Sequence[cst.BaseFormattedStringContent]], bool - ] - ], - ] - ], - AllOf[ - Union[ - Sequence[ - Union[ - BaseFormattedStringContentMatchType, - OneOf[BaseFormattedStringContentMatchType], - AllOf[BaseFormattedStringContentMatchType], - AtLeastN[ - Union[ - BaseFormattedStringContentMatchType, - OneOf[BaseFormattedStringContentMatchType], - AllOf[BaseFormattedStringContentMatchType], - ] - ], - AtMostN[ - Union[ - BaseFormattedStringContentMatchType, - OneOf[BaseFormattedStringContentMatchType], - AllOf[BaseFormattedStringContentMatchType], - ] - ], - ] - ], - MatchIfTrue[ - Callable[ - [Sequence[cst.BaseFormattedStringContent]], bool - ] - ], - ] - ], - ], - None, + Optional[Sequence["BaseFormattedStringContent"]], MetadataMatchType, MatchIfTrue[ - Callable[ - [ - Union[ - Sequence[cst.BaseFormattedStringContent], - None, - OneOf[ - Union[ - Sequence[cst.BaseFormattedStringContent], None - ] - ], - AllOf[ - Union[ - Sequence[cst.BaseFormattedStringContent], None - ] - ], - ] - ], - bool, - ] + Callable[[Optional[Sequence[cst.BaseFormattedStringContent]]], bool] ], ] ], AllOf[ Union[ - Union[ - Sequence[ - Union[ - BaseFormattedStringContentMatchType, - OneOf[BaseFormattedStringContentMatchType], - AllOf[BaseFormattedStringContentMatchType], - AtLeastN[ - Union[ - BaseFormattedStringContentMatchType, - OneOf[BaseFormattedStringContentMatchType], - AllOf[BaseFormattedStringContentMatchType], - ] - ], - AtMostN[ - Union[ - BaseFormattedStringContentMatchType, - OneOf[BaseFormattedStringContentMatchType], - AllOf[BaseFormattedStringContentMatchType], - ] - ], - ] - ], - MatchIfTrue[ - Callable[[Sequence[cst.BaseFormattedStringContent]], bool] - ], - OneOf[ - Union[ - Sequence[ - Union[ - BaseFormattedStringContentMatchType, - OneOf[BaseFormattedStringContentMatchType], - AllOf[BaseFormattedStringContentMatchType], - AtLeastN[ - Union[ - BaseFormattedStringContentMatchType, - OneOf[BaseFormattedStringContentMatchType], - AllOf[BaseFormattedStringContentMatchType], - ] - ], - AtMostN[ - Union[ - BaseFormattedStringContentMatchType, - OneOf[BaseFormattedStringContentMatchType], - AllOf[BaseFormattedStringContentMatchType], - ] - ], - ] - ], - MatchIfTrue[ - Callable[ - [Sequence[cst.BaseFormattedStringContent]], bool - ] - ], - ] - ], - AllOf[ - Union[ - Sequence[ - Union[ - BaseFormattedStringContentMatchType, - OneOf[BaseFormattedStringContentMatchType], - AllOf[BaseFormattedStringContentMatchType], - AtLeastN[ - Union[ - BaseFormattedStringContentMatchType, - OneOf[BaseFormattedStringContentMatchType], - AllOf[BaseFormattedStringContentMatchType], - ] - ], - AtMostN[ - Union[ - BaseFormattedStringContentMatchType, - OneOf[BaseFormattedStringContentMatchType], - AllOf[BaseFormattedStringContentMatchType], - ] - ], - ] - ], - MatchIfTrue[ - Callable[ - [Sequence[cst.BaseFormattedStringContent]], bool - ] - ], - ] - ], - ], - None, + Optional[Sequence["BaseFormattedStringContent"]], MetadataMatchType, MatchIfTrue[ - Callable[ - [ - Union[ - Sequence[cst.BaseFormattedStringContent], - None, - OneOf[ - Union[ - Sequence[cst.BaseFormattedStringContent], None - ] - ], - AllOf[ - Union[ - Sequence[cst.BaseFormattedStringContent], None - ] - ], - ] - ], - bool, - ] + Callable[[Optional[Sequence[cst.BaseFormattedStringContent]]], bool] ], ] ], @@ -5457,10 +5252,24 @@ class FormattedStringExpression(BaseFormattedStringContent, BaseMatcherNode): AllOf[BaseParenthesizableWhitespaceMatchType], ] = DoNotCare() equal: Union[ - AssignEqualOrNoneMatchType, + Optional["AssignEqual"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.AssignEqual]], bool]], DoNotCareSentinel, - OneOf[AssignEqualOrNoneMatchType], - AllOf[AssignEqualOrNoneMatchType], + OneOf[ + Union[ + Optional["AssignEqual"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.AssignEqual]], bool]], + ] + ], + AllOf[ + Union[ + Optional["AssignEqual"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.AssignEqual]], bool]], + ] + ], ] = DoNotCare() metadata: Union[ MetadataMatchType, @@ -5514,12 +5323,6 @@ class From(BaseMatcherNode): ParametersMatchType = Union[ "Parameters", MetadataMatchType, MatchIfTrue[Callable[[cst.Parameters], bool]] ] -AnnotationOrNoneMatchType = Union[ - "Annotation", - None, - MetadataMatchType, - MatchIfTrue[Callable[[Union[cst.Annotation, None]], bool]], -] @dataclass(frozen=True, eq=False, unsafe_hash=False) @@ -5619,17 +5422,45 @@ class FunctionDef(BaseCompoundStatement, BaseStatement, BaseMatcherNode): ] ], ] = DoNotCare() - returns: Union[ - AnnotationOrNoneMatchType, - DoNotCareSentinel, - OneOf[AnnotationOrNoneMatchType], - AllOf[AnnotationOrNoneMatchType], - ] = DoNotCare() + returns: Union[ + Optional["Annotation"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.Annotation]], bool]], + DoNotCareSentinel, + OneOf[ + Union[ + Optional["Annotation"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.Annotation]], bool]], + ] + ], + AllOf[ + Union[ + Optional["Annotation"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.Annotation]], bool]], + ] + ], + ] = DoNotCare() asynchronous: Union[ - AsynchronousOrNoneMatchType, + Optional["Asynchronous"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.Asynchronous]], bool]], DoNotCareSentinel, - OneOf[AsynchronousOrNoneMatchType], - AllOf[AsynchronousOrNoneMatchType], + OneOf[ + Union[ + Optional["Asynchronous"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.Asynchronous]], bool]], + ] + ], + AllOf[ + Union[ + Optional["Asynchronous"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.Asynchronous]], bool]], + ] + ], ] = DoNotCare() leading_lines: Union[ Sequence[ @@ -6794,10 +6625,24 @@ class ImportAlias(BaseMatcherNode): AllOf[AttributeOrNameMatchType], ] = DoNotCare() asname: Union[ - AsNameOrNoneMatchType, + Optional["AsName"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.AsName]], bool]], DoNotCareSentinel, - OneOf[AsNameOrNoneMatchType], - AllOf[AsNameOrNoneMatchType], + OneOf[ + Union[ + Optional["AsName"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.AsName]], bool]], + ] + ], + AllOf[ + Union[ + Optional["AsName"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.AsName]], bool]], + ] + ], ] = DoNotCare() comma: Union[ CommaMatchType, DoNotCareSentinel, OneOf[CommaMatchType], AllOf[CommaMatchType] @@ -6817,18 +6662,6 @@ class ImportAlias(BaseMatcherNode): MetadataMatchType, MatchIfTrue[Callable[[Union[cst.Attribute, cst.Name, None]], bool]], ] -LeftParenOrNoneMatchType = Union[ - "LeftParen", - None, - MetadataMatchType, - MatchIfTrue[Callable[[Union[cst.LeftParen, None]], bool]], -] -RightParenOrNoneMatchType = Union[ - "RightParen", - None, - MetadataMatchType, - MatchIfTrue[Callable[[Union[cst.RightParen, None]], bool]], -] @dataclass(frozen=True, eq=False, unsafe_hash=False) @@ -7200,16 +7033,44 @@ class ImportFrom(BaseSmallStatement, BaseMatcherNode): ], ] = DoNotCare() lpar: Union[ - LeftParenOrNoneMatchType, + Optional["LeftParen"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.LeftParen]], bool]], DoNotCareSentinel, - OneOf[LeftParenOrNoneMatchType], - AllOf[LeftParenOrNoneMatchType], + OneOf[ + Union[ + Optional["LeftParen"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.LeftParen]], bool]], + ] + ], + AllOf[ + Union[ + Optional["LeftParen"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.LeftParen]], bool]], + ] + ], ] = DoNotCare() rpar: Union[ - RightParenOrNoneMatchType, + Optional["RightParen"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.RightParen]], bool]], DoNotCareSentinel, - OneOf[RightParenOrNoneMatchType], - AllOf[RightParenOrNoneMatchType], + OneOf[ + Union[ + Optional["RightParen"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.RightParen]], bool]], + ] + ], + AllOf[ + Union[ + Optional["RightParen"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.RightParen]], bool]], + ] + ], ] = DoNotCare() semicolon: Union[ SemicolonMatchType, @@ -7369,10 +7230,24 @@ class IndentedBlock(BaseSuite, BaseMatcherNode): AllOf[TrailingWhitespaceMatchType], ] = DoNotCare() indent: Union[ - strOrNoneMatchType, + Optional[str], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[str]], bool]], DoNotCareSentinel, - OneOf[strOrNoneMatchType], - AllOf[strOrNoneMatchType], + OneOf[ + Union[ + Optional[str], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[str]], bool]], + ] + ], + AllOf[ + Union[ + Optional[str], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[str]], bool]], + ] + ], ] = DoNotCare() footer: Union[ Sequence[ @@ -9404,10 +9279,24 @@ class NamedExpr(BaseExpression, BaseMatcherNode): @dataclass(frozen=True, eq=False, unsafe_hash=False) class Newline(BaseMatcherNode): value: Union[ - strOrNoneMatchType, + Optional[str], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[str]], bool]], DoNotCareSentinel, - OneOf[strOrNoneMatchType], - AllOf[strOrNoneMatchType], + OneOf[ + Union[ + Optional[str], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[str]], bool]], + ] + ], + AllOf[ + Union[ + Optional[str], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[str]], bool]], + ] + ], ] = DoNotCare() metadata: Union[ MetadataMatchType, @@ -9616,10 +9505,24 @@ class Param(BaseMatcherNode): NameMatchType, DoNotCareSentinel, OneOf[NameMatchType], AllOf[NameMatchType] ] = DoNotCare() annotation: Union[ - AnnotationOrNoneMatchType, + Optional["Annotation"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.Annotation]], bool]], DoNotCareSentinel, - OneOf[AnnotationOrNoneMatchType], - AllOf[AnnotationOrNoneMatchType], + OneOf[ + Union[ + Optional["Annotation"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.Annotation]], bool]], + ] + ], + AllOf[ + Union[ + Optional["Annotation"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.Annotation]], bool]], + ] + ], ] = DoNotCare() equal: Union[ AssignEqualMatchType, @@ -9628,10 +9531,24 @@ class Param(BaseMatcherNode): AllOf[AssignEqualMatchType], ] = DoNotCare() default: Union[ - BaseExpressionOrNoneMatchType, + Optional["BaseExpression"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.BaseExpression]], bool]], DoNotCareSentinel, - OneOf[BaseExpressionOrNoneMatchType], - AllOf[BaseExpressionOrNoneMatchType], + OneOf[ + Union[ + Optional["BaseExpression"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.BaseExpression]], bool]], + ] + ], + AllOf[ + Union[ + Optional["BaseExpression"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.BaseExpression]], bool]], + ] + ], ] = DoNotCare() comma: Union[ CommaMatchType, DoNotCareSentinel, OneOf[CommaMatchType], AllOf[CommaMatchType] @@ -9694,12 +9611,6 @@ class ParamStar(BaseMatcherNode): MetadataMatchType, MatchIfTrue[Callable[[Union[cst.Param, cst.ParamStar]], bool]], ] -ParamOrNoneMatchType = Union[ - "Param", - None, - MetadataMatchType, - MatchIfTrue[Callable[[Union[cst.Param, None]], bool]], -] ParamSlashMatchType = Union[ "ParamSlash", MetadataMatchType, MatchIfTrue[Callable[[cst.ParamSlash], bool]] ] @@ -9874,10 +9785,24 @@ class Parameters(BaseMatcherNode): ], ] = DoNotCare() star_kwarg: Union[ - ParamOrNoneMatchType, + Optional["Param"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.Param]], bool]], DoNotCareSentinel, - OneOf[ParamOrNoneMatchType], - AllOf[ParamOrNoneMatchType], + OneOf[ + Union[ + Optional["Param"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.Param]], bool]], + ] + ], + AllOf[ + Union[ + Optional["Param"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.Param]], bool]], + ] + ], ] = DoNotCare() posonly_params: Union[ Sequence[ @@ -10154,27 +10079,47 @@ class PowerAssign(BaseAugOp, BaseMatcherNode): ] = DoNotCare() -FromOrNoneMatchType = Union[ - "From", - None, - MetadataMatchType, - MatchIfTrue[Callable[[Union[cst.From, None]], bool]], -] - - @dataclass(frozen=True, eq=False, unsafe_hash=False) class Raise(BaseSmallStatement, BaseMatcherNode): exc: Union[ - BaseExpressionOrNoneMatchType, + Optional["BaseExpression"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.BaseExpression]], bool]], DoNotCareSentinel, - OneOf[BaseExpressionOrNoneMatchType], - AllOf[BaseExpressionOrNoneMatchType], + OneOf[ + Union[ + Optional["BaseExpression"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.BaseExpression]], bool]], + ] + ], + AllOf[ + Union[ + Optional["BaseExpression"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.BaseExpression]], bool]], + ] + ], ] = DoNotCare() cause: Union[ - FromOrNoneMatchType, + Optional["From"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.From]], bool]], DoNotCareSentinel, - OneOf[FromOrNoneMatchType], - AllOf[FromOrNoneMatchType], + OneOf[ + Union[ + Optional["From"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.From]], bool]], + ] + ], + AllOf[ + Union[ + Optional["From"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.From]], bool]], + ] + ], ] = DoNotCare() whitespace_after_raise: Union[ SimpleWhitespaceMatchType, @@ -10199,10 +10144,24 @@ class Raise(BaseSmallStatement, BaseMatcherNode): @dataclass(frozen=True, eq=False, unsafe_hash=False) class Return(BaseSmallStatement, BaseMatcherNode): value: Union[ - BaseExpressionOrNoneMatchType, + Optional["BaseExpression"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.BaseExpression]], bool]], DoNotCareSentinel, - OneOf[BaseExpressionOrNoneMatchType], - AllOf[BaseExpressionOrNoneMatchType], + OneOf[ + Union[ + Optional["BaseExpression"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.BaseExpression]], bool]], + ] + ], + AllOf[ + Union[ + Optional["BaseExpression"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.BaseExpression]], bool]], + ] + ], ] = DoNotCare() whitespace_after_return: Union[ SimpleWhitespaceMatchType, @@ -11268,22 +11227,64 @@ class SimpleWhitespace(BaseParenthesizableWhitespace, BaseMatcherNode): @dataclass(frozen=True, eq=False, unsafe_hash=False) class Slice(BaseSlice, BaseMatcherNode): lower: Union[ - BaseExpressionOrNoneMatchType, + Optional["BaseExpression"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.BaseExpression]], bool]], DoNotCareSentinel, - OneOf[BaseExpressionOrNoneMatchType], - AllOf[BaseExpressionOrNoneMatchType], + OneOf[ + Union[ + Optional["BaseExpression"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.BaseExpression]], bool]], + ] + ], + AllOf[ + Union[ + Optional["BaseExpression"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.BaseExpression]], bool]], + ] + ], ] = DoNotCare() upper: Union[ - BaseExpressionOrNoneMatchType, + Optional["BaseExpression"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.BaseExpression]], bool]], DoNotCareSentinel, - OneOf[BaseExpressionOrNoneMatchType], - AllOf[BaseExpressionOrNoneMatchType], + OneOf[ + Union[ + Optional["BaseExpression"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.BaseExpression]], bool]], + ] + ], + AllOf[ + Union[ + Optional["BaseExpression"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.BaseExpression]], bool]], + ] + ], ] = DoNotCare() step: Union[ - BaseExpressionOrNoneMatchType, + Optional["BaseExpression"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.BaseExpression]], bool]], DoNotCareSentinel, - OneOf[BaseExpressionOrNoneMatchType], - AllOf[BaseExpressionOrNoneMatchType], + OneOf[ + Union[ + Optional["BaseExpression"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.BaseExpression]], bool]], + ] + ], + AllOf[ + Union[ + Optional["BaseExpression"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.BaseExpression]], bool]], + ] + ], ] = DoNotCare() first_colon: Union[ ColonMatchType, DoNotCareSentinel, OneOf[ColonMatchType], AllOf[ColonMatchType] @@ -11869,10 +11870,24 @@ class TrailingWhitespace(BaseMatcherNode): AllOf[SimpleWhitespaceMatchType], ] = DoNotCare() comment: Union[ - CommentOrNoneMatchType, + Optional["Comment"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.Comment]], bool]], DoNotCareSentinel, - OneOf[CommentOrNoneMatchType], - AllOf[CommentOrNoneMatchType], + OneOf[ + Union[ + Optional["Comment"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.Comment]], bool]], + ] + ], + AllOf[ + Union[ + Optional["Comment"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.Comment]], bool]], + ] + ], ] = DoNotCare() newline: Union[ NewlineMatchType, @@ -11891,12 +11906,6 @@ class TrailingWhitespace(BaseMatcherNode): ExceptHandlerMatchType = Union[ "ExceptHandler", MetadataMatchType, MatchIfTrue[Callable[[cst.ExceptHandler], bool]] ] -FinallyOrNoneMatchType = Union[ - "Finally", - None, - MetadataMatchType, - MatchIfTrue[Callable[[Union[cst.Finally, None]], bool]], -] @dataclass(frozen=True, eq=False, unsafe_hash=False) @@ -11988,16 +11997,44 @@ class Try(BaseCompoundStatement, BaseStatement, BaseMatcherNode): ], ] = DoNotCare() orelse: Union[ - ElseOrNoneMatchType, + Optional["Else"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.Else]], bool]], DoNotCareSentinel, - OneOf[ElseOrNoneMatchType], - AllOf[ElseOrNoneMatchType], + OneOf[ + Union[ + Optional["Else"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.Else]], bool]], + ] + ], + AllOf[ + Union[ + Optional["Else"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.Else]], bool]], + ] + ], ] = DoNotCare() finalbody: Union[ - FinallyOrNoneMatchType, + Optional["Finally"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.Finally]], bool]], DoNotCareSentinel, - OneOf[FinallyOrNoneMatchType], - AllOf[FinallyOrNoneMatchType], + OneOf[ + Union[ + Optional["Finally"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.Finally]], bool]], + ] + ], + AllOf[ + Union[ + Optional["Finally"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.Finally]], bool]], + ] + ], ] = DoNotCare() leading_lines: Union[ Sequence[ @@ -12547,10 +12584,24 @@ class While(BaseCompoundStatement, BaseStatement, BaseMatcherNode): AllOf[BaseSuiteMatchType], ] = DoNotCare() orelse: Union[ - ElseOrNoneMatchType, + Optional["Else"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.Else]], bool]], DoNotCareSentinel, - OneOf[ElseOrNoneMatchType], - AllOf[ElseOrNoneMatchType], + OneOf[ + Union[ + Optional["Else"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.Else]], bool]], + ] + ], + AllOf[ + Union[ + Optional["Else"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.Else]], bool]], + ] + ], ] = DoNotCare() leading_lines: Union[ Sequence[ @@ -12746,10 +12797,24 @@ class With(BaseCompoundStatement, BaseStatement, BaseMatcherNode): AllOf[BaseSuiteMatchType], ] = DoNotCare() asynchronous: Union[ - AsynchronousOrNoneMatchType, + Optional["Asynchronous"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.Asynchronous]], bool]], DoNotCareSentinel, - OneOf[AsynchronousOrNoneMatchType], - AllOf[AsynchronousOrNoneMatchType], + OneOf[ + Union[ + Optional["Asynchronous"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.Asynchronous]], bool]], + ] + ], + AllOf[ + Union[ + Optional["Asynchronous"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.Asynchronous]], bool]], + ] + ], ] = DoNotCare() leading_lines: Union[ Sequence[ @@ -12860,10 +12925,24 @@ class WithItem(BaseMatcherNode): AllOf[BaseExpressionMatchType], ] = DoNotCare() asname: Union[ - AsNameOrNoneMatchType, + Optional["AsName"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.AsName]], bool]], DoNotCareSentinel, - OneOf[AsNameOrNoneMatchType], - AllOf[AsNameOrNoneMatchType], + OneOf[ + Union[ + Optional["AsName"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.AsName]], bool]], + ] + ], + AllOf[ + Union[ + Optional["AsName"], + MetadataMatchType, + MatchIfTrue[Callable[[Optional[cst.AsName]], bool]], + ] + ], ] = DoNotCare() comma: Union[ CommaMatchType, DoNotCareSentinel, OneOf[CommaMatchType], AllOf[CommaMatchType]