Skip to content

Instantly share code, notes, and snippets.

@thatch
Created May 31, 2020 06:23
Show Gist options
  • Save thatch/7f402910a46fdbe6c4e17a9493ef91a5 to your computer and use it in GitHub Desktop.
Save thatch/7f402910a46fdbe6c4e17a9493ef91a5 to your computer and use it in GitHub Desktop.
diff --git a/libcst/matchers/__init__.py b/libcst/matchers/__init__.py
index df13b71..dc85e16 100644
--- a/libcst/matchers/__init__.py
+++ b/libcst/matchers/__init__.py
@@ -227,12 +227,6 @@ BaseExpressionMatchType = Union[
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]]
]
@@ -256,10 +250,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,
@@ -309,12 +317,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]]
]
@@ -329,10 +331,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,
@@ -436,10 +452,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]
@@ -2381,18 +2411,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)
@@ -2490,16 +2508,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,
@@ -4122,12 +4168,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]]
]
@@ -4145,10 +4185,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,
@@ -4186,14 +4240,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[
@@ -4203,16 +4249,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[
@@ -4655,14 +4729,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[
@@ -4684,16 +4750,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[
@@ -5087,17 +5181,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[
@@ -5107,335 +5190,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]
],
]
],
@@ -5453,10 +5248,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,
@@ -5510,12 +5319,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)
@@ -5615,17 +5418,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[
@@ -6790,10 +6621,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]
@@ -6813,18 +6658,6 @@ AttributeOrNameOrNoneMatchType = Union[
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)
@@ -7196,16 +7029,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,
@@ -7365,10 +7226,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[
@@ -9400,10 +9275,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,
@@ -9612,10 +9501,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,
@@ -9624,10 +9527,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]
@@ -9690,12 +9607,6 @@ ParamOrParamStarMatchType = Union[
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]]
]
@@ -9870,10 +9781,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[
@@ -10150,27 +10075,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,
@@ -10195,10 +10140,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,
@@ -11264,22 +11223,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]
@@ -11865,10 +11866,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,
@@ -11887,12 +11902,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)
@@ -11984,16 +11993,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[
@@ -12543,10 +12580,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[
@@ -12742,10 +12793,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[
@@ -12856,10 +12921,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]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment