diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1827f877d..4b5baae94 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,7 +23,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, windows-latest, macos-latest] - python-version: ['3.11', '3.12', '3.13', '3.14-dev'] + python-version: ['3.11', '3.12', '3.13', '3.14', '3.15'] qt-version: [5, 6] qt-binding: [pyqt] exclude: @@ -33,7 +33,9 @@ jobs: qt-version: 5 - python-version: '3.13' qt-version: 5 - - python-version: '3.14-dev' + - python-version: '3.14' + qt-version: 5 + - python-version: '3.15' qt-version: 5 fail-fast: false steps: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index fa2f5a2bd..7ea17b406 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -62,7 +62,7 @@ jobs: python -m pip install wheel cibuildwheel - name: Build wheels env: - CIBW_BUILD: "cp311-* cp312-* cp313-* cp314-*" + CIBW_BUILD: "cp311-* cp312-* cp313-* cp314-* cp315-*" CIBW_ARCHS_MACOS: x86_64 universal2 arm64 CIBW_ARCHS_WINDOWS: auto64 CIBW_TEST_REQUIRES: pytest diff --git a/enaml/compat.py b/enaml/compat.py index 6b957359f..e4cd57693 100644 --- a/enaml/compat.py +++ b/enaml/compat.py @@ -16,6 +16,8 @@ PY314 = sys.version_info >= (3, 14) +PY315 = sys.version_info >= (3, 15) + # Functions used to update the co_filename slot of a code object # Available in Python 3.5+ (tested up to 3.8) from _imp import _fix_co_filename diff --git a/enaml/core/code_generator.py b/enaml/core/code_generator.py index 351255dde..0aa181db2 100644 --- a/enaml/core/code_generator.py +++ b/enaml/core/code_generator.py @@ -11,7 +11,37 @@ import bytecode as bc from atom.api import Atom, Bool, Int, List, Str -from ..compat import PY312, PY313, PY314 +try: + from bytecode.instr import CommonConstant +except ImportError: # pragma: no cover + CommonConstant = None + +from ..compat import PY312, PY313, PY314, PY315 + + +def _common_const(value): + """Return the matching common-constant enum for the given singleton.""" + if CommonConstant is None: + return None + if value is None: + return CommonConstant.CONSTANT_NONE + if value is False: + return CommonConstant.CONSTANT_FALSE + if value is True: + return CommonConstant.CONSTANT_TRUE + if value == "": + return CommonConstant.CONSTANT_EMPTY_STR + if value == -1: + return CommonConstant.CONSTANT_MINUS_ONE + return None + + +def _load_const_instr(value): + """Build the appropriate constant-load instruction for the active Python.""" + common = _common_const(value) if PY315 else None + if common is not None: + return bc.Instr("LOAD_COMMON_CONSTANT", common) + return bc.Instr("LOAD_CONST", value) class _ReturnNoneIdentifier(ast.NodeVisitor): @@ -153,7 +183,7 @@ def load_fast(self, name): def load_const(self, const): """Load a const value onto the TOS.""" self.code_ops.append( # TOS - bc.Instr("LOAD_CONST", const), # TOS -> value + _load_const_instr(const), # TOS -> value ) def load_attr(self, name): @@ -218,6 +248,7 @@ def return_value(self): if ( not PY314 and PY312 + and not PY315 and self.code_ops and self.code_ops[-1].name == "LOAD_CONST" ): @@ -428,7 +459,7 @@ def try_squash_raise(self): bc.Instr("JUMP_FORWARD", end_label), # Under Python 3.11 only the actual exception is pushed exc_label, # TOS -> val - bc.Instr("LOAD_CONST", None), # TOS -> val -> None + _load_const_instr(None), # TOS -> val -> None bc.Instr("COPY", 2), # TOS -> val -> None -> val bc.Instr("STORE_ATTR", "__traceback__"), # TOS -> val bc.Instr("RAISE_VARARGS", 1), @@ -477,12 +508,10 @@ def for_loop(self, iter_var, fast_var=True): if PY312 else bc.Instr("JUMP_ABSOLUTE", start_label), jump_label, + bc.Instr("POP_BLOCK"), + end_label, ] ) - self.code_ops.extend( - bc.Instr("POP_BLOCK"), - end_label, - ) if PY312: self.code_ops.append(bc.Instr("END_FOR")) @@ -505,8 +534,17 @@ def insert_python_block(self, pydata, trim=True): (rc := (block[-1].name == "RETURN_CONST" and block[-1].arg is None)) or ( block[-1].name == "RETURN_VALUE" - and block[-2].name == "LOAD_CONST" - and block[-2].arg is None + and len(block) >= 2 + and isinstance(block[-2], bc.Instr) + and ( + ( + PY315 + and block[-2].name == "LOAD_COMMON_CONSTANT" + and block[-2].arg == CommonConstant.CONSTANT_NONE + ) + # The dual check on py315 is sub-optimal + or (block[-2].name == "LOAD_CONST" and block[-2].arg is None) + ) and block[-1].lineno not in _inspector.lines ) ): @@ -537,6 +575,7 @@ def insert_python_expr(self, pydata, trim=True): bc_code = bc.Bytecode.from_code(code) # Trim irrelevant RESUME opcode bc_code = bc_code[1:] + assert isinstance(bc_code[-1], bc.Instr) if bc_code[-1].name == "RETURN_CONST": bc_code[-1] = bc.Instr( "LOAD_CONST", bc_code[-1].arg, location=bc_code[-1].location diff --git a/enaml/core/compiler_common.py b/enaml/core/compiler_common.py index 626cc0ef5..e20f46db1 100644 --- a/enaml/core/compiler_common.py +++ b/enaml/core/compiler_common.py @@ -14,7 +14,7 @@ import bytecode as bc from atom.api import Str, Typed -from ..compat import PY312, PY313, PY314 +from ..compat import PY312, PY313, PY314, PY315 from .code_generator import CodeGenerator from .enaml_ast import ( AliasExpr, ASTVisitor, Binding, ChildDef, EnamlDef, StorageExpr, Template, @@ -913,8 +913,9 @@ def _insert_decl_function(cg, funcdef): # convert to a bytecode object and remove the leading and # trailing ops: STORE_NAME LOAD_CONST RETURN_VALUE - # Python 3.12 uses RETURN_CONST - outer_ops = bc.Bytecode.from_code(code)[0:(-2 if not PY314 and PY312 else -3)] + # Python 3.12 uses RETURN_CONST and Python 3.15 uses LOAD_COMMON_CONSTANT + # for None. + outer_ops = bc.Bytecode.from_code(code)[0:(-2 if (PY312 and not PY314 and not PY315) else -3)] # On 3.14 if the function has annotations it looks like # ... diff --git a/enaml/core/import_hooks.py b/enaml/core/import_hooks.py index 36ab55f55..17df4206d 100644 --- a/enaml/core/import_hooks.py +++ b/enaml/core/import_hooks.py @@ -10,7 +10,7 @@ import io import struct import sys -from abc import ABCMeta, abstractmethod, abstractclassmethod +from abc import ABCMeta, abstractmethod from collections import defaultdict, namedtuple from zipfile import ZipFile @@ -147,7 +147,8 @@ def exec_module(self, module, code=None): #-------------------------------------------------------------------------- # Abstract API #-------------------------------------------------------------------------- - @abstractclassmethod + @classmethod + @abstractmethod def locate_module(cls, fullname, path=None): """ Searches for the given Enaml module and returns an instance of AbstractEnamlImporter on success. diff --git a/enaml/core/parser/__init__.py b/enaml/core/parser/__init__.py index 87485e0a2..730f709b2 100644 --- a/enaml/core/parser/__init__.py +++ b/enaml/core/parser/__init__.py @@ -1,5 +1,5 @@ # ------------------------------------------------------------------------------ -# Copyright (c) 2013-2025, Nucleic Development Team. +# Copyright (c) 2013-2026, Nucleic Development Team. # # Distributed under the terms of the Modified BSD License. # @@ -8,7 +8,7 @@ import io import os import tokenize -from typing import Callable, Iterator, Optional, TextIO, Union +from typing import Callable, Iterator, Optional, TextIO from pegen.tokenizer import Tokenizer @@ -31,7 +31,7 @@ def _parse( else tokenize.generate_tokens(stream.readline) ) tokenizer = Tokenizer( - tok_stream, verbose=verbose, path=path if os.path.isfile(path) else None + tok_stream, verbose=verbose, path=path if os.path.isfile(path) else "" ) parser = EnamlParser( tokenizer, @@ -42,7 +42,6 @@ def _parse( return parser.parse("start") -# XXX document # filename is named so for backward compatibility def parse( source: str, @@ -58,12 +57,7 @@ def parse( This function is meant for in memory sources and one should prefer parse_file for sources existing in a file. - Parameters - ---------- - - """ return _parse( io.StringIO(source), filename, py_version, token_stream_factory, verbose ) - diff --git a/enaml/core/parser/base_enaml_parser.py b/enaml/core/parser/base_enaml_parser.py index 5c4a2be21..17664c4b8 100644 --- a/enaml/core/parser/base_enaml_parser.py +++ b/enaml/core/parser/base_enaml_parser.py @@ -136,15 +136,15 @@ def create_python_func_for_operator( self.raise_syntax_error_known_location(msg, item) func_node = ast.FunctionDef( - name = "f", - args = self.make_arguments(None, [], None, None, None), - decorator_list = [], - returns = None, - body = body, - lineno = body[0].lineno, - col_offset = body[0].col_offset, - end_lineno = body[-1].end_lineno, - end_col_offset = body[-1].end_col_offset, + name="f", + args=self.make_arguments(None, [], None, None, None), + decorator_list=[], + returns=None, + body=body, + lineno=body[0].lineno, + col_offset=body[0].col_offset, + end_lineno=body[-1].end_lineno, + end_col_offset=body[-1].end_col_offset, ) return self.create_python_module([func_node]) diff --git a/enaml/core/parser/base_python_parser.py b/enaml/core/parser/base_python_parser.py index 39cea4912..6cb791de3 100644 --- a/enaml/core/parser/base_python_parser.py +++ b/enaml/core/parser/base_python_parser.py @@ -1,4 +1,4 @@ -# -------------------------------------------------------------------------------------- +8# -------------------------------------------------------------------------------------- # Copyright (c) 2021-2025, Nucleic Development Team. # # Distributed under the terms of the Modified BSD License. @@ -22,9 +22,27 @@ Union, ) -from pegen.parser import Parser +from pegen.parser import ( + FSTRING_END, + FSTRING_START, + Parser, + memoize, +) from pegen.tokenizer import Tokenizer +try: + from token import ( + TSTRING_END, + TSTRING_MIDDLE, + TSTRING_START, + ) +except ImportError: + # On Python version on which t-string are not supported + # use unmatchable token values + TSTRING_END = -1001 + TSTRING_MIDDLE = -1002 + TSTRING_START = -1003 + # Singleton ast nodes, created once for efficiency Load = ast.Load() Store = ast.Store() @@ -60,6 +78,10 @@ ast.IfExp: "conditional expression", ast.NamedExpr: "named expression", } +if hasattr(ast, "TemplateStr"): + EXPR_NAME_MAPPING[ast.TemplateStr] = "t-string expression" +if hasattr(ast, "Interpolation"): + EXPR_NAME_MAPPING[ast.Interpolation] = "t-string expression" class Target(enum.Enum): @@ -85,6 +107,65 @@ def __init__( self.py_version = ( min(py_version, sys.version_info) if py_version else sys.version_info ) + self._fstring_raw_stack: List[bool] = [] + self._tstring_raw_stack: List[bool] = [] + + @memoize + def fstring_start(self) -> Optional[tokenize.TokenInfo]: + tok = self._tokenizer.peek() + if tok.type == FSTRING_START: + tok = self._tokenizer.getnext() + self._fstring_raw_stack.append("r" in tok.string.lower()) + return tok + return None + + @memoize + def tstring_start(self) -> Optional[tokenize.TokenInfo]: + tok = self._tokenizer.peek() + if tok.type == TSTRING_START: + tok = self._tokenizer.getnext() + self._tstring_raw_stack.append("r" in tok.string.lower()) + return tok + return None + + @memoize + def tstring_middle(self) -> Optional[tokenize.TokenInfo]: + tok = self._tokenizer.peek() + if tok.type == TSTRING_MIDDLE: + return self._tokenizer.getnext() + return None + + @memoize + def TSTRING_START(self) -> Optional[tokenize.TokenInfo]: + return self.tstring_start() + + @memoize + def TSTRING_MIDDLE(self) -> Optional[tokenize.TokenInfo]: + return self.tstring_middle() + + @memoize + def TSTRING_END(self) -> Optional[tokenize.TokenInfo]: + return self.tstring_end() + + @memoize + def fstring_end(self) -> Optional[tokenize.TokenInfo]: + tok = self._tokenizer.peek() + if tok.type == FSTRING_END: + tok = self._tokenizer.getnext() + if self._fstring_raw_stack: + self._fstring_raw_stack.pop() + return tok + return None + + @memoize + def tstring_end(self) -> Optional[tokenize.TokenInfo]: + tok = self._tokenizer.peek() + if tok.type == TSTRING_END: + tok = self._tokenizer.getnext() + if self._tstring_raw_stack: + self._tstring_raw_stack.pop() + return tok + return None def parse(self, rule: str, call_invalid_rules: bool = False) -> Optional[ast.AST]: self.call_invalid_rules = call_invalid_rules @@ -135,6 +216,269 @@ def raise_indentation_error(self, msg: str) -> None: ) raise IndentationError(msg, args) + def _advance_location(self, start: tuple[int, int], text: str) -> tuple[int, int]: + line, col = start + for ch in text: + if ch in ("\n", "\r"): + line += 1 + col = 0 + else: + col += 1 + return line, col + + def _source_offset(self, start: tuple[int, int], end: tuple[int, int]) -> int: + line, col = start + offset = 0 + while line < end[0]: + offset += len(self._tokenizer.get_lines([line])[0]) - col + line += 1 + col = 0 + offset += end[1] - col + return offset + + def _is_raw_fstring(self) -> bool: + return bool(self._fstring_raw_stack) and self._fstring_raw_stack[-1] + + def _is_raw_tstring(self) -> bool: + return bool(self._tstring_raw_stack) and self._tstring_raw_stack[-1] + + def _decode_fstring_literal(self, text: str, *, raw: Optional[bool] = None) -> str: + """Decode escape sequences in a literal f-string segment unless the f-string is raw.""" + if raw is None: + raw = self._is_raw_fstring() + if raw: + return text + return text.encode("utf-8").decode("unicode_escape") + + def _decode_tstring_literal(self, text: str, *, raw: Optional[bool] = None) -> str: + """Decode escape sequences in a literal t-string segment unless the t-string is raw.""" + if raw is None: + raw = self._is_raw_tstring() + if raw: + return text + return text.encode("utf-8").decode("unicode_escape") + + def fstring_debug_prefix( + self, + lbrace: tokenize.TokenInfo, + debug_expr: tokenize.TokenInfo, + rbrace: tokenize.TokenInfo, + ) -> str: + """Reconstruct the literal prefix emitted before a debug f-string value.""" + start = lbrace.end + stop = rbrace.start + lines = self._tokenizer.get_lines(list(range(start[0], stop[0] + 1))) + + if start[0] == stop[0]: + inside = lines[0][start[1] : stop[1]] + else: + pieces = [] + for i, line_no in enumerate(range(start[0], stop[0] + 1)): + line = lines[i] + if line_no == start[0]: + pieces.append(line[start[1] :]) + elif line_no == stop[0]: + pieces.append(line[: stop[1]]) + else: + pieces.append(line) + inside = "".join(pieces) + + eq_offset = self._source_offset(lbrace.end, debug_expr.start) + for idx in range(eq_offset + 1, len(inside)): + if inside[idx] in ("!", ":"): + prefix = inside[:idx] + return self._decode_fstring_literal(prefix, raw=self._is_raw_fstring()) + return self._decode_fstring_literal(inside, raw=self._is_raw_fstring()) + + def fstring_debug_value( + self, + value: ast.AST, + lbrace: tokenize.TokenInfo, + debug_expr: Optional[tokenize.TokenInfo], + conversion: Optional[int], + format_spec: Optional[ast.AST], + rbrace: tokenize.TokenInfo, + ) -> ast.AST: + """Build the AST for a debug f-string replacement field.""" + if debug_expr is None: + return ast.FormattedValue( + value=value, + conversion=(conversion if conversion is not None else -1), + format_spec=format_spec, + lineno=lbrace.start[0], + col_offset=lbrace.start[1], + end_lineno=rbrace.end[0], + end_col_offset=rbrace.end[1], + ) + + prefix = self.fstring_debug_prefix(lbrace, debug_expr, rbrace) + prefix_start = lbrace.end + prefix_end = self._advance_location(prefix_start, prefix) + formatted = ast.FormattedValue( + value=value, + conversion=( + conversion + if conversion is not None + else (ord("r") if format_spec is None else -1) + ), + format_spec=format_spec, + lineno=lbrace.start[0], + col_offset=lbrace.start[1], + end_lineno=rbrace.end[0], + end_col_offset=rbrace.end[1], + ) + return ast.JoinedStr( + values=[ + ast.Constant( + value=prefix, + lineno=prefix_start[0], + col_offset=prefix_start[1], + end_lineno=prefix_end[0], + end_col_offset=prefix_end[1], + ), + formatted, + ], + lineno=lbrace.start[0], + col_offset=lbrace.start[1], + end_lineno=rbrace.end[0], + end_col_offset=rbrace.end[1], + ) + + def tstring_debug_prefix( + self, + lbrace: tokenize.TokenInfo, + debug_expr: tokenize.TokenInfo, + rbrace: tokenize.TokenInfo, + ) -> str: + """Reconstruct the literal prefix emitted before a debug t-string value.""" + start = lbrace.end + stop = rbrace.start + lines = self._tokenizer.get_lines(list(range(start[0], stop[0] + 1))) + + if start[0] == stop[0]: + inside = lines[0][start[1] : stop[1]] + else: + pieces = [] + for i, line_no in enumerate(range(start[0], stop[0] + 1)): + line = lines[i] + if line_no == start[0]: + pieces.append(line[start[1] :]) + elif line_no == stop[0]: + pieces.append(line[: stop[1]]) + else: + pieces.append(line) + inside = "".join(pieces) + + eq_offset = self._source_offset(lbrace.end, debug_expr.start) + for idx in range(eq_offset + 1, len(inside)): + if inside[idx] in ("!", ":"): + prefix = inside[:idx] + return self._decode_tstring_literal(prefix, raw=self._is_raw_tstring()) + return self._decode_tstring_literal(inside, raw=self._is_raw_tstring()) + + def _tstring_expression_text( + self, + lbrace: tokenize.TokenInfo, + rbrace: tokenize.TokenInfo, + *, + debug_expr: Optional[tokenize.TokenInfo] = None, + ) -> str: + start = lbrace.end + stop = rbrace.start + lines = self._tokenizer.get_lines(list(range(start[0], stop[0] + 1))) + + if start[0] == stop[0]: + inside = lines[0][start[1] : stop[1]] + else: + pieces = [] + for i, line_no in enumerate(range(start[0], stop[0] + 1)): + line = lines[i] + if line_no == start[0]: + pieces.append(line[start[1] :]) + elif line_no == stop[0]: + pieces.append(line[: stop[1]]) + else: + pieces.append(line) + inside = "".join(pieces) + + if debug_expr is not None: + expr_end = self._source_offset(lbrace.end, debug_expr.start) + return inside[:expr_end].rstrip() + + depth = 0 + for i, ch in enumerate(inside): + if ch in "([{": + depth += 1 + elif ch in ")]}": + if depth: + depth -= 1 + elif depth == 0: + if ch in ("!", ":"): + if ch == "!" and i + 1 < len(inside) and inside[i + 1] == "=": + continue + return inside[:i].rstrip() + if ch == "=" and (i + 1 >= len(inside) or inside[i + 1] != "="): + return inside[:i].rstrip() + return inside.rstrip() + + def tstring_debug_value( + self, + value: ast.AST, + lbrace: tokenize.TokenInfo, + debug_expr: Optional[tokenize.TokenInfo], + conversion: Optional[int], + format_spec: Optional[ast.AST], + rbrace: tokenize.TokenInfo, + ) -> ast.AST: + """Build the AST for a debug t-string replacement field.""" + expr_text = self._tstring_expression_text(lbrace, rbrace, debug_expr=debug_expr) + + if debug_expr is None: + return ast.Interpolation( + value=value, + str=expr_text, + conversion=(conversion if conversion is not None else -1), + format_spec=format_spec, + lineno=lbrace.start[0], + col_offset=lbrace.start[1], + end_lineno=rbrace.end[0], + end_col_offset=rbrace.end[1], + ) + + prefix = self.tstring_debug_prefix(lbrace, debug_expr, rbrace) + prefix_start = lbrace.end + prefix_end = self._advance_location(prefix_start, prefix) + formatted = ast.Interpolation( + value=value, + str=expr_text, + conversion=( + conversion + if conversion is not None + else (ord("r") if format_spec is None else -1) + ), + format_spec=format_spec, + lineno=lbrace.start[0], + col_offset=lbrace.start[1], + end_lineno=rbrace.end[0], + end_col_offset=rbrace.end[1], + ) + return ast.TemplateStr( + values=[ + ast.Constant( + value=prefix, + lineno=prefix_start[0], + col_offset=prefix_start[1], + end_lineno=prefix_end[0], + end_col_offset=prefix_end[1], + ), + formatted, + ], + lineno=lbrace.start[0], + col_offset=lbrace.start[1], + end_lineno=rbrace.end[0], + end_col_offset=rbrace.end[1], + ) + def get_expr_name(self, node) -> str: """Get a descriptive name for an expression.""" # See https://github.com/python/cpython/blob/master/Parser/pegen.c#L161 @@ -220,8 +564,8 @@ def ensure_imaginary(self, number: tokenize.TokenInfo) -> complex: def check_fstring_conversion( self, mark: tokenize.TokenInfo, name: tokenize.TokenInfo - ) -> tokenize.TokenInfo: - if mark.lineno != name.lineno or mark.col_offset != name.col_offset: + ) -> int: + if mark.end != name.start: self.raise_syntax_error_known_range( "f-string: conversion type must come right after the exclamanation mark", mark, @@ -235,7 +579,7 @@ def check_fstring_conversion( name, ) - return name + return ord(s) def _concat_strings_in_constant(self, parts) -> ast.Constant: s = ast.literal_eval(parts[0].string) @@ -252,26 +596,54 @@ def _concat_strings_in_constant(self, parts) -> ast.Constant: args["kind"] = "u" return ast.Constant(**args) + def _flatten_joinedstr_values(self, values): + """Unwrap nested JoinedStr/TemplateStr nodes while preserving value order. + + Empty Constant nodes are filtered out. + + """ + flattened = [] + template_type = getattr(ast, "TemplateStr", None) + for value in values: + if isinstance(value, ast.JoinedStr) or ( + template_type is not None and isinstance(value, template_type) + ): + flattened.extend(self._flatten_joinedstr_values(value.values)) + elif isinstance(value, ast.Constant) and value.value == "": + continue + else: + flattened.append(value) + return flattened + def concatenate_strings(self, parts): - """Concatenate multiple tokens and ast.JoinedStr""" - # Get proper start and stop + """Concatenate multiple tokens and template-like literal AST nodes.""" start = end = None - if isinstance(parts[0], ast.JoinedStr): + template_type = getattr(ast, "TemplateStr", None) + if isinstance(parts[0], ast.JoinedStr) or ( + template_type is not None and isinstance(parts[0], template_type) + ): start = parts[0].lineno, parts[0].col_offset - if isinstance(parts[-1], ast.JoinedStr): + if isinstance(parts[-1], ast.JoinedStr) or ( + template_type is not None and isinstance(parts[-1], template_type) + ): end = parts[-1].end_lineno, parts[-1].end_col_offset - # Combine the different parts seen_joined = False + seen_template = False values = [] ss = [] for p in parts: - if isinstance(p, ast.JoinedStr): + if isinstance(p, ast.JoinedStr) or ( + template_type is not None and isinstance(p, template_type) + ): seen_joined = True + seen_template = seen_template or ( + template_type is not None and isinstance(p, template_type) + ) if ss: values.append(self._concat_strings_in_constant(ss)) ss.clear() - values.extend(p.values) + values.extend(self._flatten_joinedstr_values(p.values)) else: ss.append(p) @@ -293,14 +665,19 @@ def concatenate_strings(self, parts): if not seen_joined and len(values) == 1 and isinstance(values[0], ast.Constant): return values[0] - else: - return ast.JoinedStr( - values=consolidated, - lineno=start[0] if start else values[0].lineno, - col_offset=start[1] if start else values[0].col_offset, - end_lineno=end[0] if end else values[-1].end_lineno, - end_col_offset=end[1] if end else values[-1].end_col_offset, - ) + + cls = ( + ast.TemplateStr + if seen_template and hasattr(ast, "TemplateStr") + else ast.JoinedStr + ) + return cls( + values=consolidated, + lineno=start[0] if start else values[0].lineno, + col_offset=start[1] if start else values[0].col_offset, + end_lineno=end[0] if end else values[-1].end_lineno, + end_col_offset=end[1] if end else values[-1].end_col_offset, + ) def generate_ast_for_string(self, tokens): """Generate AST nodes for strings.""" diff --git a/enaml/core/parser/enaml.gram b/enaml/core/parser/enaml.gram index 4dddd9eba..0d07bf9a9 100644 --- a/enaml/core/parser/enaml.gram +++ b/enaml/core/parser/enaml.gram @@ -21,12 +21,13 @@ import ast import sys import itertools -from typing import Any, List, NoReturn, Optional, Tuple, TypeVar, Union +from typing import Any, List, NoReturn, Optional, Tuple, Union from enaml.core import enaml_ast -from pegen.parser import Parser, logger, memoize, memoize_left_rec +from pegen.parser import logger, memoize, memoize_left_rec from .base_enaml_parser import BaseEnamlParser as Parser +from .base_python_parser import Target # Singleton ast nodes, created once for efficiency Load = ast.Load() @@ -478,9 +479,9 @@ simple_stmts[list]: simple_stmt (memo): | assignment | &"type" type_alias + | &('import' | 'from' | "lazy") import_stmt | e=star_expressions { ast.Expr(value=e, LOCATIONS) } | &'return' return_stmt - | &('import' | 'from') import_stmt | &'raise' raise_stmt | 'pass' { ast.Pass(LOCATIONS) } | &'del' del_stmt @@ -597,16 +598,33 @@ import_stmt[ast.Import]: # Import statements # ----------------- -import_name[ast.Import]: 'import' a=dotted_as_names { ast.Import(names=a, LOCATIONS) } +import_name[ast.Import]: lazy="lazy"? 'import' a=dotted_as_names { + ast.Import(names=a, is_lazy=1 if lazy else 0, LOCATIONS) + if self.py_version >= (3, 15) else + self.check_version((3, 15), "Lazy imports are", ast.Import(names=a, LOCATIONS)) + if lazy else + ast.Import(names=a, LOCATIONS) + } # note below: the ('.' | '...') is necessary because '...' is tokenized as ELLIPSIS import_from[ast.ImportFrom]: - | 'from' a=('.' | '...')* b=dotted_name 'import' c=import_from_targets { + | invalid_import_from + | lazy="lazy"? 'from' a=('.' | '...')* b=dotted_name 'import' c=import_from_targets { + ast.ImportFrom(module=b, names=c, level=self.extract_import_level(a), is_lazy=1 if lazy else 0, LOCATIONS) + if self.py_version >= (3, 15) else + self.check_version((3, 15), "Lazy imports are", + ast.ImportFrom(module=b, names=c, level=self.extract_import_level(a), LOCATIONS)) + if lazy else ast.ImportFrom(module=b, names=c, level=self.extract_import_level(a), LOCATIONS) } - | 'from' a=('.' | '...')+ 'import' b=import_from_targets { + | lazy="lazy"? 'from' a=('.' | '...')+ 'import' b=import_from_targets { + ast.ImportFrom(names=b, level=self.extract_import_level(a), is_lazy=1 if lazy else 0, LOCATIONS) + if self.py_version >= (3, 15) else + self.check_version((3, 15), "Lazy imports are", + ast.ImportFrom(names=b, level=self.extract_import_level(a), LOCATIONS)) + if lazy else ast.ImportFrom(names=b, level=self.extract_import_level(a), LOCATIONS) - if sys.version_info >= (3, 9) else + if self.py_version >= (3, 9) else ast.ImportFrom(module=None, names=b, level=self.extract_import_level(a), LOCATIONS) } import_from_targets[List[ast.alias]]: @@ -821,7 +839,7 @@ param_maybe_default[Tuple[ast.arg, Any]]: | a=param c=default? tc=TYPE_COMMENT? &')' { (self.set_arg_type_comment(a, tc), c) } param: a=NAME b=annotation? { ast.arg(arg=a.string, annotation=b, LOCATIONS) } param_star_annotation: a=NAME b=star_annotation { - ast.arg(arg=a.string, annotations=b, LOCATIONS) + ast.arg(arg=a.string, annotation=b, LOCATIONS) } annotation: ':' a=expression { a } star_annotation: ':' a=star_expression { a } @@ -931,16 +949,25 @@ try_stmt[ast.Try]: except_block[ast.ExceptHandler]: | invalid_except_stmt_indent + | invalid_except_stmt | 'except' e=expression t=['as' z=NAME { z.string }] ':' b=block { ast.ExceptHandler(type=e, name=t, body=b, LOCATIONS) } | 'except' ':' b=block { ast.ExceptHandler(type=None, name=None, body=b, LOCATIONS) } - | invalid_except_stmt + | 'except' e=expressions ':' b=block { + ast.ExceptHandler(type=e, name=None, body=b, LOCATIONS) + if self.py_version >= (3, 14) + else None } except_star_block[ast.ExceptHandler]: | invalid_except_star_stmt_indent + | invalid_except_stmt | 'except' '*' e=expression t=['as' z=NAME { z.string }] ':' b=block { ast.ExceptHandler(type=e, name=t, body=b, LOCATIONS) } - | invalid_except_stmt + | 'except' '*' e=expressions ':' b=block { + ast.ExceptHandler(type=e, name=None, body=b, LOCATIONS) + if self.py_version >= (3, 14) + else None + } finally_block[list]: | invalid_finally_stmt | 'finally' &&':' a=block { a } @@ -987,7 +1014,7 @@ pattern: as_pattern["ast.MatchAs"]: | pattern=or_pattern 'as' target=pattern_capture_target { - ast.MatchAs(pattern=pattern, name=target, LOCATIONS) + self.raise_syntax_error_known_location("cannot use '_' as a target", pattern) if isinstance(pattern, ast.MatchAs) and pattern.pattern is None and pattern.name is None else ast.MatchAs(pattern=pattern, name=target, LOCATIONS) } | invalid_as_pattern @@ -1067,7 +1094,7 @@ pattern_capture_target[str]: | !"_" name=NAME !('.' | '(' | '=') { name.string } wildcard_pattern["ast.MatchAs"]: - | "_" { ast.MatchAs(pattern=None, target=None, LOCATIONS) } + | "_" { ast.MatchAs(pattern=None, name=None, LOCATIONS) } value_pattern["ast.MatchValue"]: | attr=attr !('.' | '(' | '=') { ast.MatchValue(value=attr, LOCATIONS) } @@ -1472,7 +1499,7 @@ atom: if sys.version_info >= (3, 9) else ast.Constant(value=None, kind=None, LOCATIONS) } - | &(STRING|FSTRING_START) strings + | &(STRING|FSTRING_START|TSTRING_START) strings | a=NUMBER { ast.Constant(value=ast.literal_eval(a.string), LOCATIONS) if sys.version_info >= (3, 9) else @@ -1564,19 +1591,10 @@ lambda_param[ast.arg]: a=NAME { fstring_mid: | fstring_replacement_field - | t=FSTRING_MIDDLE { ast.Constant(value=t.string, LOCATIONS) } + | t=FSTRING_MIDDLE { ast.Constant(value=self._decode_fstring_literal(t.string, raw=self._is_raw_fstring()), LOCATIONS) } fstring_replacement_field: - | '{' a=(yield_expr | star_expressions) debug_expr="="? conversion=[fstring_conversion] format=[fstring_full_format_spec] rbrace='}' { - ast.FormattedValue( - value=a, - conversion=( - conversion.decode()[0] - if conversion else - (b'r'[0] if debug_expr else -1) - ), - format_spec=format, - LOCATIONS - ) + | lbrace='{' a=annotated_rhs debug_expr='='? conversion=[fstring_conversion] format=[fstring_full_format_spec] rbrace='}' { + self.fstring_debug_value(a, lbrace, debug_expr, conversion, format, rbrace) } | invalid_replacement_field fstring_conversion[int]: @@ -1584,21 +1602,49 @@ fstring_conversion[int]: fstring_full_format_spec: | ':' spec=fstring_format_spec* { ast.JoinedStr( - values=spec if spec and (len(spec) > 1 or spec[0].value) else [], + values=self._flatten_joinedstr_values(spec), LOCATIONS, ) } fstring_format_spec: - | t=FSTRING_MIDDLE { ast.Constant(value=t.string, LOCATIONS) } + | t=FSTRING_MIDDLE { ast.Constant(value=self._decode_fstring_literal(t.string, raw=self._is_raw_fstring()), LOCATIONS) } | fstring_replacement_field fstring: | a=FSTRING_START b=fstring_mid* c=FSTRING_END { - ast.JoinedStr(values=b, LOCATIONS) + ast.JoinedStr(values=self._flatten_joinedstr_values(b), LOCATIONS) } -strings (memo): a=(fstring|STRING)+ { - self.concatenate_strings(a) if sys.version_info >= (3, 12) else self.generate_ast_for_string(a) - } +tstring_mid: + | tstring_replacement_field + | t=TSTRING_MIDDLE { ast.Constant(value=self._decode_tstring_literal(t.string, raw=self._is_raw_tstring()), LOCATIONS) } +tstring_replacement_field: + | lbrace='{' a=annotated_rhs debug_expr='='? conversion=[fstring_conversion] format=[tstring_full_format_spec] rbrace='}' { + self.tstring_debug_value(a, lbrace, debug_expr, conversion, format, rbrace) + } + | invalid_tstring_replacement_field +tstring_full_format_spec: + | ':' spec=tstring_format_spec* { + ast.JoinedStr( + values=self._flatten_joinedstr_values(spec), + LOCATIONS, + ) + } +tstring_format_spec: + | t=TSTRING_MIDDLE { ast.Constant(value=self._decode_tstring_literal(t.string, raw=self._is_raw_tstring()), LOCATIONS) } + | fstring_replacement_field +tstring: + | a=TSTRING_START b=tstring_mid* c=TSTRING_END { + ast.TemplateStr(values=self._flatten_joinedstr_values(b), LOCATIONS) + } + +strings (memo): + | invalid_string_tstring_concat + | a=(fstring|STRING)+ { + self.concatenate_strings(a) if sys.version_info >= (3, 12) else self.generate_ast_for_string(a) + } + | a=tstring+ { + self.concatenate_strings(a) if sys.version_info >= (3, 12) else self.generate_ast_for_string(a) + } list[ast.List]: | '[' a=[star_named_expressions] ']' { ast.List(elts=a or [], ctx=Load, LOCATIONS) } @@ -1805,10 +1851,10 @@ func_type_comment: # From here on, there are rules for invalid syntax with specialised error messages invalid_arguments[NoReturn]: - | a=args ',' '*' { - self.raise_syntax_error_known_location( + | ((','.(starred_expression | ( assignment_expression | expression !':=') !'=')+ ',' kwargs) | kwargs) a=',' ','.(starred_expression !'=')+ { + self.raise_syntax_error_starting_from( "iterable argument unpacking follows keyword argument unpacking", - a[1][-1] if a[1] else a[0][-1], + a, ) } | a=expression b=for_if_clauses ',' [args | expression for_if_clauses] { @@ -2099,6 +2145,12 @@ invalid_import: "Did you mean to use 'from ... import ...' instead?", a ) } +invalid_import_from: + | 'from' ('.' | '...')* dotted_name a="lazy" 'import' import_from_targets { + self.raise_syntax_error_known_location( + "use 'lazy from ... ' instead of 'from ... lazy import'", a + ) + } invalid_import_from_targets[NoReturn]: | import_from_as_names ',' NEWLINE { self.raise_syntax_error("trailing comma not allowed without surrounding parentheses") @@ -2140,7 +2192,27 @@ invalid_try_stmt[NoReturn]: } invalid_except_stmt[None]: | 'except' '*'? a=expression ',' expressions ['as' NAME ] ':' { - self.raise_syntax_error_starting_from("multiple exception types must be parenthesized", a) + self.raise_syntax_error_known_range( + "multiple exception types must be parenthesized when using 'as'" + if self.py_version >= (3, 14) + else "multiple exception types must be parenthesized", + a, + a, + ) + } + | 'except' '*'? a=expression ',' b=expressions ':' { + self.raise_syntax_error_known_range( + "multiple exception types must be parenthesized", + a, + b, + ) + if self.py_version < (3, 14) + else None + } + | 'except' '*'? expression a=',' { + self.raise_syntax_error_known_location("invalid syntax", a) + if self.py_version < (3, 14) + else None } | a='except' '*'? expression ['as' NAME ] NEWLINE { self.raise_syntax_error("expected ':'") } | a='except' '*'? NEWLINE { self.raise_syntax_error("expected ':'") } @@ -2198,8 +2270,11 @@ invalid_as_pattern[NoReturn]: | or_pattern 'as' a="_" { self.raise_syntax_error_known_location("cannot use '_' as a target", a) } - | or_pattern 'as' !NAME a=expression { - self.raise_syntax_error_known_location("invalid pattern target", a) + | or_pattern 'as' a=expression { + self.raise_syntax_error_known_location( + f"cannot use {self.get_expr_name(a)} as pattern target", a) + if self.py_version >= (3, 14) + else self.raise_syntax_error_known_location("invalid pattern target", a) } invalid_class_pattern[NoReturn]: | name_or_attr '(' a=invalid_class_argument_pattern { @@ -2319,3 +2394,41 @@ invalid_replacement_field: invalid_conversion_character: | '!' &(':' | '}') { self.raise_syntax_error_on_next_token("f-string: missing conversion character") } | '!' !NAME { self.raise_syntax_error_on_next_token("f-string: invalid conversion character") } + +invalid_tstring_replacement_field: + | '{' a='=' { self.raise_syntax_error_known_location("t-string: valid expression required before '='", a) } + | '{' a='!' { self.raise_syntax_error_known_location("t-string: valid expression required before '!'", a) } + | '{' a=':' { self.raise_syntax_error_known_location("t-string: valid expression required before ':'", a) } + | '{' a='}' { self.raise_syntax_error_known_location("t-string: valid expression required before '}'", a) } + | '{' !(yield_expr | star_expressions) { + self.raise_syntax_error_on_next_token( + "t-string: expecting a valid expression after '{'" + ) + } + | '{' (yield_expr | star_expressions) !('=' | '!' | ':' | '}') { + self.raise_syntax_error_on_next_token("t-string: expecting '=', or '!', or ':', or '}'") } + | '{' (yield_expr | star_expressions) '=' !('!' | ':' | '}') { + self.raise_syntax_error_on_next_token("t-string: expecting '!', or ':', or '}'") + } + | '{' (yield_expr | star_expressions) '='? invalid_tstring_conversion_character + | '{' (yield_expr | star_expressions) '='? ['!' NAME] !(':' | '}') { + self.raise_syntax_error_on_next_token("t-string: expecting ':' or '}'") + } + | '{' (yield_expr | star_expressions) '='? ['!' NAME] ':' tstring_format_spec* !'}' { + self.raise_syntax_error_on_next_token("t-string: expecting '}', or format specs") + } + | '{' (yield_expr | star_expressions) '='? ['!' NAME] !'}' { + self.raise_syntax_error_on_next_token("t-string: expecting '}'") + } + +invalid_tstring_conversion_character: + | '!' &(':' | '}') { self.raise_syntax_error_on_next_token("t-string: missing conversion character") } + | '!' !NAME { self.raise_syntax_error_on_next_token("t-string: invalid conversion character") } + +invalid_string_tstring_concat: + | a=(fstring|STRING)+ b=tstring { + self.raise_syntax_error_known_range("cannot mix t-string literals with string or bytes literals", a[-1], b) + } + | a=tstring+ b=(fstring|STRING) { + self.raise_syntax_error_known_range("cannot mix t-string literals with string or bytes literals", a[-1], b) + } diff --git a/enaml/core/parser/enaml_parser.py b/enaml/core/parser/enaml_parser.py index 7e1bb20da..dd6e67a92 100644 --- a/enaml/core/parser/enaml_parser.py +++ b/enaml/core/parser/enaml_parser.py @@ -1,170 +1,152 @@ - -#--------------------------------------------------------------------------------------- +# --------------------------------------------------------------------------------------- # Copyright (c) 2021-2025, Nucleic Development Team. # # Distributed under the terms of the Modified BSD License. # # The full license is in the file LICENSE, distributed with this software. -#--------------------------------------------------------------------------------------- +# --------------------------------------------------------------------------------------- # NOTE This file was generated using enaml/core/parser/generate_enaml_parser.py # DO NOT EDIT DIRECTLY import ast import sys import itertools -from typing import Any, List, NoReturn, Optional, Tuple, TypeVar, Union +from typing import Any, List, NoReturn, Optional, Tuple, Union from enaml.core import enaml_ast -from pegen.parser import Parser, logger, memoize, memoize_left_rec +from pegen.parser import logger, memoize, memoize_left_rec from .base_enaml_parser import BaseEnamlParser as Parser +from .base_python_parser import Target # Singleton ast nodes, created once for efficiency Load = ast.Load() Store = ast.Store() Del = ast.Del() + + # Keywords and soft keywords are listed at the end of the parser definition. class EnamlParser(Parser): - @memoize - def start(self) -> Optional[enaml_ast . Module]: + def start(self) -> Optional[enaml_ast.Module]: # start: enaml_item* NEWLINE? $ mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start if ( (a := self._loop0_1(),) - and - (self.expect('NEWLINE'),) - and - (self.expect('ENDMARKER')) + and (self.expect("NEWLINE"),) + and (self.expect("ENDMARKER")) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return self . create_enaml_module ( itertools . chain . from_iterable ( a ) , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return self.create_enaml_module( + itertools.chain.from_iterable(a), + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - return None; + return None @memoize - def enaml_item(self) -> Optional[List [ast . AST]]: + def enaml_item(self) -> Optional[List[ast.AST]]: # enaml_item: statement | enamldef | template mark = self._mark() - if ( - (statement := self.statement()) - ): - return statement; + if statement := self.statement(): + return statement self._reset(mark) - if ( - (a := self.enamldef()) - ): - return [a]; + if a := self.enamldef(): + return [a] self._reset(mark) - if ( - (a := self.template()) - ): - return [a]; + if a := self.template(): + return [a] self._reset(mark) - return None; + return None @memoize - def enamldef(self) -> Optional[enaml_ast . EnamlDef]: + def enamldef(self) -> Optional[enaml_ast.EnamlDef]: # enamldef: pragma* "enamldef" NAME '(' NAME ')' [':' NAME] &&':' enamldef_body mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start if ( (p := self._loop0_2(),) - and - (self.expect("enamldef")) - and - (a := self.name()) - and - (self.expect('(')) - and - (b := self.name()) - and - (self.expect(')')) - and - (c := self._tmp_3(),) - and - (self.expect_forced(self.expect(':'), "':'")) - and - (d := self.enamldef_body()) - ): - tok = self._tokenizer.get_last_non_whitespace_token() - end_lineno, end_col_offset = tok.end - return self . validate_enamldef ( enaml_ast . EnamlDef ( typename = a . string , base = b . string , identifier = c . string if c else '' , docstring = d [0] , body = [x for x in d [1] if not isinstance ( x , ast . Pass )] , pragmas = p , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ) ); - self._reset(mark) - return None; - - @memoize - def enamldef_body(self) -> Optional[Tuple [str , list]]: + and (self.expect("enamldef")) + and (a := self.name()) + and (self.expect("(")) + and (b := self.name()) + and (self.expect(")")) + and (c := self._tmp_3(),) + and (self.expect_forced(self.expect(":"), "':'")) + and (d := self.enamldef_body()) + ): + tok = self._tokenizer.get_last_non_whitespace_token() + end_lineno, end_col_offset = tok.end + return self.validate_enamldef( + enaml_ast.EnamlDef( + typename=a.string, + base=b.string, + identifier=c.string if c else "", + docstring=d[0], + body=[x for x in d[1] if not isinstance(x, ast.Pass)], + pragmas=p, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) + ) + self._reset(mark) + return None + + @memoize + def enamldef_body(self) -> Optional[Tuple[str, list]]: # enamldef_body: NEWLINE INDENT STRING NEWLINE enamldef_item+ DEDENT | NEWLINE INDENT enamldef_item+ DEDENT | enamldef_simple_item | invalid_block mark = self._mark() if ( - (self.expect('NEWLINE')) - and - (self.expect('INDENT')) - and - (a := self.string()) - and - (self.expect('NEWLINE')) - and - (b := self._loop1_4()) - and - (self.expect('DEDENT')) + (self.expect("NEWLINE")) + and (self.expect("INDENT")) + and (a := self.string()) + and (self.expect("NEWLINE")) + and (b := self._loop1_4()) + and (self.expect("DEDENT")) ): - return a . string , b; + return a.string, b self._reset(mark) if ( - (self.expect('NEWLINE')) - and - (self.expect('INDENT')) - and - (b := self._loop1_5()) - and - (self.expect('DEDENT')) + (self.expect("NEWLINE")) + and (self.expect("INDENT")) + and (b := self._loop1_5()) + and (self.expect("DEDENT")) ): - return "" , b; + return "", b self._reset(mark) - if ( - (a := self.enamldef_simple_item()) - ): - return "" , [a]; + if a := self.enamldef_simple_item(): + return "", [a] self._reset(mark) - if ( - self.call_invalid_rules - and - (self.invalid_block()) - ): - return None # pragma: no cover; + if self.call_invalid_rules and (self.invalid_block()): + return None # pragma: no cover self._reset(mark) - return None; + return None @memoize def enamldef_item(self) -> Optional[Any]: # enamldef_item: enamldef_simple_item | decl_funcdef | child_def | template_inst mark = self._mark() - if ( - (enamldef_simple_item := self.enamldef_simple_item()) - ): - return enamldef_simple_item; + if enamldef_simple_item := self.enamldef_simple_item(): + return enamldef_simple_item self._reset(mark) - if ( - (decl_funcdef := self.decl_funcdef()) - ): - return decl_funcdef; + if decl_funcdef := self.decl_funcdef(): + return decl_funcdef self._reset(mark) - if ( - (child_def := self.child_def()) - ): - return child_def; + if child_def := self.child_def(): + return child_def self._reset(mark) - if ( - (template_inst := self.template_inst()) - ): - return template_inst; + if template_inst := self.template_inst(): + return template_inst self._reset(mark) - return None; + return None @memoize def enamldef_simple_item(self) -> Optional[Any]: @@ -172,272 +154,266 @@ def enamldef_simple_item(self) -> Optional[Any]: mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - (binding := self.binding()) - ): - return binding; + if binding := self.binding(): + return binding self._reset(mark) - if ( - (ex_binding := self.ex_binding()) - ): - return ex_binding; + if ex_binding := self.ex_binding(): + return ex_binding self._reset(mark) - if ( - (storage_alias_const_expr := self.storage_alias_const_expr()) - ): - return storage_alias_const_expr; + if storage_alias_const_expr := self.storage_alias_const_expr(): + return storage_alias_const_expr self._reset(mark) - if ( - (self.expect('pass')) - and - (self.expect('NEWLINE')) - ): + if (self.expect("pass")) and (self.expect("NEWLINE")): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . Pass ( lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.Pass( + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - return None; + return None @memoize - def pragmas(self) -> Optional[List [enaml_ast . Pragma]]: + def pragmas(self) -> Optional[List[enaml_ast.Pragma]]: # pragmas: pragma+ mark = self._mark() - if ( - (_loop1_6 := self._loop1_6()) - ): - return _loop1_6; + if _loop1_6 := self._loop1_6(): + return _loop1_6 self._reset(mark) - return None; + return None @memoize - def pragma(self) -> Optional[enaml_ast . Pragma]: + def pragma(self) -> Optional[enaml_ast.Pragma]: # pragma: "pragma" NAME ['(' ','.pragma_arg+ ')'] NEWLINE mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start if ( (self.expect("pragma")) - and - (a := self.name()) - and - (args := self._tmp_7(),) - and - (self.expect('NEWLINE')) + and (a := self.name()) + and (args := self._tmp_7(),) + and (self.expect("NEWLINE")) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return enaml_ast . Pragma ( command = a . string , arguments = args or [] , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return enaml_ast.Pragma( + command=a.string, + arguments=args or [], + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - return None; + return None @memoize - def pragma_arg(self) -> Optional[enaml_ast . PragmaArg]: + def pragma_arg(self) -> Optional[enaml_ast.PragmaArg]: # pragma_arg: NAME | NUMBER | STRING mark = self._mark() - if ( - (a := self.name()) - ): - return enaml_ast . PragmaArg ( kind = "token" , value = a . string ); + if a := self.name(): + return enaml_ast.PragmaArg(kind="token", value=a.string) self._reset(mark) - if ( - (a := self.number()) - ): - return enaml_ast . PragmaArg ( kind = "number" , value = a ); + if a := self.number(): + return enaml_ast.PragmaArg(kind="number", value=a) self._reset(mark) - if ( - (a := self.string()) - ): - return enaml_ast . PragmaArg ( kind = "string" , value = a ); + if a := self.string(): + return enaml_ast.PragmaArg(kind="string", value=a) self._reset(mark) - return None; + return None @memoize def storage_alias_const_expr(self) -> Optional[Any]: # storage_alias_const_expr: alias_expr | const_expr | storage_expr mark = self._mark() - if ( - (alias_expr := self.alias_expr()) - ): - return alias_expr; + if alias_expr := self.alias_expr(): + return alias_expr self._reset(mark) - if ( - (const_expr := self.const_expr()) - ): - return const_expr; + if const_expr := self.const_expr(): + return const_expr self._reset(mark) - if ( - (storage_expr := self.storage_expr()) - ): - return storage_expr; + if storage_expr := self.storage_expr(): + return storage_expr self._reset(mark) - return None; + return None @memoize - def alias_expr(self) -> Optional[enaml_ast . AliasExpr]: + def alias_expr(self) -> Optional[enaml_ast.AliasExpr]: # alias_expr: "alias" NAME [':' '.'.NAME+] NEWLINE mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start if ( (self.expect("alias")) - and - (a := self.name()) - and - (b := self._tmp_8(),) - and - (self.expect('NEWLINE')) + and (a := self.name()) + and (b := self._tmp_8(),) + and (self.expect("NEWLINE")) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return enaml_ast . AliasExpr ( name = a . string , target = b [0] . string if b else a . string , chain = tuple ( p . string for p in b [1 :] ) if b else ( ) , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return enaml_ast.AliasExpr( + name=a.string, + target=b[0].string if b else a.string, + chain=tuple(p.string for p in b[1:]) if b else (), + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - return None; + return None @memoize - def const_expr(self) -> Optional[enaml_ast . ConstExpr]: + def const_expr(self) -> Optional[enaml_ast.ConstExpr]: # const_expr: "const" NAME [':' dec_primary] &'=' operator_expr mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start if ( (self.expect("const")) - and - (a := self.name()) - and - (b := self._tmp_9(),) - and - (self.positive_lookahead(self.expect, '=')) - and - (d := self.operator_expr()) + and (a := self.name()) + and (b := self._tmp_9(),) + and (self.positive_lookahead(self.expect, "=")) + and (d := self.operator_expr()) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return enaml_ast . ConstExpr ( name = a . string , typename = b , expr = d . value , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return enaml_ast.ConstExpr( + name=a.string, + typename=b, + expr=d.value, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - return None; + return None @memoize - def storage_expr(self) -> Optional[enaml_ast . StorageExpr]: + def storage_expr(self) -> Optional[enaml_ast.StorageExpr]: # storage_expr: ("attr" | "event") NAME [':' dec_primary] NEWLINE | ("attr" | "event") NAME [':' dec_primary] operator_expr mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start if ( (a := self._tmp_10()) - and - (b := self.name()) - and - (c := self._tmp_11(),) - and - (self.expect('NEWLINE')) + and (b := self.name()) + and (c := self._tmp_11(),) + and (self.expect("NEWLINE")) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return enaml_ast . StorageExpr ( name = b . string , kind = a . string , typename = c , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return enaml_ast.StorageExpr( + name=b.string, + kind=a.string, + typename=c, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) if ( (a := self._tmp_12()) - and - (b := self.name()) - and - (c := self._tmp_13(),) - and - (e := self.operator_expr()) + and (b := self.name()) + and (c := self._tmp_13(),) + and (e := self.operator_expr()) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return enaml_ast . StorageExpr ( name = b . string , kind = a . string , typename = c , expr = e , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return enaml_ast.StorageExpr( + name=b.string, + kind=a.string, + typename=c, + expr=e, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - return None; + return None @memoize - def child_def(self) -> Optional[enaml_ast . ChildDef]: + def child_def(self) -> Optional[enaml_ast.ChildDef]: # child_def: NAME ':' child_def_body | NAME ':' NAME ':' child_def_body mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - (a := self.name()) - and - (self.expect(':')) - and - (c := self.child_def_body()) - ): + if (a := self.name()) and (self.expect(":")) and (c := self.child_def_body()): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return enaml_ast . ChildDef ( typename = a . string , identifier = "" , body = [x for x in c if not isinstance ( x , ast . Pass )] , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return enaml_ast.ChildDef( + typename=a.string, + identifier="", + body=[x for x in c if not isinstance(x, ast.Pass)], + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) if ( (a := self.name()) - and - (self.expect(':')) - and - (b := self.name()) - and - (self.expect(':')) - and - (c := self.child_def_body()) + and (self.expect(":")) + and (b := self.name()) + and (self.expect(":")) + and (c := self.child_def_body()) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return enaml_ast . ChildDef ( typename = a . string , identifier = b . string , body = [x for x in c if not isinstance ( x , ast . Pass )] , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return enaml_ast.ChildDef( + typename=a.string, + identifier=b.string, + body=[x for x in c if not isinstance(x, ast.Pass)], + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - return None; + return None @memoize def child_def_body(self) -> Optional[list]: # child_def_body: NEWLINE INDENT child_def_item+ DEDENT | child_def_simple_item | invalid_block mark = self._mark() if ( - (self.expect('NEWLINE')) - and - (self.expect('INDENT')) - and - (a := self._loop1_14()) - and - (self.expect('DEDENT')) + (self.expect("NEWLINE")) + and (self.expect("INDENT")) + and (a := self._loop1_14()) + and (self.expect("DEDENT")) ): - return a; + return a self._reset(mark) - if ( - (a := self.child_def_simple_item()) - ): - return [a]; + if a := self.child_def_simple_item(): + return [a] self._reset(mark) - if ( - self.call_invalid_rules - and - (self.invalid_block()) - ): - return None # pragma: no cover; + if self.call_invalid_rules and (self.invalid_block()): + return None # pragma: no cover self._reset(mark) - return None; + return None @memoize def child_def_item(self) -> Optional[Any]: # child_def_item: child_def_simple_item | decl_funcdef | child_def | template_inst mark = self._mark() - if ( - (child_def_simple_item := self.child_def_simple_item()) - ): - return child_def_simple_item; + if child_def_simple_item := self.child_def_simple_item(): + return child_def_simple_item self._reset(mark) - if ( - (decl_funcdef := self.decl_funcdef()) - ): - return decl_funcdef; + if decl_funcdef := self.decl_funcdef(): + return decl_funcdef self._reset(mark) - if ( - (child_def := self.child_def()) - ): - return child_def; + if child_def := self.child_def(): + return child_def self._reset(mark) - if ( - (template_inst := self.template_inst()) - ): - return template_inst; + if template_inst := self.template_inst(): + return template_inst self._reset(mark) - return None; + return None @memoize def child_def_simple_item(self) -> Optional[Any]: @@ -445,70 +421,69 @@ def child_def_simple_item(self) -> Optional[Any]: mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - (binding := self.binding()) - ): - return binding; + if binding := self.binding(): + return binding self._reset(mark) - if ( - (ex_binding := self.ex_binding()) - ): - return ex_binding; + if ex_binding := self.ex_binding(): + return ex_binding self._reset(mark) - if ( - (alias_expr := self.alias_expr()) - ): - return alias_expr; + if alias_expr := self.alias_expr(): + return alias_expr self._reset(mark) - if ( - (storage_expr := self.storage_expr()) - ): - return storage_expr; + if storage_expr := self.storage_expr(): + return storage_expr self._reset(mark) - if ( - (self.expect('pass')) - and - (self.expect('NEWLINE')) - ): + if (self.expect("pass")) and (self.expect("NEWLINE")): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . Pass ( lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.Pass( + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - return None; + return None @memoize - def binding(self) -> Optional[enaml_ast . Binding]: + def binding(self) -> Optional[enaml_ast.Binding]: # binding: NAME operator_expr mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - (a := self.name()) - and - (b := self.operator_expr()) - ): + if (a := self.name()) and (b := self.operator_expr()): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return enaml_ast . Binding ( name = a . string , expr = b , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return enaml_ast.Binding( + name=a.string, + expr=b, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - return None; + return None @memoize - def ex_binding(self) -> Optional[enaml_ast . ExBinding]: + def ex_binding(self) -> Optional[enaml_ast.ExBinding]: # ex_binding: '.'.NAME+ operator_expr mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - (a := self._gather_15()) - and - (b := self.operator_expr()) - ): + if (a := self._gather_15()) and (b := self.operator_expr()): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return enaml_ast . ExBinding ( chain = tuple ( p . string for p in a ) , expr = b , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return enaml_ast.ExBinding( + chain=tuple(p.string for p in a), + expr=b, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - return None; + return None @memoize def operator_expr(self) -> Optional[Any]: @@ -516,64 +491,94 @@ def operator_expr(self) -> Optional[Any]: mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - (a := self._tmp_17()) - and - (b := self.py_expr()) - and - (self.expect('NEWLINE')) - ): - tok = self._tokenizer.get_last_non_whitespace_token() - end_lineno, end_col_offset = tok.end - return enaml_ast . OperatorExpr ( operator = a . string , value = b , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); - self._reset(mark) - if ( - (a := self._tmp_18()) - and - (b := self.py_expr()) - and - (self.expect('NEWLINE')) - ): - tok = self._tokenizer.get_last_non_whitespace_token() - end_lineno, end_col_offset = tok.end - return enaml_ast . OperatorExpr ( operator = a . string , value = b , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ) if isinstance ( b . ast . body , self . INVERTABLE ) else self . raise_syntax_error_known_location ( "can't assign to expression of this form" , b ); - self._reset(mark) - if ( - (a := self.expect(':')) - and - (b := self.expect(':')) - and - (c := self.block()) - ): - tok = self._tokenizer.get_last_non_whitespace_token() - end_lineno, end_col_offset = tok.end - return enaml_ast . OperatorExpr ( operator = '::' , value = self . create_python_func_for_operator ( c , self . NOTIFICATION_DISALLOWED , '%s not allowed in a notification block' ) , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ) if a . end == b . start else self . raise_syntax_error_known_range ( "invalid syntax. Did you mean '::' ?" , a , b ); - self._reset(mark) - if ( - (self.expect('<<')) - and - (a := self.block()) - ): - tok = self._tokenizer.get_last_non_whitespace_token() - end_lineno, end_col_offset = tok.end - return enaml_ast . OperatorExpr ( operator = '<<' , value = self . create_python_func_for_operator ( a , self . SUBSCRIPTION_DISALLOWED , '%s not allowed in a subscription block' ) , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); - self._reset(mark) - return None; - - @memoize - def py_expr(self) -> Optional[enaml_ast . PythonExpression]: + if (a := self._tmp_17()) and (b := self.py_expr()) and (self.expect("NEWLINE")): + tok = self._tokenizer.get_last_non_whitespace_token() + end_lineno, end_col_offset = tok.end + return enaml_ast.OperatorExpr( + operator=a.string, + value=b, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) + self._reset(mark) + if (a := self._tmp_18()) and (b := self.py_expr()) and (self.expect("NEWLINE")): + tok = self._tokenizer.get_last_non_whitespace_token() + end_lineno, end_col_offset = tok.end + return ( + enaml_ast.OperatorExpr( + operator=a.string, + value=b, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) + if isinstance(b.ast.body, self.INVERTABLE) + else self.raise_syntax_error_known_location( + "can't assign to expression of this form", b + ) + ) + self._reset(mark) + if (a := self.expect(":")) and (b := self.expect(":")) and (c := self.block()): + tok = self._tokenizer.get_last_non_whitespace_token() + end_lineno, end_col_offset = tok.end + return ( + enaml_ast.OperatorExpr( + operator="::", + value=self.create_python_func_for_operator( + c, + self.NOTIFICATION_DISALLOWED, + "%s not allowed in a notification block", + ), + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) + if a.end == b.start + else self.raise_syntax_error_known_range( + "invalid syntax. Did you mean '::' ?", a, b + ) + ) + self._reset(mark) + if (self.expect("<<")) and (a := self.block()): + tok = self._tokenizer.get_last_non_whitespace_token() + end_lineno, end_col_offset = tok.end + return enaml_ast.OperatorExpr( + operator="<<", + value=self.create_python_func_for_operator( + a, + self.SUBSCRIPTION_DISALLOWED, + "%s not allowed in a subscription block", + ), + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) + self._reset(mark) + return None + + @memoize + def py_expr(self) -> Optional[enaml_ast.PythonExpression]: # py_expr: expression mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - (a := self.expression()) - ): + if a := self.expression(): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return enaml_ast . PythonExpression ( ast = ast . Expression ( body = a ) , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return enaml_ast.PythonExpression( + ast=ast.Expression(body=a), + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - return None; + return None @memoize def decl_funcdef(self) -> Optional[Any]: @@ -581,21 +586,47 @@ def decl_funcdef(self) -> Optional[Any]: mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - (self.expect('async')) - and - (a := self.sync_decl_fundef()) - ): - tok = self._tokenizer.get_last_non_whitespace_token() - end_lineno, end_col_offset = tok.end - return enaml_ast . AsyncFuncDef ( funcdef = ( ast . AsyncFunctionDef ( name = a . funcdef . name , args = a . funcdef . args , returns = a . funcdef . returns , body = a . funcdef . body , decorator_list = a . funcdef . decorator_list , type_params = [] , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset , ) if sys . version_info >= ( 3 , 12 ) else ast . AsyncFunctionDef ( name = a . funcdef . name , args = a . funcdef . args , returns = a . funcdef . returns , body = a . funcdef . body , decorator_list = a . funcdef . decorator_list , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset , ) ) , is_override = a . is_override , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); - self._reset(mark) - if ( - (sync_decl_fundef := self.sync_decl_fundef()) - ): - return sync_decl_fundef; - self._reset(mark) - return None; + if (self.expect("async")) and (a := self.sync_decl_fundef()): + tok = self._tokenizer.get_last_non_whitespace_token() + end_lineno, end_col_offset = tok.end + return enaml_ast.AsyncFuncDef( + funcdef=( + ast.AsyncFunctionDef( + name=a.funcdef.name, + args=a.funcdef.args, + returns=a.funcdef.returns, + body=a.funcdef.body, + decorator_list=a.funcdef.decorator_list, + type_params=[], + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) + if sys.version_info >= (3, 12) + else ast.AsyncFunctionDef( + name=a.funcdef.name, + args=a.funcdef.args, + returns=a.funcdef.returns, + body=a.funcdef.body, + decorator_list=a.funcdef.decorator_list, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) + ), + is_override=a.is_override, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) + self._reset(mark) + if sync_decl_fundef := self.sync_decl_fundef(): + return sync_decl_fundef + self._reset(mark) + return None @memoize def sync_decl_fundef(self) -> Optional[Any]: @@ -605,143 +636,188 @@ def sync_decl_fundef(self) -> Optional[Any]: start_lineno, start_col_offset = tok.start if ( (self.expect("func")) - and - (a := self.name()) - and - (self.expect('(')) - and - (b := self.params(),) - and - (self.expect(')')) - and - (r := self._tmp_19(),) - and - (self.expect_forced(self.expect(':'), "':'")) - and - (c := self.block()) - ): - tok = self._tokenizer.get_last_non_whitespace_token() - end_lineno, end_col_offset = tok.end - return enaml_ast . FuncDef ( funcdef = ( ast . FunctionDef ( name = a . string , args = b or self . make_arguments ( None , [] , None , [] , None ) , returns = r , body = self . validate_decl_func_body ( c ) , decorator_list = [] , type_params = [] , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ) if sys . version_info >= ( 3 , 12 ) else ast . FunctionDef ( name = a . string , args = b or self . make_arguments ( None , [] , None , [] , None ) , returns = r , body = self . validate_decl_func_body ( c ) , decorator_list = [] , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ) ) , is_override = False , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + and (a := self.name()) + and (self.expect("(")) + and (b := self.params(),) + and (self.expect(")")) + and (r := self._tmp_19(),) + and (self.expect_forced(self.expect(":"), "':'")) + and (c := self.block()) + ): + tok = self._tokenizer.get_last_non_whitespace_token() + end_lineno, end_col_offset = tok.end + return enaml_ast.FuncDef( + funcdef=( + ast.FunctionDef( + name=a.string, + args=b or self.make_arguments(None, [], None, [], None), + returns=r, + body=self.validate_decl_func_body(c), + decorator_list=[], + type_params=[], + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) + if sys.version_info >= (3, 12) + else ast.FunctionDef( + name=a.string, + args=b or self.make_arguments(None, [], None, [], None), + returns=r, + body=self.validate_decl_func_body(c), + decorator_list=[], + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) + ), + is_override=False, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) if ( (a := self.name()) - and - (x := self.expect('=')) - and - (y := self.expect('>')) - and - (self.expect('(')) - and - (b := self.params(),) - and - (self.expect(')')) - and - (r := self._tmp_20(),) - and - (self.expect_forced(self.expect(':'), "':'")) - and - (c := self.block()) - ): - tok = self._tokenizer.get_last_non_whitespace_token() - end_lineno, end_col_offset = tok.end - return enaml_ast . FuncDef ( funcdef = ( ast . FunctionDef ( name = a . string , args = b or self . make_arguments ( None , [] , None , [] , None ) , returns = r , body = self . validate_decl_func_body ( c ) , decorator_list = [] , type_params = [] , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ) if sys . version_info >= ( 3 , 12 ) else ast . FunctionDef ( name = a . string , args = b or self . make_arguments ( None , [] , None , [] , None ) , returns = r , body = self . validate_decl_func_body ( c ) , decorator_list = [] , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ) ) , is_override = True , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ) if x . end == y . start else self . raise_syntax_error_known_range ( "invalid syntax. Did you mean '=>' ?" , x , y ); - self._reset(mark) - return None; - - @memoize - def template(self) -> Optional[enaml_ast . Template]: + and (x := self.expect("=")) + and (y := self.expect(">")) + and (self.expect("(")) + and (b := self.params(),) + and (self.expect(")")) + and (r := self._tmp_20(),) + and (self.expect_forced(self.expect(":"), "':'")) + and (c := self.block()) + ): + tok = self._tokenizer.get_last_non_whitespace_token() + end_lineno, end_col_offset = tok.end + return ( + enaml_ast.FuncDef( + funcdef=( + ast.FunctionDef( + name=a.string, + args=b or self.make_arguments(None, [], None, [], None), + returns=r, + body=self.validate_decl_func_body(c), + decorator_list=[], + type_params=[], + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) + if sys.version_info >= (3, 12) + else ast.FunctionDef( + name=a.string, + args=b or self.make_arguments(None, [], None, [], None), + returns=r, + body=self.validate_decl_func_body(c), + decorator_list=[], + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) + ), + is_override=True, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) + if x.end == y.start + else self.raise_syntax_error_known_range( + "invalid syntax. Did you mean '=>' ?", x, y + ) + ) + self._reset(mark) + return None + + @memoize + def template(self) -> Optional[enaml_ast.Template]: # template: pragmas? "template" NAME '(' template_params? ')' &&':' template_body mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start if ( (a := self.pragmas(),) - and - (self.expect("template")) - and - (b := self.name()) - and - (self.expect('(')) - and - (c := self.template_params(),) - and - (self.expect(')')) - and - (self.expect_forced(self.expect(':'), "':'")) - and - (d := self.template_body()) - ): - tok = self._tokenizer.get_last_non_whitespace_token() - end_lineno, end_col_offset = tok.end - return self . validate_template ( enaml_ast . Template ( name = b . string , parameters = ( c or enaml_ast . TemplateParameters ( positional = [] , keywords = [] , starparam = "" ) ) , docstring = d [0] , body = [i for i in d [1] if not isinstance ( i , ast . Pass )] , pragmas = a or [] , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ) ); - self._reset(mark) - return None; - - @memoize - def template_body(self) -> Optional[Tuple [str , list]]: + and (self.expect("template")) + and (b := self.name()) + and (self.expect("(")) + and (c := self.template_params(),) + and (self.expect(")")) + and (self.expect_forced(self.expect(":"), "':'")) + and (d := self.template_body()) + ): + tok = self._tokenizer.get_last_non_whitespace_token() + end_lineno, end_col_offset = tok.end + return self.validate_template( + enaml_ast.Template( + name=b.string, + parameters=( + c + or enaml_ast.TemplateParameters( + positional=[], keywords=[], starparam="" + ) + ), + docstring=d[0], + body=[i for i in d[1] if not isinstance(i, ast.Pass)], + pragmas=a or [], + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) + ) + self._reset(mark) + return None + + @memoize + def template_body(self) -> Optional[Tuple[str, list]]: # template_body: NEWLINE INDENT template_item+ DEDENT | NEWLINE INDENT STRING NEWLINE template_item+ DEDENT | template_simple_item | invalid_block mark = self._mark() if ( - (self.expect('NEWLINE')) - and - (self.expect('INDENT')) - and - (a := self._loop1_21()) - and - (self.expect('DEDENT')) + (self.expect("NEWLINE")) + and (self.expect("INDENT")) + and (a := self._loop1_21()) + and (self.expect("DEDENT")) ): - return "" , a; + return "", a self._reset(mark) if ( - (self.expect('NEWLINE')) - and - (self.expect('INDENT')) - and - (d := self.string()) - and - (self.expect('NEWLINE')) - and - (a := self._loop1_22()) - and - (self.expect('DEDENT')) + (self.expect("NEWLINE")) + and (self.expect("INDENT")) + and (d := self.string()) + and (self.expect("NEWLINE")) + and (a := self._loop1_22()) + and (self.expect("DEDENT")) ): - return d . string , a; + return d.string, a self._reset(mark) - if ( - (a := self.template_simple_item()) - ): - return "" , [a]; + if a := self.template_simple_item(): + return "", [a] self._reset(mark) - if ( - self.call_invalid_rules - and - (self.invalid_block()) - ): - return None # pragma: no cover; + if self.call_invalid_rules and (self.invalid_block()): + return None # pragma: no cover self._reset(mark) - return None; + return None @memoize def template_item(self) -> Optional[Any]: # template_item: template_simple_item | child_def | template_inst mark = self._mark() - if ( - (template_simple_item := self.template_simple_item()) - ): - return template_simple_item; + if template_simple_item := self.template_simple_item(): + return template_simple_item self._reset(mark) - if ( - (child_def := self.child_def()) - ): - return child_def; + if child_def := self.child_def(): + return child_def self._reset(mark) - if ( - (template_inst := self.template_inst()) - ): - return template_inst; + if template_inst := self.template_inst(): + return template_inst self._reset(mark) - return None; + return None @memoize def template_simple_item(self) -> Optional[Any]: @@ -749,41 +825,36 @@ def template_simple_item(self) -> Optional[Any]: mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - (const_expr := self.const_expr()) - ): - return const_expr; + if const_expr := self.const_expr(): + return const_expr self._reset(mark) - if ( - (self.expect('pass')) - and - (self.expect('NEWLINE')) - ): + if (self.expect("pass")) and (self.expect("NEWLINE")): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . Pass ( lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.Pass( + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - return None; + return None @memoize def template_params(self) -> Optional[Any]: # template_params: ','.template_param+ [',' '*' NAME] | '*' NAME mark = self._mark() - if ( - (a := self._gather_23()) - and - (b := self._tmp_25(),) - ): - return enaml_ast . TemplateParameters ( ** self . validate_template_paramlist ( a , b . string if b else "" ) ); + if (a := self._gather_23()) and (b := self._tmp_25(),): + return enaml_ast.TemplateParameters( + **self.validate_template_paramlist(a, b.string if b else "") + ) self._reset(mark) - if ( - (self.expect('*')) - and - (b := self.name()) - ): - return enaml_ast . TemplateParameters ( ** self . validate_template_paramlist ( [] , b . string ) ); + if (self.expect("*")) and (b := self.name()): + return enaml_ast.TemplateParameters( + **self.validate_template_paramlist([], b.string) + ) self._reset(mark) - return None; + return None @memoize def template_param(self) -> Optional[Any]: @@ -791,36 +862,54 @@ def template_param(self) -> Optional[Any]: mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - (a := self.name()) - and - (self.expect(':')) - and - (b := self.expression()) - ): - tok = self._tokenizer.get_last_non_whitespace_token() - end_lineno, end_col_offset = tok.end - return enaml_ast . PositionalParameter ( name = a . string , specialization = enaml_ast . PythonExpression ( ast = ast . Expression ( body = b ) , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset , ) , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset , ); - self._reset(mark) - if ( - (a := self.name()) - and - (self.expect('=')) - and - (b := self.expression()) - ): - tok = self._tokenizer.get_last_non_whitespace_token() - end_lineno, end_col_offset = tok.end - return enaml_ast . KeywordParameter ( name = a . string , default = enaml_ast . PythonExpression ( ast = ast . Expression ( body = b ) , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset , ) , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset , ); - self._reset(mark) - if ( - (a := self.name()) - ): - tok = self._tokenizer.get_last_non_whitespace_token() - end_lineno, end_col_offset = tok.end - return enaml_ast . PositionalParameter ( name = a . string , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); - self._reset(mark) - return None; + if (a := self.name()) and (self.expect(":")) and (b := self.expression()): + tok = self._tokenizer.get_last_non_whitespace_token() + end_lineno, end_col_offset = tok.end + return enaml_ast.PositionalParameter( + name=a.string, + specialization=enaml_ast.PythonExpression( + ast=ast.Expression(body=b), + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ), + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) + self._reset(mark) + if (a := self.name()) and (self.expect("=")) and (b := self.expression()): + tok = self._tokenizer.get_last_non_whitespace_token() + end_lineno, end_col_offset = tok.end + return enaml_ast.KeywordParameter( + name=a.string, + default=enaml_ast.PythonExpression( + ast=ast.Expression(body=b), + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ), + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) + self._reset(mark) + if a := self.name(): + tok = self._tokenizer.get_last_non_whitespace_token() + end_lineno, end_col_offset = tok.end + return enaml_ast.PositionalParameter( + name=a.string, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) + self._reset(mark) + return None @memoize def template_inst(self) -> Optional[Any]: @@ -830,26 +919,31 @@ def template_inst(self) -> Optional[Any]: start_lineno, start_col_offset = tok.start if ( (a := self.pragmas(),) - and - (b := self.name()) - and - (self.expect('(')) - and - (c := self.template_args(),) - and - (self.expect(')')) - and - (d := self._tmp_26(),) - and - (self.expect(':')) - and - (e := self.template_inst_body()) + and (b := self.name()) + and (self.expect("(")) + and (c := self.template_args(),) + and (self.expect(")")) + and (d := self._tmp_26(),) + and (self.expect(":")) + and (e := self.template_inst_body()) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return self . validate_template_inst ( enaml_ast . TemplateInst ( name = b . string , arguments = ( c or enaml_ast . TemplateArguments ( args = [] , stararg = None ) ) , identifiers = d , pragmas = a or [] , body = [i for i in e if not isinstance ( i , ast . Pass )] , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset , ) ); + return self.validate_template_inst( + enaml_ast.TemplateInst( + name=b.string, + arguments=(c or enaml_ast.TemplateArguments(args=[], stararg=None)), + identifiers=d, + pragmas=a or [], + body=[i for i in e if not isinstance(i, ast.Pass)], + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) + ) self._reset(mark) - return None; + return None @memoize def template_args(self) -> Optional[Any]: @@ -857,25 +951,39 @@ def template_args(self) -> Optional[Any]: mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - (a := self._gather_27()) - and - (b := self._tmp_29(),) - ): + if (a := self._gather_27()) and (b := self._tmp_29(),): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return enaml_ast . TemplateArguments ( args = a , stararg = ( enaml_ast . PythonExpression ( ast = ast . Expression ( body = b ) , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset , ) if b else None ) , ); + return enaml_ast.TemplateArguments( + args=a, + stararg=( + enaml_ast.PythonExpression( + ast=ast.Expression(body=b), + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) + if b + else None + ), + ) self._reset(mark) - if ( - (self.expect('*')) - and - (b := self.expression()) - ): + if (self.expect("*")) and (b := self.expression()): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return enaml_ast . TemplateArguments ( args = [] , stararg = enaml_ast . PythonExpression ( ast = ast . Expression ( body = b ) , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset , ) , ); + return enaml_ast.TemplateArguments( + args=[], + stararg=enaml_ast.PythonExpression( + ast=ast.Expression(body=b), + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ), + ) self._reset(mark) - return None; + return None @memoize def template_argument(self) -> Optional[Any]: @@ -883,23 +991,36 @@ def template_argument(self) -> Optional[Any]: mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - (a := self.expression()) - ): + if a := self.expression(): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return enaml_ast . PythonExpression ( ast = ast . Expression ( body = a ) , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset , ); + return enaml_ast.PythonExpression( + ast=ast.Expression(body=a), + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - if ( - (a := self.expression()) - and - (b := self.for_if_clauses()) - ): + if (a := self.expression()) and (b := self.for_if_clauses()): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return enaml_ast . PythonExpression ( ast . GeneratorExp ( elt = a , generators = b , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ) , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset , ); + return enaml_ast.PythonExpression( + ast.GeneratorExp( + elt=a, + generators=b, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ), + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - return None; + return None @memoize def template_ids(self) -> Optional[Any]: @@ -907,54 +1028,51 @@ def template_ids(self) -> Optional[Any]: mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - (a := self._gather_30()) - and - (b := self._tmp_32(),) - ): + if (a := self._gather_30()) and (b := self._tmp_32(),): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return enaml_ast . TemplateIdentifiers ( names = [p . string for p in a] , starname = b . string if b else "" , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return enaml_ast.TemplateIdentifiers( + names=[p.string for p in a], + starname=b.string if b else "", + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - if ( - (self.expect('*')) - and - (b := self.name()) - ): + if (self.expect("*")) and (b := self.name()): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return enaml_ast . TemplateIdentifiers ( names = [] , starname = b . string , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return enaml_ast.TemplateIdentifiers( + names=[], + starname=b.string, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - return None; + return None @memoize def template_inst_body(self) -> Optional[Any]: # template_inst_body: NEWLINE INDENT template_inst_item+ DEDENT | template_inst_item | invalid_block mark = self._mark() if ( - (self.expect('NEWLINE')) - and - (self.expect('INDENT')) - and - (a := self._loop1_33()) - and - (self.expect('DEDENT')) + (self.expect("NEWLINE")) + and (self.expect("INDENT")) + and (a := self._loop1_33()) + and (self.expect("DEDENT")) ): - return a; + return a self._reset(mark) - if ( - (a := self.template_inst_item()) - ): - return [a]; + if a := self.template_inst_item(): + return [a] self._reset(mark) - if ( - self.call_invalid_rules - and - (self.invalid_block()) - ): - return None # pragma: no cover; + if self.call_invalid_rules and (self.invalid_block()): + return None # pragma: no cover self._reset(mark) - return None; + return None @memoize def template_inst_item(self) -> Optional[Any]: @@ -964,52 +1082,53 @@ def template_inst_item(self) -> Optional[Any]: start_lineno, start_col_offset = tok.start if ( (a := self.name()) - and - (b := self._tmp_34(),) - and - (c := self.operator_expr()) + and (b := self._tmp_34(),) + and (c := self.operator_expr()) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return enaml_ast . TemplateInstBinding ( name = a . string , chain = tuple ( p . string for p in b ) if b else ( ) , expr = c , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset , ); + return enaml_ast.TemplateInstBinding( + name=a.string, + chain=tuple(p.string for p in b) if b else (), + expr=c, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - if ( - (self.expect('pass')) - and - (self.expect('NEWLINE')) - ): + if (self.expect("pass")) and (self.expect("NEWLINE")): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . Pass ( lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.Pass( + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - return None; + return None @memoize def statements(self) -> Optional[list]: # statements: statement+ mark = self._mark() - if ( - (a := self._loop1_35()) - ): - return list ( itertools . chain . from_iterable ( a ) ); + if a := self._loop1_35(): + return list(itertools.chain.from_iterable(a)) self._reset(mark) - return None; + return None @memoize def statement(self) -> Optional[list]: # statement: compound_stmt | simple_stmts mark = self._mark() - if ( - (a := self.compound_stmt()) - ): - return [a]; + if a := self.compound_stmt(): + return [a] self._reset(mark) - if ( - (a := self.simple_stmts()) - ): - return a; + if a := self.simple_stmts(): + return a self._reset(mark) - return None; + return None @memoize def statement_newline(self) -> Optional[list]: @@ -1017,31 +1136,28 @@ def statement_newline(self) -> Optional[list]: mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - (a := self.compound_stmt()) - and - (self.expect('NEWLINE')) - ): - return [a]; + if (a := self.compound_stmt()) and (self.expect("NEWLINE")): + return [a] self._reset(mark) - if ( - (simple_stmts := self.simple_stmts()) - ): - return simple_stmts; + if simple_stmts := self.simple_stmts(): + return simple_stmts self._reset(mark) - if ( - (self.expect('NEWLINE')) - ): + if self.expect("NEWLINE"): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return [ast . Pass ( lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset )]; + return [ + ast.Pass( + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) + ] self._reset(mark) - if ( - (self.expect('ENDMARKER')) - ): - return None; + if self.expect("ENDMARKER"): + return None self._reset(mark) - return None; + return None @memoize def simple_stmts(self) -> Optional[list]: @@ -1049,187 +1165,168 @@ def simple_stmts(self) -> Optional[list]: mark = self._mark() if ( (a := self.simple_stmt()) - and - (self.negative_lookahead(self.expect, ';')) - and - (self.expect('NEWLINE')) + and (self.negative_lookahead(self.expect, ";")) + and (self.expect("NEWLINE")) ): - return [a]; + return [a] self._reset(mark) if ( (a := self._gather_36()) - and - (self.expect(';'),) - and - (self.expect('NEWLINE')) + and (self.expect(";"),) + and (self.expect("NEWLINE")) ): - return a; + return a self._reset(mark) - return None; + return None @memoize def simple_stmt(self) -> Optional[Any]: - # simple_stmt: assignment | &"type" type_alias | star_expressions | &'return' return_stmt | &('import' | 'from') import_stmt | &'raise' raise_stmt | 'pass' | &'del' del_stmt | &'yield' yield_stmt | &'assert' assert_stmt | 'break' | 'continue' | &'global' global_stmt | &'nonlocal' nonlocal_stmt + # simple_stmt: assignment | &"type" type_alias | &('import' | 'from' | "lazy") import_stmt | star_expressions | &'return' return_stmt | &'raise' raise_stmt | 'pass' | &'del' del_stmt | &'yield' yield_stmt | &'assert' assert_stmt | 'break' | 'continue' | &'global' global_stmt | &'nonlocal' nonlocal_stmt mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - (assignment := self.assignment()) - ): - return assignment; + if assignment := self.assignment(): + return assignment self._reset(mark) - if ( - (self.positive_lookahead(self.expect, "type")) - and - (type_alias := self.type_alias()) + if (self.positive_lookahead(self.expect, "type")) and ( + type_alias := self.type_alias() ): - return type_alias; + return type_alias self._reset(mark) if ( - (e := self.star_expressions()) - ): + self.positive_lookahead( + self._tmp_38, + ) + ) and (import_stmt := self.import_stmt()): + return import_stmt + self._reset(mark) + if e := self.star_expressions(): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . Expr ( value = e , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); - self._reset(mark) - if ( - (self.positive_lookahead(self.expect, 'return')) - and - (return_stmt := self.return_stmt()) - ): - return return_stmt; + return ast.Expr( + value=e, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - if ( - (self.positive_lookahead(self._tmp_38, )) - and - (import_stmt := self.import_stmt()) + if (self.positive_lookahead(self.expect, "return")) and ( + return_stmt := self.return_stmt() ): - return import_stmt; + return return_stmt self._reset(mark) - if ( - (self.positive_lookahead(self.expect, 'raise')) - and - (raise_stmt := self.raise_stmt()) + if (self.positive_lookahead(self.expect, "raise")) and ( + raise_stmt := self.raise_stmt() ): - return raise_stmt; + return raise_stmt self._reset(mark) - if ( - (self.expect('pass')) - ): + if self.expect("pass"): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . Pass ( lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.Pass( + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - if ( - (self.positive_lookahead(self.expect, 'del')) - and - (del_stmt := self.del_stmt()) + if (self.positive_lookahead(self.expect, "del")) and ( + del_stmt := self.del_stmt() ): - return del_stmt; + return del_stmt self._reset(mark) - if ( - (self.positive_lookahead(self.expect, 'yield')) - and - (yield_stmt := self.yield_stmt()) + if (self.positive_lookahead(self.expect, "yield")) and ( + yield_stmt := self.yield_stmt() ): - return yield_stmt; + return yield_stmt self._reset(mark) - if ( - (self.positive_lookahead(self.expect, 'assert')) - and - (assert_stmt := self.assert_stmt()) + if (self.positive_lookahead(self.expect, "assert")) and ( + assert_stmt := self.assert_stmt() ): - return assert_stmt; + return assert_stmt self._reset(mark) - if ( - (self.expect('break')) - ): + if self.expect("break"): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . Break ( lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.Break( + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - if ( - (self.expect('continue')) - ): + if self.expect("continue"): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . Continue ( lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.Continue( + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - if ( - (self.positive_lookahead(self.expect, 'global')) - and - (global_stmt := self.global_stmt()) + if (self.positive_lookahead(self.expect, "global")) and ( + global_stmt := self.global_stmt() ): - return global_stmt; + return global_stmt self._reset(mark) - if ( - (self.positive_lookahead(self.expect, 'nonlocal')) - and - (nonlocal_stmt := self.nonlocal_stmt()) + if (self.positive_lookahead(self.expect, "nonlocal")) and ( + nonlocal_stmt := self.nonlocal_stmt() ): - return nonlocal_stmt; + return nonlocal_stmt self._reset(mark) - return None; + return None @memoize def compound_stmt(self) -> Optional[Any]: # compound_stmt: &('def' | '@' | 'async') function_def | &'if' if_stmt | &('class' | '@') class_def | &('with' | 'async') with_stmt | &('for' | 'async') for_stmt | &'try' try_stmt | &'while' while_stmt | match_stmt mark = self._mark() if ( - (self.positive_lookahead(self._tmp_39, )) - and - (function_def := self.function_def()) - ): - return function_def; + self.positive_lookahead( + self._tmp_39, + ) + ) and (function_def := self.function_def()): + return function_def self._reset(mark) - if ( - (self.positive_lookahead(self.expect, 'if')) - and - (if_stmt := self.if_stmt()) - ): - return if_stmt; + if (self.positive_lookahead(self.expect, "if")) and (if_stmt := self.if_stmt()): + return if_stmt self._reset(mark) if ( - (self.positive_lookahead(self._tmp_40, )) - and - (class_def := self.class_def()) - ): - return class_def; + self.positive_lookahead( + self._tmp_40, + ) + ) and (class_def := self.class_def()): + return class_def self._reset(mark) if ( - (self.positive_lookahead(self._tmp_41, )) - and - (with_stmt := self.with_stmt()) - ): - return with_stmt; + self.positive_lookahead( + self._tmp_41, + ) + ) and (with_stmt := self.with_stmt()): + return with_stmt self._reset(mark) if ( - (self.positive_lookahead(self._tmp_42, )) - and - (for_stmt := self.for_stmt()) - ): - return for_stmt; + self.positive_lookahead( + self._tmp_42, + ) + ) and (for_stmt := self.for_stmt()): + return for_stmt self._reset(mark) - if ( - (self.positive_lookahead(self.expect, 'try')) - and - (try_stmt := self.try_stmt()) + if (self.positive_lookahead(self.expect, "try")) and ( + try_stmt := self.try_stmt() ): - return try_stmt; + return try_stmt self._reset(mark) - if ( - (self.positive_lookahead(self.expect, 'while')) - and - (while_stmt := self.while_stmt()) + if (self.positive_lookahead(self.expect, "while")) and ( + while_stmt := self.while_stmt() ): - return while_stmt; + return while_stmt self._reset(mark) - if ( - (match_stmt := self.match_stmt()) - ): - return match_stmt; + if match_stmt := self.match_stmt(): + return match_stmt self._reset(mark) - return None; + return None @memoize def assignment(self) -> Optional[Any]: @@ -1239,539 +1336,644 @@ def assignment(self) -> Optional[Any]: start_lineno, start_col_offset = tok.start if ( (a := self.name()) - and - (self.expect(':')) - and - (b := self.expression()) - and - (c := self._tmp_43(),) - ): - tok = self._tokenizer.get_last_non_whitespace_token() - end_lineno, end_col_offset = tok.end - return self . check_version ( ( 3 , 6 ) , "Variable annotation syntax is" , ast . AnnAssign ( target = ast . Name ( id = a . string , ctx = Store , lineno = a . start [0] , col_offset = a . start [1] , end_lineno = a . end [0] , end_col_offset = a . end [1] , ) , annotation = b , value = c , simple = 1 , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset , ) ); + and (self.expect(":")) + and (b := self.expression()) + and (c := self._tmp_43(),) + ): + tok = self._tokenizer.get_last_non_whitespace_token() + end_lineno, end_col_offset = tok.end + return self.check_version( + (3, 6), + "Variable annotation syntax is", + ast.AnnAssign( + target=ast.Name( + id=a.string, + ctx=Store, + lineno=a.start[0], + col_offset=a.start[1], + end_lineno=a.end[0], + end_col_offset=a.end[1], + ), + annotation=b, + value=c, + simple=1, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ), + ) self._reset(mark) if ( (a := self._tmp_44()) - and - (self.expect(':')) - and - (b := self.expression()) - and - (c := self._tmp_45(),) + and (self.expect(":")) + and (b := self.expression()) + and (c := self._tmp_45(),) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return self . check_version ( ( 3 , 6 ) , "Variable annotation syntax is" , ast . AnnAssign ( target = a , annotation = b , value = c , simple = 0 , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset , ) ); + return self.check_version( + (3, 6), + "Variable annotation syntax is", + ast.AnnAssign( + target=a, + annotation=b, + value=c, + simple=0, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ), + ) self._reset(mark) if ( (a := self._loop1_46()) - and - (b := self._tmp_47()) - and - (self.negative_lookahead(self.expect, '=')) - and - (tc := self.type_comment(),) + and (b := self._tmp_47()) + and (self.negative_lookahead(self.expect, "=")) + and (tc := self.type_comment(),) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . Assign ( targets = a , value = b , type_comment = tc , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.Assign( + targets=a, + value=b, + type_comment=tc, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) cut = False if ( (a := self.single_target()) - and - (b := self.augassign()) - and - (cut := True) - and - (c := self._tmp_48()) + and (b := self.augassign()) + and (cut := True) + and (c := self._tmp_48()) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . AugAssign ( target = a , op = b , value = c , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.AugAssign( + target=a, + op=b, + value=c, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) if cut: - return None; - if ( - self.call_invalid_rules - and - (self.invalid_assignment()) - ): - return None # pragma: no cover; + return None + if self.call_invalid_rules and (self.invalid_assignment()): + return None # pragma: no cover self._reset(mark) - return None; + return None @memoize def annotated_rhs(self) -> Optional[Any]: # annotated_rhs: yield_expr | star_expressions mark = self._mark() - if ( - (yield_expr := self.yield_expr()) - ): - return yield_expr; + if yield_expr := self.yield_expr(): + return yield_expr self._reset(mark) - if ( - (star_expressions := self.star_expressions()) - ): - return star_expressions; + if star_expressions := self.star_expressions(): + return star_expressions self._reset(mark) - return None; + return None @memoize def augassign(self) -> Optional[Any]: # augassign: '+=' | '-=' | '*=' | '@=' | '/=' | '%=' | '&=' | '|=' | '^=' | '<<=' | '>>=' | '**=' | '//=' mark = self._mark() - if ( - (self.expect('+=')) - ): - return ast . Add ( ); + if self.expect("+="): + return ast.Add() self._reset(mark) - if ( - (self.expect('-=')) - ): - return ast . Sub ( ); + if self.expect("-="): + return ast.Sub() self._reset(mark) - if ( - (self.expect('*=')) - ): - return ast . Mult ( ); + if self.expect("*="): + return ast.Mult() self._reset(mark) - if ( - (self.expect('@=')) - ): - return self . check_version ( ( 3 , 5 ) , "The '@' operator is" , ast . MatMult ( ) ); + if self.expect("@="): + return self.check_version((3, 5), "The '@' operator is", ast.MatMult()) self._reset(mark) - if ( - (self.expect('/=')) - ): - return ast . Div ( ); + if self.expect("/="): + return ast.Div() self._reset(mark) - if ( - (self.expect('%=')) - ): - return ast . Mod ( ); + if self.expect("%="): + return ast.Mod() self._reset(mark) - if ( - (self.expect('&=')) - ): - return ast . BitAnd ( ); + if self.expect("&="): + return ast.BitAnd() self._reset(mark) - if ( - (self.expect('|=')) - ): - return ast . BitOr ( ); + if self.expect("|="): + return ast.BitOr() self._reset(mark) - if ( - (self.expect('^=')) - ): - return ast . BitXor ( ); + if self.expect("^="): + return ast.BitXor() self._reset(mark) - if ( - (self.expect('<<=')) - ): - return ast . LShift ( ); + if self.expect("<<="): + return ast.LShift() self._reset(mark) - if ( - (self.expect('>>=')) - ): - return ast . RShift ( ); + if self.expect(">>="): + return ast.RShift() self._reset(mark) - if ( - (self.expect('**=')) - ): - return ast . Pow ( ); + if self.expect("**="): + return ast.Pow() self._reset(mark) - if ( - (self.expect('//=')) - ): - return ast . FloorDiv ( ); + if self.expect("//="): + return ast.FloorDiv() self._reset(mark) - return None; + return None @memoize - def return_stmt(self) -> Optional[ast . Return]: + def return_stmt(self) -> Optional[ast.Return]: # return_stmt: 'return' star_expressions? mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - (self.expect('return')) - and - (a := self.star_expressions(),) - ): + if (self.expect("return")) and (a := self.star_expressions(),): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . Return ( value = a , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.Return( + value=a, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - return None; + return None @memoize - def raise_stmt(self) -> Optional[ast . Raise]: + def raise_stmt(self) -> Optional[ast.Raise]: # raise_stmt: 'raise' expression ['from' expression] | 'raise' mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start if ( - (self.expect('raise')) - and - (a := self.expression()) - and - (b := self._tmp_49(),) + (self.expect("raise")) + and (a := self.expression()) + and (b := self._tmp_49(),) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . Raise ( exc = a , cause = b , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.Raise( + exc=a, + cause=b, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - if ( - (self.expect('raise')) - ): + if self.expect("raise"): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . Raise ( exc = None , cause = None , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.Raise( + exc=None, + cause=None, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - return None; + return None @memoize - def global_stmt(self) -> Optional[ast . Global]: + def global_stmt(self) -> Optional[ast.Global]: # global_stmt: 'global' ','.NAME+ mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - (self.expect('global')) - and - (a := self._gather_50()) - ): + if (self.expect("global")) and (a := self._gather_50()): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . Global ( names = [n . string for n in a] , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.Global( + names=[n.string for n in a], + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - return None; + return None @memoize - def nonlocal_stmt(self) -> Optional[ast . Nonlocal]: + def nonlocal_stmt(self) -> Optional[ast.Nonlocal]: # nonlocal_stmt: 'nonlocal' ','.NAME+ mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - (self.expect('nonlocal')) - and - (a := self._gather_52()) - ): + if (self.expect("nonlocal")) and (a := self._gather_52()): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . Nonlocal ( names = [n . string for n in a] , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.Nonlocal( + names=[n.string for n in a], + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - return None; + return None @memoize - def del_stmt(self) -> Optional[ast . Delete]: + def del_stmt(self) -> Optional[ast.Delete]: # del_stmt: 'del' del_targets &(';' | NEWLINE) | invalid_del_stmt mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start if ( - (self.expect('del')) - and - (a := self.del_targets()) - and - (self.positive_lookahead(self._tmp_54, )) + (self.expect("del")) + and (a := self.del_targets()) + and ( + self.positive_lookahead( + self._tmp_54, + ) + ) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . Delete ( targets = a , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.Delete( + targets=a, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - if ( - self.call_invalid_rules - and - (self.invalid_del_stmt()) - ): - return None # pragma: no cover; + if self.call_invalid_rules and (self.invalid_del_stmt()): + return None # pragma: no cover self._reset(mark) - return None; + return None @memoize - def yield_stmt(self) -> Optional[ast . Expr]: + def yield_stmt(self) -> Optional[ast.Expr]: # yield_stmt: yield_expr mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - (y := self.yield_expr()) - ): + if y := self.yield_expr(): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . Expr ( value = y , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.Expr( + value=y, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - return None; + return None @memoize - def assert_stmt(self) -> Optional[ast . Assert]: + def assert_stmt(self) -> Optional[ast.Assert]: # assert_stmt: 'assert' expression [',' expression] mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start if ( - (self.expect('assert')) - and - (a := self.expression()) - and - (b := self._tmp_55(),) + (self.expect("assert")) + and (a := self.expression()) + and (b := self._tmp_55(),) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . Assert ( test = a , msg = b , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.Assert( + test=a, + msg=b, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - return None; + return None @memoize - def import_stmt(self) -> Optional[ast . Import]: + def import_stmt(self) -> Optional[ast.Import]: # import_stmt: invalid_import | import_name | import_from mark = self._mark() - if ( - self.call_invalid_rules - and - (self.invalid_import()) - ): - return None # pragma: no cover; + if self.call_invalid_rules and (self.invalid_import()): + return None # pragma: no cover self._reset(mark) - if ( - (import_name := self.import_name()) - ): - return import_name; + if import_name := self.import_name(): + return import_name self._reset(mark) - if ( - (import_from := self.import_from()) - ): - return import_from; + if import_from := self.import_from(): + return import_from self._reset(mark) - return None; + return None @memoize - def import_name(self) -> Optional[ast . Import]: - # import_name: 'import' dotted_as_names + def import_name(self) -> Optional[ast.Import]: + # import_name: "lazy"? 'import' dotted_as_names mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start if ( - (self.expect('import')) - and - (a := self.dotted_as_names()) - ): - tok = self._tokenizer.get_last_non_whitespace_token() - end_lineno, end_col_offset = tok.end - return ast . Import ( names = a , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); - self._reset(mark) - return None; - - @memoize - def import_from(self) -> Optional[ast . ImportFrom]: - # import_from: 'from' (('.' | '...'))* dotted_name 'import' import_from_targets | 'from' (('.' | '...'))+ 'import' import_from_targets + (lazy := self.expect("lazy"),) + and (self.expect("import")) + and (a := self.dotted_as_names()) + ): + tok = self._tokenizer.get_last_non_whitespace_token() + end_lineno, end_col_offset = tok.end + return ( + ast.Import( + names=a, + is_lazy=1 if lazy else 0, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) + if self.py_version >= (3, 15) + else self.check_version( + (3, 15), + "Lazy imports are", + ast.Import( + names=a, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ), + ) + if lazy + else ast.Import( + names=a, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) + ) + self._reset(mark) + return None + + @memoize + def import_from(self) -> Optional[ast.ImportFrom]: + # import_from: invalid_import_from | "lazy"? 'from' (('.' | '...'))* dotted_name 'import' import_from_targets | "lazy"? 'from' (('.' | '...'))+ 'import' import_from_targets mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - (self.expect('from')) - and - (a := self._loop0_56(),) - and - (b := self.dotted_name()) - and - (self.expect('import')) - and - (c := self.import_from_targets()) - ): - tok = self._tokenizer.get_last_non_whitespace_token() - end_lineno, end_col_offset = tok.end - return ast . ImportFrom ( module = b , names = c , level = self . extract_import_level ( a ) , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); - self._reset(mark) - if ( - (self.expect('from')) - and - (a := self._loop1_57()) - and - (self.expect('import')) - and - (b := self.import_from_targets()) - ): - tok = self._tokenizer.get_last_non_whitespace_token() - end_lineno, end_col_offset = tok.end - return ast . ImportFrom ( names = b , level = self . extract_import_level ( a ) , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ) if sys . version_info >= ( 3 , 9 ) else ast . ImportFrom ( module = None , names = b , level = self . extract_import_level ( a ) , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); - self._reset(mark) - return None; - - @memoize - def import_from_targets(self) -> Optional[List [ast . alias]]: + if self.call_invalid_rules and (self.invalid_import_from()): + return None # pragma: no cover + self._reset(mark) + if ( + (lazy := self.expect("lazy"),) + and (self.expect("from")) + and (a := self._loop0_56(),) + and (b := self.dotted_name()) + and (self.expect("import")) + and (c := self.import_from_targets()) + ): + tok = self._tokenizer.get_last_non_whitespace_token() + end_lineno, end_col_offset = tok.end + return ( + ast.ImportFrom( + module=b, + names=c, + level=self.extract_import_level(a), + is_lazy=1 if lazy else 0, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) + if self.py_version >= (3, 15) + else self.check_version( + (3, 15), + "Lazy imports are", + ast.ImportFrom( + module=b, + names=c, + level=self.extract_import_level(a), + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ), + ) + if lazy + else ast.ImportFrom( + module=b, + names=c, + level=self.extract_import_level(a), + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) + ) + self._reset(mark) + if ( + (lazy := self.expect("lazy"),) + and (self.expect("from")) + and (a := self._loop1_57()) + and (self.expect("import")) + and (b := self.import_from_targets()) + ): + tok = self._tokenizer.get_last_non_whitespace_token() + end_lineno, end_col_offset = tok.end + return ( + ast.ImportFrom( + names=b, + level=self.extract_import_level(a), + is_lazy=1 if lazy else 0, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) + if self.py_version >= (3, 15) + else self.check_version( + (3, 15), + "Lazy imports are", + ast.ImportFrom( + names=b, + level=self.extract_import_level(a), + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ), + ) + if lazy + else ast.ImportFrom( + names=b, + level=self.extract_import_level(a), + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) + if self.py_version >= (3, 9) + else ast.ImportFrom( + module=None, + names=b, + level=self.extract_import_level(a), + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) + ) + self._reset(mark) + return None + + @memoize + def import_from_targets(self) -> Optional[List[ast.alias]]: # import_from_targets: '(' import_from_as_names ','? ')' | import_from_as_names !',' | '*' | invalid_import_from_targets mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start if ( - (self.expect('(')) - and - (a := self.import_from_as_names()) - and - (self.expect(','),) - and - (self.expect(')')) + (self.expect("(")) + and (a := self.import_from_as_names()) + and (self.expect(","),) + and (self.expect(")")) ): - return a; + return a self._reset(mark) - if ( - (import_from_as_names := self.import_from_as_names()) - and - (self.negative_lookahead(self.expect, ',')) + if (import_from_as_names := self.import_from_as_names()) and ( + self.negative_lookahead(self.expect, ",") ): - return import_from_as_names; + return import_from_as_names self._reset(mark) - if ( - (self.expect('*')) - ): + if self.expect("*"): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return [ast . alias ( name = "*" , asname = None , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset )]; + return [ + ast.alias( + name="*", + asname=None, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) + ] self._reset(mark) - if ( - self.call_invalid_rules - and - (self.invalid_import_from_targets()) - ): - return None # pragma: no cover; + if self.call_invalid_rules and (self.invalid_import_from_targets()): + return None # pragma: no cover self._reset(mark) - return None; + return None @memoize - def import_from_as_names(self) -> Optional[List [ast . alias]]: + def import_from_as_names(self) -> Optional[List[ast.alias]]: # import_from_as_names: ','.import_from_as_name+ mark = self._mark() - if ( - (a := self._gather_58()) - ): - return a; + if a := self._gather_58(): + return a self._reset(mark) - return None; + return None @memoize - def import_from_as_name(self) -> Optional[ast . alias]: + def import_from_as_name(self) -> Optional[ast.alias]: # import_from_as_name: NAME ['as' NAME] mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - (a := self.name()) - and - (b := self._tmp_60(),) - ): + if (a := self.name()) and (b := self._tmp_60(),): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . alias ( name = a . string , asname = b , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.alias( + name=a.string, + asname=b, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - return None; + return None @memoize - def dotted_as_names(self) -> Optional[List [ast . alias]]: + def dotted_as_names(self) -> Optional[List[ast.alias]]: # dotted_as_names: ','.dotted_as_name+ mark = self._mark() - if ( - (a := self._gather_61()) - ): - return a; + if a := self._gather_61(): + return a self._reset(mark) - return None; + return None @memoize - def dotted_as_name(self) -> Optional[ast . alias]: + def dotted_as_name(self) -> Optional[ast.alias]: # dotted_as_name: dotted_name ['as' NAME] mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - (a := self.dotted_name()) - and - (b := self._tmp_63(),) - ): + if (a := self.dotted_name()) and (b := self._tmp_63(),): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . alias ( name = a , asname = b , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.alias( + name=a, + asname=b, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - return None; + return None @memoize_left_rec def dotted_name(self) -> Optional[str]: # dotted_name: dotted_name '.' NAME | NAME mark = self._mark() - if ( - (a := self.dotted_name()) - and - (self.expect('.')) - and - (b := self.name()) - ): - return a + "." + b . string; + if (a := self.dotted_name()) and (self.expect(".")) and (b := self.name()): + return a + "." + b.string self._reset(mark) - if ( - (a := self.name()) - ): - return a . string; + if a := self.name(): + return a.string self._reset(mark) - return None; + return None @memoize def block(self) -> Optional[list]: # block: NEWLINE INDENT statements DEDENT | simple_stmts | invalid_block mark = self._mark() if ( - (self.expect('NEWLINE')) - and - (self.expect('INDENT')) - and - (a := self.statements()) - and - (self.expect('DEDENT')) + (self.expect("NEWLINE")) + and (self.expect("INDENT")) + and (a := self.statements()) + and (self.expect("DEDENT")) ): - return a; + return a self._reset(mark) - if ( - (simple_stmts := self.simple_stmts()) - ): - return simple_stmts; + if simple_stmts := self.simple_stmts(): + return simple_stmts self._reset(mark) - if ( - self.call_invalid_rules - and - (self.invalid_block()) - ): - return None # pragma: no cover; + if self.call_invalid_rules and (self.invalid_block()): + return None # pragma: no cover self._reset(mark) - return None; + return None @memoize def decorators(self) -> Optional[Any]: # decorators: decorator+ mark = self._mark() - if ( - (_loop1_64 := self._loop1_64()) - ): - return _loop1_64; + if _loop1_64 := self._loop1_64(): + return _loop1_64 self._reset(mark) - return None; + return None @memoize def decorator(self) -> Optional[Any]: # decorator: ('@' dec_maybe_call NEWLINE) | ('@' named_expression NEWLINE) mark = self._mark() - if ( - (a := self._tmp_65()) - ): - return a; + if a := self._tmp_65(): + return a self._reset(mark) - if ( - (a := self._tmp_66()) - ): - return self . check_version ( ( 3 , 9 ) , "Generic decorator are" , a ); + if a := self._tmp_66(): + return self.check_version((3, 9), "Generic decorator are", a) self._reset(mark) - return None; + return None @memoize def dec_maybe_call(self) -> Optional[Any]: @@ -1781,23 +1983,26 @@ def dec_maybe_call(self) -> Optional[Any]: start_lineno, start_col_offset = tok.start if ( (dn := self.dec_primary()) - and - (self.expect('(')) - and - (z := self.arguments(),) - and - (self.expect(')')) + and (self.expect("(")) + and (z := self.arguments(),) + and (self.expect(")")) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . Call ( func = dn , args = z [0] if z else [] , keywords = z [1] if z else [] , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.Call( + func=dn, + args=z[0] if z else [], + keywords=z[1] if z else [], + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - if ( - (dec_primary := self.dec_primary()) - ): - return dec_primary; + if dec_primary := self.dec_primary(): + return dec_primary self._reset(mark) - return None; + return None @memoize_left_rec def dec_primary(self) -> Optional[Any]: @@ -1805,452 +2010,432 @@ def dec_primary(self) -> Optional[Any]: mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - (a := self.dec_primary()) - and - (self.expect('.')) - and - (b := self.name()) - ): + if (a := self.dec_primary()) and (self.expect(".")) and (b := self.name()): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . Attribute ( value = a , attr = b . string , ctx = Load , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.Attribute( + value=a, + attr=b.string, + ctx=Load, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - if ( - (a := self.name()) - ): + if a := self.name(): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . Name ( id = a . string , ctx = Load , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.Name( + id=a.string, + ctx=Load, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - return None; + return None @memoize - def class_def(self) -> Optional[ast . ClassDef]: + def class_def(self) -> Optional[ast.ClassDef]: # class_def: decorators class_def_raw | class_def_raw mark = self._mark() - if ( - (a := self.decorators()) - and - (b := self.class_def_raw()) - ): - return self . set_decorators ( b , a ); + if (a := self.decorators()) and (b := self.class_def_raw()): + return self.set_decorators(b, a) self._reset(mark) - if ( - (class_def_raw := self.class_def_raw()) - ): - return class_def_raw; + if class_def_raw := self.class_def_raw(): + return class_def_raw self._reset(mark) - return None; + return None @memoize - def class_def_raw(self) -> Optional[ast . ClassDef]: + def class_def_raw(self) -> Optional[ast.ClassDef]: # class_def_raw: invalid_class_def_raw | 'class' NAME type_params? ['(' arguments? ')'] &&':' block mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - self.call_invalid_rules - and - (self.invalid_class_def_raw()) - ): - return None # pragma: no cover; - self._reset(mark) - if ( - (self.expect('class')) - and - (a := self.name()) - and - (t := self.type_params(),) - and - (b := self._tmp_67(),) - and - (self.expect_forced(self.expect(':'), "':'")) - and - (c := self.block()) - ): - tok = self._tokenizer.get_last_non_whitespace_token() - end_lineno, end_col_offset = tok.end - return ( ast . ClassDef ( a . string , bases = b [0] if b else [] , keywords = b [1] if b else [] , body = c , decorator_list = [] , type_params = t or [] , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset , ) if sys . version_info >= ( 3 , 12 ) else ast . ClassDef ( a . string , bases = b [0] if b else [] , keywords = b [1] if b else [] , body = c , decorator_list = [] , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset , ) ); - self._reset(mark) - return None; - - @memoize - def function_def(self) -> Optional[Union [ast . FunctionDef , ast . AsyncFunctionDef]]: + if self.call_invalid_rules and (self.invalid_class_def_raw()): + return None # pragma: no cover + self._reset(mark) + if ( + (self.expect("class")) + and (a := self.name()) + and (t := self.type_params(),) + and (b := self._tmp_67(),) + and (self.expect_forced(self.expect(":"), "':'")) + and (c := self.block()) + ): + tok = self._tokenizer.get_last_non_whitespace_token() + end_lineno, end_col_offset = tok.end + return ( + ast.ClassDef( + a.string, + bases=b[0] if b else [], + keywords=b[1] if b else [], + body=c, + decorator_list=[], + type_params=t or [], + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) + if sys.version_info >= (3, 12) + else ast.ClassDef( + a.string, + bases=b[0] if b else [], + keywords=b[1] if b else [], + body=c, + decorator_list=[], + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) + ) + self._reset(mark) + return None + + @memoize + def function_def(self) -> Optional[Union[ast.FunctionDef, ast.AsyncFunctionDef]]: # function_def: decorators function_def_raw | function_def_raw mark = self._mark() - if ( - (d := self.decorators()) - and - (f := self.function_def_raw()) - ): - return self . set_decorators ( f , d ); + if (d := self.decorators()) and (f := self.function_def_raw()): + return self.set_decorators(f, d) self._reset(mark) - if ( - (f := self.function_def_raw()) - ): - return self . set_decorators ( f , [] ); + if f := self.function_def_raw(): + return self.set_decorators(f, []) self._reset(mark) - return None; + return None @memoize - def function_def_raw(self) -> Optional[Union [ast . FunctionDef , ast . AsyncFunctionDef]]: + def function_def_raw( + self, + ) -> Optional[Union[ast.FunctionDef, ast.AsyncFunctionDef]]: # function_def_raw: invalid_def_raw | 'def' NAME type_params? &&'(' params? ')' ['->' expression] &&':' func_type_comment? block | 'async' 'def' NAME type_params? &&'(' params? ')' ['->' expression] &&':' func_type_comment? block mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - self.call_invalid_rules - and - (self.invalid_def_raw()) - ): - return None # pragma: no cover; - self._reset(mark) - if ( - (self.expect('def')) - and - (n := self.name()) - and - (t := self.type_params(),) - and - (self.expect_forced(self.expect('('), "'('")) - and - (params := self.params(),) - and - (self.expect(')')) - and - (a := self._tmp_68(),) - and - (self.expect_forced(self.expect(':'), "':'")) - and - (tc := self.func_type_comment(),) - and - (b := self.block()) - ): - tok = self._tokenizer.get_last_non_whitespace_token() - end_lineno, end_col_offset = tok.end - return ( ast . FunctionDef ( name = n . string , args = params or self . make_arguments ( None , [] , None , [] , None ) , returns = a , body = b , type_comment = tc , type_params = t or [] , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset , ) if sys . version_info >= ( 3 , 12 ) else ast . FunctionDef ( name = n . string , args = params or self . make_arguments ( None , [] , None , [] , None ) , returns = a , body = b , type_comment = tc , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset , ) ); - self._reset(mark) - if ( - (self.expect('async')) - and - (self.expect('def')) - and - (n := self.name()) - and - (t := self.type_params(),) - and - (self.expect_forced(self.expect('('), "'('")) - and - (params := self.params(),) - and - (self.expect(')')) - and - (a := self._tmp_69(),) - and - (self.expect_forced(self.expect(':'), "':'")) - and - (tc := self.func_type_comment(),) - and - (b := self.block()) - ): - tok = self._tokenizer.get_last_non_whitespace_token() - end_lineno, end_col_offset = tok.end - return ( self . check_version ( ( 3 , 5 ) , "Async functions are" , ast . AsyncFunctionDef ( name = n . string , args = params or self . make_arguments ( None , [] , None , [] , None ) , returns = a , body = b , type_comment = tc , type_params = t or [] , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset , ) ) if sys . version_info >= ( 3 , 12 ) else self . check_version ( ( 3 , 5 ) , "Async functions are" , ast . AsyncFunctionDef ( name = n . string , args = params or self . make_arguments ( None , [] , None , [] , None ) , returns = a , body = b , type_comment = tc , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset , ) ) ); - self._reset(mark) - return None; + if self.call_invalid_rules and (self.invalid_def_raw()): + return None # pragma: no cover + self._reset(mark) + if ( + (self.expect("def")) + and (n := self.name()) + and (t := self.type_params(),) + and (self.expect_forced(self.expect("("), "'('")) + and (params := self.params(),) + and (self.expect(")")) + and (a := self._tmp_68(),) + and (self.expect_forced(self.expect(":"), "':'")) + and (tc := self.func_type_comment(),) + and (b := self.block()) + ): + tok = self._tokenizer.get_last_non_whitespace_token() + end_lineno, end_col_offset = tok.end + return ( + ast.FunctionDef( + name=n.string, + args=params or self.make_arguments(None, [], None, [], None), + returns=a, + body=b, + type_comment=tc, + type_params=t or [], + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) + if sys.version_info >= (3, 12) + else ast.FunctionDef( + name=n.string, + args=params or self.make_arguments(None, [], None, [], None), + returns=a, + body=b, + type_comment=tc, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) + ) + self._reset(mark) + if ( + (self.expect("async")) + and (self.expect("def")) + and (n := self.name()) + and (t := self.type_params(),) + and (self.expect_forced(self.expect("("), "'('")) + and (params := self.params(),) + and (self.expect(")")) + and (a := self._tmp_69(),) + and (self.expect_forced(self.expect(":"), "':'")) + and (tc := self.func_type_comment(),) + and (b := self.block()) + ): + tok = self._tokenizer.get_last_non_whitespace_token() + end_lineno, end_col_offset = tok.end + return ( + self.check_version( + (3, 5), + "Async functions are", + ast.AsyncFunctionDef( + name=n.string, + args=params or self.make_arguments(None, [], None, [], None), + returns=a, + body=b, + type_comment=tc, + type_params=t or [], + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ), + ) + if sys.version_info >= (3, 12) + else self.check_version( + (3, 5), + "Async functions are", + ast.AsyncFunctionDef( + name=n.string, + args=params or self.make_arguments(None, [], None, [], None), + returns=a, + body=b, + type_comment=tc, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ), + ) + ) + self._reset(mark) + return None @memoize def params(self) -> Optional[Any]: # params: invalid_parameters | parameters mark = self._mark() - if ( - self.call_invalid_rules - and - (self.invalid_parameters()) - ): - return None # pragma: no cover; + if self.call_invalid_rules and (self.invalid_parameters()): + return None # pragma: no cover self._reset(mark) - if ( - (parameters := self.parameters()) - ): - return parameters; + if parameters := self.parameters(): + return parameters self._reset(mark) - return None; + return None @memoize - def parameters(self) -> Optional[ast . arguments]: + def parameters(self) -> Optional[ast.arguments]: # parameters: slash_no_default param_no_default* param_with_default* star_etc? | slash_with_default param_with_default* star_etc? | param_no_default+ param_with_default* star_etc? | param_with_default+ star_etc? | star_etc mark = self._mark() if ( (a := self.slash_no_default()) - and - (b := self._loop0_70(),) - and - (c := self._loop0_71(),) - and - (d := self.star_etc(),) + and (b := self._loop0_70(),) + and (c := self._loop0_71(),) + and (d := self.star_etc(),) ): - return self . check_version ( ( 3 , 8 ) , "Positional only arguments are" , self . make_arguments ( a , [] , b , c , d ) ); + return self.check_version( + (3, 8), + "Positional only arguments are", + self.make_arguments(a, [], b, c, d), + ) self._reset(mark) if ( (a := self.slash_with_default()) - and - (b := self._loop0_72(),) - and - (c := self.star_etc(),) + and (b := self._loop0_72(),) + and (c := self.star_etc(),) ): - return self . check_version ( ( 3 , 8 ) , "Positional only arguments are" , self . make_arguments ( None , a , None , b , c ) , ); + return self.check_version( + (3, 8), + "Positional only arguments are", + self.make_arguments(None, a, None, b, c), + ) self._reset(mark) if ( (a := self._loop1_73()) - and - (b := self._loop0_74(),) - and - (c := self.star_etc(),) + and (b := self._loop0_74(),) + and (c := self.star_etc(),) ): - return self . make_arguments ( None , [] , a , b , c ); + return self.make_arguments(None, [], a, b, c) self._reset(mark) - if ( - (a := self._loop1_75()) - and - (b := self.star_etc(),) - ): - return self . make_arguments ( None , [] , None , a , b ); + if (a := self._loop1_75()) and (b := self.star_etc(),): + return self.make_arguments(None, [], None, a, b) self._reset(mark) - if ( - (a := self.star_etc()) - ): - return self . make_arguments ( None , [] , None , None , a ); + if a := self.star_etc(): + return self.make_arguments(None, [], None, None, a) self._reset(mark) - return None; + return None @memoize - def slash_no_default(self) -> Optional[List [Tuple [ast . arg , None]]]: + def slash_no_default(self) -> Optional[List[Tuple[ast.arg, None]]]: # slash_no_default: param_no_default+ '/' ',' | param_no_default+ '/' &')' mark = self._mark() - if ( - (a := self._loop1_76()) - and - (self.expect('/')) - and - (self.expect(',')) - ): - return [( p , None ) for p in a]; + if (a := self._loop1_76()) and (self.expect("/")) and (self.expect(",")): + return [(p, None) for p in a] self._reset(mark) if ( (a := self._loop1_77()) - and - (self.expect('/')) - and - (self.positive_lookahead(self.expect, ')')) + and (self.expect("/")) + and (self.positive_lookahead(self.expect, ")")) ): - return [( p , None ) for p in a]; + return [(p, None) for p in a] self._reset(mark) - return None; + return None @memoize - def slash_with_default(self) -> Optional[List [Tuple [ast . arg , Any]]]: + def slash_with_default(self) -> Optional[List[Tuple[ast.arg, Any]]]: # slash_with_default: param_no_default* param_with_default+ '/' ',' | param_no_default* param_with_default+ '/' &')' mark = self._mark() if ( (a := self._loop0_78(),) - and - (b := self._loop1_79()) - and - (self.expect('/')) - and - (self.expect(',')) + and (b := self._loop1_79()) + and (self.expect("/")) + and (self.expect(",")) ): - return ( [( p , None ) for p in a] if a else [] ) + b; + return ([(p, None) for p in a] if a else []) + b self._reset(mark) if ( (a := self._loop0_80(),) - and - (b := self._loop1_81()) - and - (self.expect('/')) - and - (self.positive_lookahead(self.expect, ')')) + and (b := self._loop1_81()) + and (self.expect("/")) + and (self.positive_lookahead(self.expect, ")")) ): - return ( [( p , None ) for p in a] if a else [] ) + b; + return ([(p, None) for p in a] if a else []) + b self._reset(mark) - return None; + return None @memoize - def star_etc(self) -> Optional[Tuple [Optional [ast . arg] , List [Tuple [ast . arg , Any]] , Optional [ast . arg]]]: + def star_etc( + self, + ) -> Optional[ + Tuple[Optional[ast.arg], List[Tuple[ast.arg, Any]], Optional[ast.arg]] + ]: # star_etc: invalid_star_etc | '*' param_no_default param_maybe_default* kwds? | '*' param_no_default_star_annotation param_maybe_default* kwds? | '*' ',' param_maybe_default+ kwds? | kwds mark = self._mark() - if ( - self.call_invalid_rules - and - (self.invalid_star_etc()) - ): - return None # pragma: no cover; + if self.call_invalid_rules and (self.invalid_star_etc()): + return None # pragma: no cover self._reset(mark) if ( - (self.expect('*')) - and - (a := self.param_no_default()) - and - (b := self._loop0_82(),) - and - (c := self.kwds(),) + (self.expect("*")) + and (a := self.param_no_default()) + and (b := self._loop0_82(),) + and (c := self.kwds(),) ): - return ( a , b , c ); + return (a, b, c) self._reset(mark) if ( - (self.expect('*')) - and - (a := self.param_no_default_star_annotation()) - and - (b := self._loop0_83(),) - and - (c := self.kwds(),) + (self.expect("*")) + and (a := self.param_no_default_star_annotation()) + and (b := self._loop0_83(),) + and (c := self.kwds(),) ): - return ( a , b , c ); + return (a, b, c) self._reset(mark) if ( - (self.expect('*')) - and - (self.expect(',')) - and - (b := self._loop1_84()) - and - (c := self.kwds(),) + (self.expect("*")) + and (self.expect(",")) + and (b := self._loop1_84()) + and (c := self.kwds(),) ): - return ( None , b , c ); + return (None, b, c) self._reset(mark) - if ( - (a := self.kwds()) - ): - return ( None , [] , a ); + if a := self.kwds(): + return (None, [], a) self._reset(mark) - return None; + return None @memoize - def kwds(self) -> Optional[ast . arg]: + def kwds(self) -> Optional[ast.arg]: # kwds: invalid_kwds | '**' param_no_default mark = self._mark() - if ( - self.call_invalid_rules - and - (self.invalid_kwds()) - ): - return None # pragma: no cover; + if self.call_invalid_rules and (self.invalid_kwds()): + return None # pragma: no cover self._reset(mark) - if ( - (self.expect('**')) - and - (a := self.param_no_default()) - ): - return a; + if (self.expect("**")) and (a := self.param_no_default()): + return a self._reset(mark) - return None; + return None @memoize - def param_no_default(self) -> Optional[ast . arg]: + def param_no_default(self) -> Optional[ast.arg]: # param_no_default: param ',' TYPE_COMMENT? | param TYPE_COMMENT? &')' mark = self._mark() - if ( - (a := self.param()) - and - (self.expect(',')) - and - (tc := self.type_comment(),) - ): - return self . set_arg_type_comment ( a , tc ); + if (a := self.param()) and (self.expect(",")) and (tc := self.type_comment(),): + return self.set_arg_type_comment(a, tc) self._reset(mark) if ( (a := self.param()) - and - (tc := self.type_comment(),) - and - (self.positive_lookahead(self.expect, ')')) + and (tc := self.type_comment(),) + and (self.positive_lookahead(self.expect, ")")) ): - return self . set_arg_type_comment ( a , tc ); + return self.set_arg_type_comment(a, tc) self._reset(mark) - return None; + return None @memoize - def param_no_default_star_annotation(self) -> Optional[ast . arg]: + def param_no_default_star_annotation(self) -> Optional[ast.arg]: # param_no_default_star_annotation: param_star_annotation ',' TYPE_COMMENT? | param_star_annotation TYPE_COMMENT? &')' mark = self._mark() if ( (a := self.param_star_annotation()) - and - (self.expect(',')) - and - (tc := self.type_comment(),) + and (self.expect(",")) + and (tc := self.type_comment(),) ): - return self . set_arg_type_comment ( a , tc ); + return self.set_arg_type_comment(a, tc) self._reset(mark) if ( (a := self.param_star_annotation()) - and - (tc := self.type_comment(),) - and - (self.positive_lookahead(self.expect, ')')) + and (tc := self.type_comment(),) + and (self.positive_lookahead(self.expect, ")")) ): - return self . set_arg_type_comment ( a , tc ); + return self.set_arg_type_comment(a, tc) self._reset(mark) - return None; + return None @memoize - def param_with_default(self) -> Optional[Tuple [ast . arg , Any]]: + def param_with_default(self) -> Optional[Tuple[ast.arg, Any]]: # param_with_default: param default ',' TYPE_COMMENT? | param default TYPE_COMMENT? &')' mark = self._mark() if ( (a := self.param()) - and - (c := self.default()) - and - (self.expect(',')) - and - (tc := self.type_comment(),) + and (c := self.default()) + and (self.expect(",")) + and (tc := self.type_comment(),) ): - return ( self . set_arg_type_comment ( a , tc ) , c ); + return (self.set_arg_type_comment(a, tc), c) self._reset(mark) if ( (a := self.param()) - and - (c := self.default()) - and - (tc := self.type_comment(),) - and - (self.positive_lookahead(self.expect, ')')) + and (c := self.default()) + and (tc := self.type_comment(),) + and (self.positive_lookahead(self.expect, ")")) ): - return ( self . set_arg_type_comment ( a , tc ) , c ); + return (self.set_arg_type_comment(a, tc), c) self._reset(mark) - return None; + return None @memoize - def param_maybe_default(self) -> Optional[Tuple [ast . arg , Any]]: + def param_maybe_default(self) -> Optional[Tuple[ast.arg, Any]]: # param_maybe_default: param default? ',' TYPE_COMMENT? | param default? TYPE_COMMENT? &')' mark = self._mark() if ( (a := self.param()) - and - (c := self.default(),) - and - (self.expect(',')) - and - (tc := self.type_comment(),) + and (c := self.default(),) + and (self.expect(",")) + and (tc := self.type_comment(),) ): - return ( self . set_arg_type_comment ( a , tc ) , c ); + return (self.set_arg_type_comment(a, tc), c) self._reset(mark) if ( (a := self.param()) - and - (c := self.default(),) - and - (tc := self.type_comment(),) - and - (self.positive_lookahead(self.expect, ')')) + and (c := self.default(),) + and (tc := self.type_comment(),) + and (self.positive_lookahead(self.expect, ")")) ): - return ( self . set_arg_type_comment ( a , tc ) , c ); + return (self.set_arg_type_comment(a, tc), c) self._reset(mark) - return None; + return None @memoize def param(self) -> Optional[Any]: @@ -2258,16 +2443,19 @@ def param(self) -> Optional[Any]: mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - (a := self.name()) - and - (b := self.annotation(),) - ): + if (a := self.name()) and (b := self.annotation(),): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . arg ( arg = a . string , annotation = b , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.arg( + arg=a.string, + annotation=b, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - return None; + return None @memoize def param_star_annotation(self) -> Optional[Any]: @@ -2275,574 +2463,623 @@ def param_star_annotation(self) -> Optional[Any]: mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - (a := self.name()) - and - (b := self.star_annotation()) - ): + if (a := self.name()) and (b := self.star_annotation()): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . arg ( arg = a . string , annotations = b , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.arg( + arg=a.string, + annotation=b, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - return None; + return None @memoize def annotation(self) -> Optional[Any]: # annotation: ':' expression mark = self._mark() - if ( - (self.expect(':')) - and - (a := self.expression()) - ): - return a; + if (self.expect(":")) and (a := self.expression()): + return a self._reset(mark) - return None; + return None @memoize def star_annotation(self) -> Optional[Any]: # star_annotation: ':' star_expression mark = self._mark() - if ( - (self.expect(':')) - and - (a := self.star_expression()) - ): - return a; + if (self.expect(":")) and (a := self.star_expression()): + return a self._reset(mark) - return None; + return None @memoize def default(self) -> Optional[Any]: # default: '=' expression | invalid_default mark = self._mark() - if ( - (self.expect('=')) - and - (a := self.expression()) - ): - return a; + if (self.expect("=")) and (a := self.expression()): + return a self._reset(mark) - if ( - self.call_invalid_rules - and - (self.invalid_default()) - ): - return None # pragma: no cover; + if self.call_invalid_rules and (self.invalid_default()): + return None # pragma: no cover self._reset(mark) - return None; + return None @memoize - def if_stmt(self) -> Optional[ast . If]: + def if_stmt(self) -> Optional[ast.If]: # if_stmt: invalid_if_stmt | 'if' named_expression ':' block elif_stmt | 'if' named_expression ':' block else_block? mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - self.call_invalid_rules - and - (self.invalid_if_stmt()) - ): - return None # pragma: no cover; + if self.call_invalid_rules and (self.invalid_if_stmt()): + return None # pragma: no cover self._reset(mark) if ( - (self.expect('if')) - and - (a := self.named_expression()) - and - (self.expect(':')) - and - (b := self.block()) - and - (c := self.elif_stmt()) + (self.expect("if")) + and (a := self.named_expression()) + and (self.expect(":")) + and (b := self.block()) + and (c := self.elif_stmt()) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . If ( test = a , body = b , orelse = c or [] , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.If( + test=a, + body=b, + orelse=c or [], + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) if ( - (self.expect('if')) - and - (a := self.named_expression()) - and - (self.expect(':')) - and - (b := self.block()) - and - (c := self.else_block(),) + (self.expect("if")) + and (a := self.named_expression()) + and (self.expect(":")) + and (b := self.block()) + and (c := self.else_block(),) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . If ( test = a , body = b , orelse = c or [] , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.If( + test=a, + body=b, + orelse=c or [], + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - return None; + return None @memoize - def elif_stmt(self) -> Optional[List [ast . If]]: + def elif_stmt(self) -> Optional[List[ast.If]]: # elif_stmt: invalid_elif_stmt | 'elif' named_expression ':' block elif_stmt | 'elif' named_expression ':' block else_block? mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - self.call_invalid_rules - and - (self.invalid_elif_stmt()) - ): - return None # pragma: no cover; + if self.call_invalid_rules and (self.invalid_elif_stmt()): + return None # pragma: no cover self._reset(mark) if ( - (self.expect('elif')) - and - (a := self.named_expression()) - and - (self.expect(':')) - and - (b := self.block()) - and - (c := self.elif_stmt()) + (self.expect("elif")) + and (a := self.named_expression()) + and (self.expect(":")) + and (b := self.block()) + and (c := self.elif_stmt()) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return [ast . If ( test = a , body = b , orelse = c , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset )]; + return [ + ast.If( + test=a, + body=b, + orelse=c, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) + ] self._reset(mark) if ( - (self.expect('elif')) - and - (a := self.named_expression()) - and - (self.expect(':')) - and - (b := self.block()) - and - (c := self.else_block(),) + (self.expect("elif")) + and (a := self.named_expression()) + and (self.expect(":")) + and (b := self.block()) + and (c := self.else_block(),) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return [ast . If ( test = a , body = b , orelse = c or [] , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset )]; + return [ + ast.If( + test=a, + body=b, + orelse=c or [], + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) + ] self._reset(mark) - return None; + return None @memoize def else_block(self) -> Optional[list]: # else_block: invalid_else_stmt | 'else' &&':' block mark = self._mark() - if ( - self.call_invalid_rules - and - (self.invalid_else_stmt()) - ): - return None # pragma: no cover; + if self.call_invalid_rules and (self.invalid_else_stmt()): + return None # pragma: no cover self._reset(mark) if ( - (self.expect('else')) - and - (self.expect_forced(self.expect(':'), "':'")) - and - (b := self.block()) + (self.expect("else")) + and (self.expect_forced(self.expect(":"), "':'")) + and (b := self.block()) ): - return b; + return b self._reset(mark) - return None; + return None @memoize - def while_stmt(self) -> Optional[ast . While]: + def while_stmt(self) -> Optional[ast.While]: # while_stmt: invalid_while_stmt | 'while' named_expression ':' block else_block? mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - self.call_invalid_rules - and - (self.invalid_while_stmt()) - ): - return None # pragma: no cover; + if self.call_invalid_rules and (self.invalid_while_stmt()): + return None # pragma: no cover self._reset(mark) if ( - (self.expect('while')) - and - (a := self.named_expression()) - and - (self.expect(':')) - and - (b := self.block()) - and - (c := self.else_block(),) + (self.expect("while")) + and (a := self.named_expression()) + and (self.expect(":")) + and (b := self.block()) + and (c := self.else_block(),) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . While ( test = a , body = b , orelse = c or [] , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.While( + test=a, + body=b, + orelse=c or [], + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - return None; + return None @memoize - def for_stmt(self) -> Optional[Union [ast . For , ast . AsyncFor]]: + def for_stmt(self) -> Optional[Union[ast.For, ast.AsyncFor]]: # for_stmt: invalid_for_stmt | 'for' star_targets 'in' ~ star_expressions &&':' TYPE_COMMENT? block else_block? | 'async' 'for' star_targets 'in' ~ star_expressions ':' TYPE_COMMENT? block else_block? | invalid_for_target mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - self.call_invalid_rules - and - (self.invalid_for_stmt()) - ): - return None # pragma: no cover; + if self.call_invalid_rules and (self.invalid_for_stmt()): + return None # pragma: no cover self._reset(mark) cut = False if ( - (self.expect('for')) - and - (t := self.star_targets()) - and - (self.expect('in')) - and - (cut := True) - and - (ex := self.star_expressions()) - and - (self.expect_forced(self.expect(':'), "':'")) - and - (tc := self.type_comment(),) - and - (b := self.block()) - and - (el := self.else_block(),) - ): - tok = self._tokenizer.get_last_non_whitespace_token() - end_lineno, end_col_offset = tok.end - return ast . For ( target = t , iter = ex , body = b , orelse = el or [] , type_comment = tc , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + (self.expect("for")) + and (t := self.star_targets()) + and (self.expect("in")) + and (cut := True) + and (ex := self.star_expressions()) + and (self.expect_forced(self.expect(":"), "':'")) + and (tc := self.type_comment(),) + and (b := self.block()) + and (el := self.else_block(),) + ): + tok = self._tokenizer.get_last_non_whitespace_token() + end_lineno, end_col_offset = tok.end + return ast.For( + target=t, + iter=ex, + body=b, + orelse=el or [], + type_comment=tc, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) if cut: - return None; + return None cut = False if ( - (self.expect('async')) - and - (self.expect('for')) - and - (t := self.star_targets()) - and - (self.expect('in')) - and - (cut := True) - and - (ex := self.star_expressions()) - and - (self.expect(':')) - and - (tc := self.type_comment(),) - and - (b := self.block()) - and - (el := self.else_block(),) - ): - tok = self._tokenizer.get_last_non_whitespace_token() - end_lineno, end_col_offset = tok.end - return self . check_version ( ( 3 , 5 ) , "Async for loops are" , ast . AsyncFor ( target = t , iter = ex , body = b , orelse = el or [] , type_comment = tc , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ) ); + (self.expect("async")) + and (self.expect("for")) + and (t := self.star_targets()) + and (self.expect("in")) + and (cut := True) + and (ex := self.star_expressions()) + and (self.expect(":")) + and (tc := self.type_comment(),) + and (b := self.block()) + and (el := self.else_block(),) + ): + tok = self._tokenizer.get_last_non_whitespace_token() + end_lineno, end_col_offset = tok.end + return self.check_version( + (3, 5), + "Async for loops are", + ast.AsyncFor( + target=t, + iter=ex, + body=b, + orelse=el or [], + type_comment=tc, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ), + ) self._reset(mark) if cut: - return None; - if ( - self.call_invalid_rules - and - (self.invalid_for_target()) - ): - return None # pragma: no cover; + return None + if self.call_invalid_rules and (self.invalid_for_target()): + return None # pragma: no cover self._reset(mark) - return None; + return None @memoize - def with_stmt(self) -> Optional[Union [ast . With , ast . AsyncWith]]: + def with_stmt(self) -> Optional[Union[ast.With, ast.AsyncWith]]: # with_stmt: invalid_with_stmt_indent | 'with' '(' ','.with_item+ ','? ')' ':' block | 'with' ','.with_item+ ':' TYPE_COMMENT? block | 'async' 'with' '(' ','.with_item+ ','? ')' ':' block | 'async' 'with' ','.with_item+ ':' TYPE_COMMENT? block | invalid_with_stmt mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - self.call_invalid_rules - and - (self.invalid_with_stmt_indent()) - ): - return None # pragma: no cover; - self._reset(mark) - if ( - (self.expect('with')) - and - (self.expect('(')) - and - (a := self._gather_85()) - and - (self.expect(','),) - and - (self.expect(')')) - and - (self.expect(':')) - and - (b := self.block()) - ): - tok = self._tokenizer.get_last_non_whitespace_token() - end_lineno, end_col_offset = tok.end - return self . check_version ( ( 3 , 9 ) , "Parenthesized with items" , ast . With ( items = a , body = b , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ) ); - self._reset(mark) - if ( - (self.expect('with')) - and - (a := self._gather_87()) - and - (self.expect(':')) - and - (tc := self.type_comment(),) - and - (b := self.block()) - ): - tok = self._tokenizer.get_last_non_whitespace_token() - end_lineno, end_col_offset = tok.end - return ast . With ( items = a , body = b , type_comment = tc , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); - self._reset(mark) - if ( - (self.expect('async')) - and - (self.expect('with')) - and - (self.expect('(')) - and - (a := self._gather_89()) - and - (self.expect(','),) - and - (self.expect(')')) - and - (self.expect(':')) - and - (b := self.block()) - ): - tok = self._tokenizer.get_last_non_whitespace_token() - end_lineno, end_col_offset = tok.end - return self . check_version ( ( 3 , 9 ) , "Parenthesized with items" , ast . AsyncWith ( items = a , body = b , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ) ); - self._reset(mark) - if ( - (self.expect('async')) - and - (self.expect('with')) - and - (a := self._gather_91()) - and - (self.expect(':')) - and - (tc := self.type_comment(),) - and - (b := self.block()) - ): - tok = self._tokenizer.get_last_non_whitespace_token() - end_lineno, end_col_offset = tok.end - return self . check_version ( ( 3 , 5 ) , "Async with statements are" , ast . AsyncWith ( items = a , body = b , type_comment = tc , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ) ); - self._reset(mark) - if ( - self.call_invalid_rules - and - (self.invalid_with_stmt()) - ): - return None # pragma: no cover; - self._reset(mark) - return None; - - @memoize - def with_item(self) -> Optional[ast . withitem]: + if self.call_invalid_rules and (self.invalid_with_stmt_indent()): + return None # pragma: no cover + self._reset(mark) + if ( + (self.expect("with")) + and (self.expect("(")) + and (a := self._gather_85()) + and (self.expect(","),) + and (self.expect(")")) + and (self.expect(":")) + and (b := self.block()) + ): + tok = self._tokenizer.get_last_non_whitespace_token() + end_lineno, end_col_offset = tok.end + return self.check_version( + (3, 9), + "Parenthesized with items", + ast.With( + items=a, + body=b, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ), + ) + self._reset(mark) + if ( + (self.expect("with")) + and (a := self._gather_87()) + and (self.expect(":")) + and (tc := self.type_comment(),) + and (b := self.block()) + ): + tok = self._tokenizer.get_last_non_whitespace_token() + end_lineno, end_col_offset = tok.end + return ast.With( + items=a, + body=b, + type_comment=tc, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) + self._reset(mark) + if ( + (self.expect("async")) + and (self.expect("with")) + and (self.expect("(")) + and (a := self._gather_89()) + and (self.expect(","),) + and (self.expect(")")) + and (self.expect(":")) + and (b := self.block()) + ): + tok = self._tokenizer.get_last_non_whitespace_token() + end_lineno, end_col_offset = tok.end + return self.check_version( + (3, 9), + "Parenthesized with items", + ast.AsyncWith( + items=a, + body=b, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ), + ) + self._reset(mark) + if ( + (self.expect("async")) + and (self.expect("with")) + and (a := self._gather_91()) + and (self.expect(":")) + and (tc := self.type_comment(),) + and (b := self.block()) + ): + tok = self._tokenizer.get_last_non_whitespace_token() + end_lineno, end_col_offset = tok.end + return self.check_version( + (3, 5), + "Async with statements are", + ast.AsyncWith( + items=a, + body=b, + type_comment=tc, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ), + ) + self._reset(mark) + if self.call_invalid_rules and (self.invalid_with_stmt()): + return None # pragma: no cover + self._reset(mark) + return None + + @memoize + def with_item(self) -> Optional[ast.withitem]: # with_item: expression 'as' star_target &(',' | ')' | ':') | invalid_with_item | expression mark = self._mark() if ( (e := self.expression()) - and - (self.expect('as')) - and - (t := self.star_target()) - and - (self.positive_lookahead(self._tmp_93, )) + and (self.expect("as")) + and (t := self.star_target()) + and ( + self.positive_lookahead( + self._tmp_93, + ) + ) ): - return ast . withitem ( context_expr = e , optional_vars = t ); + return ast.withitem(context_expr=e, optional_vars=t) self._reset(mark) - if ( - self.call_invalid_rules - and - (self.invalid_with_item()) - ): - return None # pragma: no cover; + if self.call_invalid_rules and (self.invalid_with_item()): + return None # pragma: no cover self._reset(mark) - if ( - (e := self.expression()) - ): - return ast . withitem ( context_expr = e , optional_vars = None ); + if e := self.expression(): + return ast.withitem(context_expr=e, optional_vars=None) self._reset(mark) - return None; + return None @memoize - def try_stmt(self) -> Optional[ast . Try]: + def try_stmt(self) -> Optional[ast.Try]: # try_stmt: invalid_try_stmt | 'try' &&':' block finally_block | 'try' &&':' block except_block+ else_block? finally_block? | 'try' &&':' block except_star_block+ else_block? finally_block? mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - self.call_invalid_rules - and - (self.invalid_try_stmt()) - ): - return None # pragma: no cover; + if self.call_invalid_rules and (self.invalid_try_stmt()): + return None # pragma: no cover self._reset(mark) if ( - (self.expect('try')) - and - (self.expect_forced(self.expect(':'), "':'")) - and - (b := self.block()) - and - (f := self.finally_block()) + (self.expect("try")) + and (self.expect_forced(self.expect(":"), "':'")) + and (b := self.block()) + and (f := self.finally_block()) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . Try ( body = b , handlers = [] , orelse = [] , finalbody = f , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.Try( + body=b, + handlers=[], + orelse=[], + finalbody=f, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) if ( - (self.expect('try')) - and - (self.expect_forced(self.expect(':'), "':'")) - and - (b := self.block()) - and - (ex := self._loop1_94()) - and - (el := self.else_block(),) - and - (f := self.finally_block(),) + (self.expect("try")) + and (self.expect_forced(self.expect(":"), "':'")) + and (b := self.block()) + and (ex := self._loop1_94()) + and (el := self.else_block(),) + and (f := self.finally_block(),) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . Try ( body = b , handlers = ex , orelse = el or [] , finalbody = f or [] , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.Try( + body=b, + handlers=ex, + orelse=el or [], + finalbody=f or [], + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) if ( - (self.expect('try')) - and - (self.expect_forced(self.expect(':'), "':'")) - and - (b := self.block()) - and - (ex := self._loop1_95()) - and - (el := self.else_block(),) - and - (f := self.finally_block(),) + (self.expect("try")) + and (self.expect_forced(self.expect(":"), "':'")) + and (b := self.block()) + and (ex := self._loop1_95()) + and (el := self.else_block(),) + and (f := self.finally_block(),) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return self . check_version ( ( 3 , 11 ) , "Exception groups are" , ( ast . TryStar ( body = b , handlers = ex , orelse = el or [] , finalbody = f or [] , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ) if sys . version_info >= ( 3 , 11 ) else None ) ); + return self.check_version( + (3, 11), + "Exception groups are", + ( + ast.TryStar( + body=b, + handlers=ex, + orelse=el or [], + finalbody=f or [], + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) + if sys.version_info >= (3, 11) + else None + ), + ) self._reset(mark) - return None; + return None @memoize - def except_block(self) -> Optional[ast . ExceptHandler]: - # except_block: invalid_except_stmt_indent | 'except' expression ['as' NAME] ':' block | 'except' ':' block | invalid_except_stmt + def except_block(self) -> Optional[ast.ExceptHandler]: + # except_block: invalid_except_stmt_indent | invalid_except_stmt | 'except' expression ['as' NAME] ':' block | 'except' ':' block | 'except' expressions ':' block mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - self.call_invalid_rules - and - (self.invalid_except_stmt_indent()) - ): - return None # pragma: no cover; + if self.call_invalid_rules and (self.invalid_except_stmt_indent()): + return None # pragma: no cover + self._reset(mark) + if self.call_invalid_rules and (self.invalid_except_stmt()): + return None # pragma: no cover self._reset(mark) if ( - (self.expect('except')) - and - (e := self.expression()) - and - (t := self._tmp_96(),) - and - (self.expect(':')) - and - (b := self.block()) + (self.expect("except")) + and (e := self.expression()) + and (t := self._tmp_96(),) + and (self.expect(":")) + and (b := self.block()) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . ExceptHandler ( type = e , name = t , body = b , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.ExceptHandler( + type=e, + name=t, + body=b, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - if ( - (self.expect('except')) - and - (self.expect(':')) - and - (b := self.block()) - ): + if (self.expect("except")) and (self.expect(":")) and (b := self.block()): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . ExceptHandler ( type = None , name = None , body = b , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.ExceptHandler( + type=None, + name=None, + body=b, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) if ( - self.call_invalid_rules - and - (self.invalid_except_stmt()) + (self.expect("except")) + and (e := self.expressions()) + and (self.expect(":")) + and (b := self.block()) ): - return None # pragma: no cover; + tok = self._tokenizer.get_last_non_whitespace_token() + end_lineno, end_col_offset = tok.end + return ( + ast.ExceptHandler( + type=e, + name=None, + body=b, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) + if self.py_version >= (3, 14) + else None + ) self._reset(mark) - return None; + return None @memoize - def except_star_block(self) -> Optional[ast . ExceptHandler]: - # except_star_block: invalid_except_star_stmt_indent | 'except' '*' expression ['as' NAME] ':' block | invalid_except_stmt + def except_star_block(self) -> Optional[ast.ExceptHandler]: + # except_star_block: invalid_except_star_stmt_indent | invalid_except_stmt | 'except' '*' expression ['as' NAME] ':' block | 'except' '*' expressions ':' block mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - self.call_invalid_rules - and - (self.invalid_except_star_stmt_indent()) - ): - return None # pragma: no cover; + if self.call_invalid_rules and (self.invalid_except_star_stmt_indent()): + return None # pragma: no cover + self._reset(mark) + if self.call_invalid_rules and (self.invalid_except_stmt()): + return None # pragma: no cover self._reset(mark) if ( - (self.expect('except')) - and - (self.expect('*')) - and - (e := self.expression()) - and - (t := self._tmp_97(),) - and - (self.expect(':')) - and - (b := self.block()) + (self.expect("except")) + and (self.expect("*")) + and (e := self.expression()) + and (t := self._tmp_97(),) + and (self.expect(":")) + and (b := self.block()) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . ExceptHandler ( type = e , name = t , body = b , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.ExceptHandler( + type=e, + name=t, + body=b, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) if ( - self.call_invalid_rules - and - (self.invalid_except_stmt()) + (self.expect("except")) + and (self.expect("*")) + and (e := self.expressions()) + and (self.expect(":")) + and (b := self.block()) ): - return None # pragma: no cover; + tok = self._tokenizer.get_last_non_whitespace_token() + end_lineno, end_col_offset = tok.end + return ( + ast.ExceptHandler( + type=e, + name=None, + body=b, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) + if self.py_version >= (3, 14) + else None + ) self._reset(mark) - return None; + return None @memoize def finally_block(self) -> Optional[list]: # finally_block: invalid_finally_stmt | 'finally' &&':' block mark = self._mark() - if ( - self.call_invalid_rules - and - (self.invalid_finally_stmt()) - ): - return None # pragma: no cover; + if self.call_invalid_rules and (self.invalid_finally_stmt()): + return None # pragma: no cover self._reset(mark) if ( - (self.expect('finally')) - and - (self.expect_forced(self.expect(':'), "':'")) - and - (a := self.block()) + (self.expect("finally")) + and (self.expect_forced(self.expect(":"), "':'")) + and (a := self.block()) ): - return a; + return a self._reset(mark) - return None; + return None @memoize def match_stmt(self) -> Optional["ast.Match"]: @@ -2852,31 +3089,28 @@ def match_stmt(self) -> Optional["ast.Match"]: start_lineno, start_col_offset = tok.start if ( (self.expect("match")) - and - (subject := self.subject_expr()) - and - (self.expect(':')) - and - (self.expect('NEWLINE')) - and - (self.expect('INDENT')) - and - (cases := self._loop1_98()) - and - (self.expect('DEDENT')) + and (subject := self.subject_expr()) + and (self.expect(":")) + and (self.expect("NEWLINE")) + and (self.expect("INDENT")) + and (cases := self._loop1_98()) + and (self.expect("DEDENT")) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . Match ( subject = subject , cases = cases , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.Match( + subject=subject, + cases=cases, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - if ( - self.call_invalid_rules - and - (self.invalid_match_stmt()) - ): - return None # pragma: no cover; + if self.call_invalid_rules and (self.invalid_match_stmt()): + return None # pragma: no cover self._reset(mark) - return None; + return None @memoize def subject_expr(self) -> Optional[Any]: @@ -2886,60 +3120,55 @@ def subject_expr(self) -> Optional[Any]: start_lineno, start_col_offset = tok.start if ( (value := self.star_named_expression()) - and - (self.expect(',')) - and - (values := self.star_named_expressions(),) + and (self.expect(",")) + and (values := self.star_named_expressions(),) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return self . check_version ( ( 3 , 10 ) , "Pattern matching is" , ast . Tuple ( elts = [value] + ( values or [] ) , ctx = Load , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ) ); + return self.check_version( + (3, 10), + "Pattern matching is", + ast.Tuple( + elts=[value] + (values or []), + ctx=Load, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ), + ) self._reset(mark) - if ( - (e := self.named_expression()) - ): - return self . check_version ( ( 3 , 10 ) , "Pattern matching is" , e ); + if e := self.named_expression(): + return self.check_version((3, 10), "Pattern matching is", e) self._reset(mark) - return None; + return None @memoize def case_block(self) -> Optional["ast.match_case"]: # case_block: invalid_case_block | "case" patterns guard? ':' block mark = self._mark() - if ( - self.call_invalid_rules - and - (self.invalid_case_block()) - ): - return None # pragma: no cover; + if self.call_invalid_rules and (self.invalid_case_block()): + return None # pragma: no cover self._reset(mark) if ( (self.expect("case")) - and - (pattern := self.patterns()) - and - (guard := self.guard(),) - and - (self.expect(':')) - and - (body := self.block()) + and (pattern := self.patterns()) + and (guard := self.guard(),) + and (self.expect(":")) + and (body := self.block()) ): - return ast . match_case ( pattern = pattern , guard = guard , body = body ); + return ast.match_case(pattern=pattern, guard=guard, body=body) self._reset(mark) - return None; + return None @memoize def guard(self) -> Optional[Any]: # guard: 'if' named_expression mark = self._mark() - if ( - (self.expect('if')) - and - (guard := self.named_expression()) - ): - return guard; + if (self.expect("if")) and (guard := self.named_expression()): + return guard self._reset(mark) - return None; + return None @memoize def patterns(self) -> Optional[Any]: @@ -2947,35 +3176,33 @@ def patterns(self) -> Optional[Any]: mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - (patterns := self.open_sequence_pattern()) - ): + if patterns := self.open_sequence_pattern(): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . MatchSequence ( patterns = patterns , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.MatchSequence( + patterns=patterns, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - if ( - (pattern := self.pattern()) - ): - return pattern; + if pattern := self.pattern(): + return pattern self._reset(mark) - return None; + return None @memoize def pattern(self) -> Optional[Any]: # pattern: as_pattern | or_pattern mark = self._mark() - if ( - (as_pattern := self.as_pattern()) - ): - return as_pattern; + if as_pattern := self.as_pattern(): + return as_pattern self._reset(mark) - if ( - (or_pattern := self.or_pattern()) - ): - return or_pattern; + if or_pattern := self.or_pattern(): + return or_pattern self._reset(mark) - return None; + return None @memoize def as_pattern(self) -> Optional["ast.MatchAs"]: @@ -2985,23 +3212,32 @@ def as_pattern(self) -> Optional["ast.MatchAs"]: start_lineno, start_col_offset = tok.start if ( (pattern := self.or_pattern()) - and - (self.expect('as')) - and - (target := self.pattern_capture_target()) + and (self.expect("as")) + and (target := self.pattern_capture_target()) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . MatchAs ( pattern = pattern , name = target , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ( + self.raise_syntax_error_known_location( + "cannot use '_' as a target", pattern + ) + if isinstance(pattern, ast.MatchAs) + and pattern.pattern is None + and pattern.name is None + else ast.MatchAs( + pattern=pattern, + name=target, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) + ) self._reset(mark) - if ( - self.call_invalid_rules - and - (self.invalid_as_pattern()) - ): - return None # pragma: no cover; + if self.call_invalid_rules and (self.invalid_as_pattern()): + return None # pragma: no cover self._reset(mark) - return None; + return None @memoize def or_pattern(self) -> Optional["ast.MatchOr"]: @@ -3009,60 +3245,52 @@ def or_pattern(self) -> Optional["ast.MatchOr"]: mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - (patterns := self._gather_99()) - ): + if patterns := self._gather_99(): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . MatchOr ( patterns = patterns , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ) if len ( patterns ) > 1 else patterns [0]; + return ( + ast.MatchOr( + patterns=patterns, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) + if len(patterns) > 1 + else patterns[0] + ) self._reset(mark) - return None; + return None @memoize def closed_pattern(self) -> Optional[Any]: # closed_pattern: literal_pattern | capture_pattern | wildcard_pattern | value_pattern | group_pattern | sequence_pattern | mapping_pattern | class_pattern mark = self._mark() - if ( - (literal_pattern := self.literal_pattern()) - ): - return literal_pattern; + if literal_pattern := self.literal_pattern(): + return literal_pattern self._reset(mark) - if ( - (capture_pattern := self.capture_pattern()) - ): - return capture_pattern; + if capture_pattern := self.capture_pattern(): + return capture_pattern self._reset(mark) - if ( - (wildcard_pattern := self.wildcard_pattern()) - ): - return wildcard_pattern; + if wildcard_pattern := self.wildcard_pattern(): + return wildcard_pattern self._reset(mark) - if ( - (value_pattern := self.value_pattern()) - ): - return value_pattern; + if value_pattern := self.value_pattern(): + return value_pattern self._reset(mark) - if ( - (group_pattern := self.group_pattern()) - ): - return group_pattern; + if group_pattern := self.group_pattern(): + return group_pattern self._reset(mark) - if ( - (sequence_pattern := self.sequence_pattern()) - ): - return sequence_pattern; + if sequence_pattern := self.sequence_pattern(): + return sequence_pattern self._reset(mark) - if ( - (mapping_pattern := self.mapping_pattern()) - ): - return mapping_pattern; + if mapping_pattern := self.mapping_pattern(): + return mapping_pattern self._reset(mark) - if ( - (class_pattern := self.class_pattern()) - ): - return class_pattern; + if class_pattern := self.class_pattern(): + return class_pattern self._reset(mark) - return None; + return None @memoize def literal_pattern(self) -> Optional[Any]: @@ -3070,51 +3298,77 @@ def literal_pattern(self) -> Optional[Any]: mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - (value := self.signed_number()) - and - (self.negative_lookahead(self._tmp_101, )) + if (value := self.signed_number()) and ( + self.negative_lookahead( + self._tmp_101, + ) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . MatchValue ( value = value , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.MatchValue( + value=value, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - if ( - (value := self.complex_number()) - ): + if value := self.complex_number(): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . MatchValue ( value = value , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.MatchValue( + value=value, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - if ( - (value := self.strings()) - ): + if value := self.strings(): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . MatchValue ( value = value , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.MatchValue( + value=value, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - if ( - (self.expect('None')) - ): + if self.expect("None"): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . MatchSingleton ( value = None , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.MatchSingleton( + value=None, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - if ( - (self.expect('True')) - ): + if self.expect("True"): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . MatchSingleton ( value = True , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.MatchSingleton( + value=True, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - if ( - (self.expect('False')) - ): + if self.expect("False"): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . MatchSingleton ( value = False , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.MatchSingleton( + value=False, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - return None; + return None @memoize def literal_expr(self) -> Optional[Any]: @@ -3122,45 +3376,53 @@ def literal_expr(self) -> Optional[Any]: mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - (signed_number := self.signed_number()) - and - (self.negative_lookahead(self._tmp_102, )) + if (signed_number := self.signed_number()) and ( + self.negative_lookahead( + self._tmp_102, + ) ): - return signed_number; + return signed_number self._reset(mark) - if ( - (complex_number := self.complex_number()) - ): - return complex_number; + if complex_number := self.complex_number(): + return complex_number self._reset(mark) - if ( - (strings := self.strings()) - ): - return strings; + if strings := self.strings(): + return strings self._reset(mark) - if ( - (self.expect('None')) - ): + if self.expect("None"): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . Constant ( value = None , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.Constant( + value=None, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - if ( - (self.expect('True')) - ): + if self.expect("True"): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . Constant ( value = True , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.Constant( + value=True, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - if ( - (self.expect('False')) - ): + if self.expect("False"): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . Constant ( value = False , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.Constant( + value=False, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - return None; + return None @memoize def complex_number(self) -> Optional[Any]: @@ -3170,27 +3432,39 @@ def complex_number(self) -> Optional[Any]: start_lineno, start_col_offset = tok.start if ( (real := self.signed_real_number()) - and - (self.expect('+')) - and - (imag := self.imaginary_number()) + and (self.expect("+")) + and (imag := self.imaginary_number()) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . BinOp ( left = real , op = ast . Add ( ) , right = imag , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.BinOp( + left=real, + op=ast.Add(), + right=imag, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) if ( (real := self.signed_real_number()) - and - (self.expect('-')) - and - (imag := self.imaginary_number()) + and (self.expect("-")) + and (imag := self.imaginary_number()) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . BinOp ( left = real , op = ast . Sub ( ) , right = imag , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.BinOp( + left=real, + op=ast.Sub(), + right=imag, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - return None; + return None @memoize def signed_number(self) -> Optional[Any]: @@ -3198,23 +3472,36 @@ def signed_number(self) -> Optional[Any]: mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - (a := self.number()) - ): + if a := self.number(): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . Constant ( value = ast . literal_eval ( a . string ) , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.Constant( + value=ast.literal_eval(a.string), + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - if ( - (self.expect('-')) - and - (a := self.number()) - ): + if (self.expect("-")) and (a := self.number()): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . UnaryOp ( op = ast . USub ( ) , operand = ast . Constant ( value = ast . literal_eval ( a . string ) , lineno = a . start [0] , col_offset = a . start [1] , end_lineno = a . end [0] , end_col_offset = a . end [1] ) , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset , ); + return ast.UnaryOp( + op=ast.USub(), + operand=ast.Constant( + value=ast.literal_eval(a.string), + lineno=a.start[0], + col_offset=a.start[1], + end_lineno=a.end[0], + end_col_offset=a.end[1], + ), + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - return None; + return None @memoize def signed_real_number(self) -> Optional[Any]: @@ -3222,51 +3509,60 @@ def signed_real_number(self) -> Optional[Any]: mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - (real_number := self.real_number()) - ): - return real_number; + if real_number := self.real_number(): + return real_number self._reset(mark) - if ( - (self.expect('-')) - and - (real := self.real_number()) - ): + if (self.expect("-")) and (real := self.real_number()): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . UnaryOp ( op = ast . USub ( ) , operand = real , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.UnaryOp( + op=ast.USub(), + operand=real, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - return None; + return None @memoize - def real_number(self) -> Optional[ast . Constant]: + def real_number(self) -> Optional[ast.Constant]: # real_number: NUMBER mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - (real := self.number()) - ): + if real := self.number(): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . Constant ( value = self . ensure_real ( real ) , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.Constant( + value=self.ensure_real(real), + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - return None; + return None @memoize - def imaginary_number(self) -> Optional[ast . Constant]: + def imaginary_number(self) -> Optional[ast.Constant]: # imaginary_number: NUMBER mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - (imag := self.number()) - ): + if imag := self.number(): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . Constant ( value = self . ensure_imaginary ( imag ) , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.Constant( + value=self.ensure_imaginary(imag), + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - return None; + return None @memoize def capture_pattern(self) -> Optional[Any]: @@ -3274,14 +3570,19 @@ def capture_pattern(self) -> Optional[Any]: mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - (target := self.pattern_capture_target()) - ): + if target := self.pattern_capture_target(): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . MatchAs ( pattern = None , name = target , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.MatchAs( + pattern=None, + name=target, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - return None; + return None @memoize def pattern_capture_target(self) -> Optional[str]: @@ -3289,14 +3590,16 @@ def pattern_capture_target(self) -> Optional[str]: mark = self._mark() if ( (self.negative_lookahead(self.expect, "_")) - and - (name := self.name()) - and - (self.negative_lookahead(self._tmp_103, )) + and (name := self.name()) + and ( + self.negative_lookahead( + self._tmp_103, + ) + ) ): - return name . string; + return name.string self._reset(mark) - return None; + return None @memoize def wildcard_pattern(self) -> Optional["ast.MatchAs"]: @@ -3304,14 +3607,19 @@ def wildcard_pattern(self) -> Optional["ast.MatchAs"]: mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - (self.expect("_")) - ): + if self.expect("_"): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . MatchAs ( pattern = None , target = None , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.MatchAs( + pattern=None, + name=None, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - return None; + return None @memoize def value_pattern(self) -> Optional["ast.MatchValue"]: @@ -3319,35 +3627,47 @@ def value_pattern(self) -> Optional["ast.MatchValue"]: mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - (attr := self.attr()) - and - (self.negative_lookahead(self._tmp_104, )) + if (attr := self.attr()) and ( + self.negative_lookahead( + self._tmp_104, + ) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . MatchValue ( value = attr , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.MatchValue( + value=attr, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - return None; + return None @memoize_left_rec - def attr(self) -> Optional[ast . Attribute]: + def attr(self) -> Optional[ast.Attribute]: # attr: name_or_attr '.' NAME mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start if ( (value := self.name_or_attr()) - and - (self.expect('.')) - and - (attr := self.name()) + and (self.expect(".")) + and (attr := self.name()) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . Attribute ( value = value , attr = attr . string , ctx = Load , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.Attribute( + value=value, + attr=attr.string, + ctx=Load, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - return None; + return None @logger def name_or_attr(self) -> Optional[Any]: @@ -3355,34 +3675,31 @@ def name_or_attr(self) -> Optional[Any]: mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - (attr := self.attr()) - ): - return attr; + if attr := self.attr(): + return attr self._reset(mark) - if ( - (name := self.name()) - ): + if name := self.name(): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . Name ( id = name . string , ctx = Load , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.Name( + id=name.string, + ctx=Load, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - return None; + return None @memoize def group_pattern(self) -> Optional[Any]: # group_pattern: '(' pattern ')' mark = self._mark() - if ( - (self.expect('(')) - and - (pattern := self.pattern()) - and - (self.expect(')')) - ): - return pattern; + if (self.expect("(")) and (pattern := self.pattern()) and (self.expect(")")): + return pattern self._reset(mark) - return None; + return None @memoize def sequence_pattern(self) -> Optional["ast.MatchSequence"]: @@ -3391,28 +3708,36 @@ def sequence_pattern(self) -> Optional["ast.MatchSequence"]: tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start if ( - (self.expect('[')) - and - (patterns := self.maybe_sequence_pattern(),) - and - (self.expect(']')) + (self.expect("[")) + and (patterns := self.maybe_sequence_pattern(),) + and (self.expect("]")) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . MatchSequence ( patterns = patterns or [] , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.MatchSequence( + patterns=patterns or [], + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) if ( - (self.expect('(')) - and - (patterns := self.open_sequence_pattern(),) - and - (self.expect(')')) + (self.expect("(")) + and (patterns := self.open_sequence_pattern(),) + and (self.expect(")")) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . MatchSequence ( patterns = patterns or [] , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.MatchSequence( + patterns=patterns or [], + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - return None; + return None @memoize def open_sequence_pattern(self) -> Optional[Any]: @@ -3420,43 +3745,33 @@ def open_sequence_pattern(self) -> Optional[Any]: mark = self._mark() if ( (pattern := self.maybe_star_pattern()) - and - (self.expect(',')) - and - (patterns := self.maybe_sequence_pattern(),) + and (self.expect(",")) + and (patterns := self.maybe_sequence_pattern(),) ): - return [pattern] + ( patterns or [] ); + return [pattern] + (patterns or []) self._reset(mark) - return None; + return None @memoize def maybe_sequence_pattern(self) -> Optional[Any]: # maybe_sequence_pattern: ','.maybe_star_pattern+ ','? mark = self._mark() - if ( - (patterns := self._gather_105()) - and - (self.expect(','),) - ): - return patterns; + if (patterns := self._gather_105()) and (self.expect(","),): + return patterns self._reset(mark) - return None; + return None @memoize def maybe_star_pattern(self) -> Optional[Any]: # maybe_star_pattern: star_pattern | pattern mark = self._mark() - if ( - (star_pattern := self.star_pattern()) - ): - return star_pattern; + if star_pattern := self.star_pattern(): + return star_pattern self._reset(mark) - if ( - (pattern := self.pattern()) - ): - return pattern; + if pattern := self.pattern(): + return pattern self._reset(mark) - return None; + return None @memoize def star_pattern(self) -> Optional[Any]: @@ -3464,25 +3779,29 @@ def star_pattern(self) -> Optional[Any]: mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - (self.expect('*')) - and - (target := self.pattern_capture_target()) - ): + if (self.expect("*")) and (target := self.pattern_capture_target()): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . MatchStar ( name = target , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.MatchStar( + name=target, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - if ( - (self.expect('*')) - and - (self.wildcard_pattern()) - ): + if (self.expect("*")) and (self.wildcard_pattern()): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . MatchStar ( target = None , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.MatchStar( + target=None, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - return None; + return None @memoize def mapping_pattern(self) -> Optional[Any]: @@ -3490,70 +3809,85 @@ def mapping_pattern(self) -> Optional[Any]: mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - (self.expect('{')) - and - (self.expect('}')) - ): + if (self.expect("{")) and (self.expect("}")): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . MatchMapping ( keys = [] , patterns = [] , rest = None , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.MatchMapping( + keys=[], + patterns=[], + rest=None, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) if ( - (self.expect('{')) - and - (rest := self.double_star_pattern()) - and - (self.expect(','),) - and - (self.expect('}')) + (self.expect("{")) + and (rest := self.double_star_pattern()) + and (self.expect(","),) + and (self.expect("}")) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . MatchMapping ( keys = [] , patterns = [] , rest = rest , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.MatchMapping( + keys=[], + patterns=[], + rest=rest, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) if ( - (self.expect('{')) - and - (items := self.items_pattern()) - and - (self.expect(',')) - and - (rest := self.double_star_pattern()) - and - (self.expect(','),) - and - (self.expect('}')) + (self.expect("{")) + and (items := self.items_pattern()) + and (self.expect(",")) + and (rest := self.double_star_pattern()) + and (self.expect(","),) + and (self.expect("}")) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . MatchMapping ( keys = [k for k , _ in items] , patterns = [p for _ , p in items] , rest = rest , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset , ); + return ast.MatchMapping( + keys=[k for k, _ in items], + patterns=[p for _, p in items], + rest=rest, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) if ( - (self.expect('{')) - and - (items := self.items_pattern()) - and - (self.expect(','),) - and - (self.expect('}')) + (self.expect("{")) + and (items := self.items_pattern()) + and (self.expect(","),) + and (self.expect("}")) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . MatchMapping ( keys = [k for k , _ in items] , patterns = [p for _ , p in items] , rest = None , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset , ); + return ast.MatchMapping( + keys=[k for k, _ in items], + patterns=[p for _, p in items], + rest=None, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - return None; + return None @memoize def items_pattern(self) -> Optional[Any]: # items_pattern: ','.key_value_pattern+ mark = self._mark() - if ( - (_gather_107 := self._gather_107()) - ): - return _gather_107; + if _gather_107 := self._gather_107(): + return _gather_107 self._reset(mark) - return None; + return None @memoize def key_value_pattern(self) -> Optional[Any]: @@ -3561,27 +3895,21 @@ def key_value_pattern(self) -> Optional[Any]: mark = self._mark() if ( (key := self._tmp_109()) - and - (self.expect(':')) - and - (pattern := self.pattern()) + and (self.expect(":")) + and (pattern := self.pattern()) ): - return ( key , pattern ); + return (key, pattern) self._reset(mark) - return None; + return None @memoize def double_star_pattern(self) -> Optional[Any]: # double_star_pattern: '**' pattern_capture_target mark = self._mark() - if ( - (self.expect('**')) - and - (target := self.pattern_capture_target()) - ): - return target; + if (self.expect("**")) and (target := self.pattern_capture_target()): + return target self._reset(mark) - return None; + return None @memoize def class_pattern(self) -> Optional["ast.MatchClass"]: @@ -3589,111 +3917,113 @@ def class_pattern(self) -> Optional["ast.MatchClass"]: mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - (cls := self.name_or_attr()) - and - (self.expect('(')) - and - (self.expect(')')) - ): + if (cls := self.name_or_attr()) and (self.expect("(")) and (self.expect(")")): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . MatchClass ( cls = cls , patterns = [] , kwd_attrs = [] , kwd_patterns = [] , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.MatchClass( + cls=cls, + patterns=[], + kwd_attrs=[], + kwd_patterns=[], + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) if ( (cls := self.name_or_attr()) - and - (self.expect('(')) - and - (patterns := self.positional_patterns()) - and - (self.expect(','),) - and - (self.expect(')')) + and (self.expect("(")) + and (patterns := self.positional_patterns()) + and (self.expect(","),) + and (self.expect(")")) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . MatchClass ( cls = cls , patterns = patterns , kwd_attrs = [] , kwd_patterns = [] , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.MatchClass( + cls=cls, + patterns=patterns, + kwd_attrs=[], + kwd_patterns=[], + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) if ( (cls := self.name_or_attr()) - and - (self.expect('(')) - and - (keywords := self.keyword_patterns()) - and - (self.expect(','),) - and - (self.expect(')')) + and (self.expect("(")) + and (keywords := self.keyword_patterns()) + and (self.expect(","),) + and (self.expect(")")) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . MatchClass ( cls = cls , patterns = [] , kwd_attrs = [k for k , _ in keywords] , kwd_patterns = [p for _ , p in keywords] , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset , ); + return ast.MatchClass( + cls=cls, + patterns=[], + kwd_attrs=[k for k, _ in keywords], + kwd_patterns=[p for _, p in keywords], + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) if ( (cls := self.name_or_attr()) - and - (self.expect('(')) - and - (patterns := self.positional_patterns()) - and - (self.expect(',')) - and - (keywords := self.keyword_patterns()) - and - (self.expect(','),) - and - (self.expect(')')) + and (self.expect("(")) + and (patterns := self.positional_patterns()) + and (self.expect(",")) + and (keywords := self.keyword_patterns()) + and (self.expect(","),) + and (self.expect(")")) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . MatchClass ( cls = cls , patterns = patterns , kwd_attrs = [k for k , _ in keywords] , kwd_patterns = [p for _ , p in keywords] , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset , ); + return ast.MatchClass( + cls=cls, + patterns=patterns, + kwd_attrs=[k for k, _ in keywords], + kwd_patterns=[p for _, p in keywords], + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - if ( - self.call_invalid_rules - and - (self.invalid_class_pattern()) - ): - return None # pragma: no cover; + if self.call_invalid_rules and (self.invalid_class_pattern()): + return None # pragma: no cover self._reset(mark) - return None; + return None @memoize def positional_patterns(self) -> Optional[Any]: # positional_patterns: ','.pattern+ mark = self._mark() - if ( - (args := self._gather_110()) - ): - return args; + if args := self._gather_110(): + return args self._reset(mark) - return None; + return None @memoize def keyword_patterns(self) -> Optional[Any]: # keyword_patterns: ','.keyword_pattern+ mark = self._mark() - if ( - (_gather_112 := self._gather_112()) - ): - return _gather_112; + if _gather_112 := self._gather_112(): + return _gather_112 self._reset(mark) - return None; + return None @memoize def keyword_pattern(self) -> Optional[Any]: # keyword_pattern: NAME '=' pattern mark = self._mark() - if ( - (arg := self.name()) - and - (self.expect('=')) - and - (value := self.pattern()) - ): - return ( arg . string , value ); + if (arg := self.name()) and (self.expect("=")) and (value := self.pattern()): + return (arg.string, value) self._reset(mark) - return None; + return None @memoize def type_alias(self) -> Optional["ast.TypeAlias"]: @@ -3703,48 +4033,57 @@ def type_alias(self) -> Optional["ast.TypeAlias"]: start_lineno, start_col_offset = tok.start if ( (self.expect("type")) - and - (n := self.name()) - and - (t := self.type_params(),) - and - (self.expect('=')) - and - (b := self.expression()) - ): - tok = self._tokenizer.get_last_non_whitespace_token() - end_lineno, end_col_offset = tok.end - return self . check_version ( ( 3 , 12 ) , "Type statement is" , ( ast . TypeAlias ( name = ast . Name ( id = n . string , ctx = Store , lineno = n . start [0] , col_offset = n . start [1] , end_lineno = n . end [0] , end_col_offset = n . end [1] , ) , type_params = t or [] , value = b , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ) if sys . version_info >= ( 3 , 12 ) else None ) ); - self._reset(mark) - return None; + and (n := self.name()) + and (t := self.type_params(),) + and (self.expect("=")) + and (b := self.expression()) + ): + tok = self._tokenizer.get_last_non_whitespace_token() + end_lineno, end_col_offset = tok.end + return self.check_version( + (3, 12), + "Type statement is", + ( + ast.TypeAlias( + name=ast.Name( + id=n.string, + ctx=Store, + lineno=n.start[0], + col_offset=n.start[1], + end_lineno=n.end[0], + end_col_offset=n.end[1], + ), + type_params=t or [], + value=b, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) + if sys.version_info >= (3, 12) + else None + ), + ) + self._reset(mark) + return None @memoize def type_params(self) -> Optional[list]: # type_params: '[' type_param_seq ']' mark = self._mark() - if ( - (self.expect('[')) - and - (t := self.type_param_seq()) - and - (self.expect(']')) - ): - return self . check_version ( ( 3 , 12 ) , "Type parameter lists are" , t ); + if (self.expect("[")) and (t := self.type_param_seq()) and (self.expect("]")): + return self.check_version((3, 12), "Type parameter lists are", t) self._reset(mark) - return None; + return None @memoize def type_param_seq(self) -> Optional[Any]: # type_param_seq: ','.type_param+ ','? mark = self._mark() - if ( - (a := self._gather_114()) - and - (self.expect(','),) - ): - return a; + if (a := self._gather_114()) and (self.expect(","),): + return a self._reset(mark) - return None; + return None @memoize def type_param(self) -> Optional[Any]: @@ -3752,69 +4091,88 @@ def type_param(self) -> Optional[Any]: mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - (a := self.name()) - and - (b := self.type_param_bound(),) - ): - tok = self._tokenizer.get_last_non_whitespace_token() - end_lineno, end_col_offset = tok.end - return ast . TypeVar ( name = a . string , bound = b , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ) if sys . version_info >= ( 3 , 12 ) else object ( ); - self._reset(mark) - if ( - (self.expect('*')) - and - (self.name()) - and - (colon := self.expect(":")) - and - (e := self.expression()) - ): - return self . raise_syntax_error_starting_from ( "cannot use constraints with TypeVarTuple" if isinstance ( e , ast . Tuple ) else "cannot use bound with TypeVarTuple" , colon ); - self._reset(mark) - if ( - (self.expect('*')) - and - (a := self.name()) - ): - tok = self._tokenizer.get_last_non_whitespace_token() - end_lineno, end_col_offset = tok.end - return ast . TypeVarTuple ( name = a . string , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ) if sys . version_info >= ( 3 , 12 ) else object ( ); - self._reset(mark) - if ( - (self.expect('**')) - and - (self.name()) - and - (colon := self.expect(":")) - and - (e := self.expression()) - ): - return self . raise_syntax_error_starting_from ( "cannot use constraints with ParamSpec" if isinstance ( e , ast . Tuple ) else "cannot use bound with ParamSpec" , colon ); - self._reset(mark) - if ( - (self.expect('**')) - and - (a := self.name()) - ): - tok = self._tokenizer.get_last_non_whitespace_token() - end_lineno, end_col_offset = tok.end - return ast . ParamSpec ( name = a . string , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ) if sys . version_info >= ( 3 , 12 ) else object ( ); - self._reset(mark) - return None; + if (a := self.name()) and (b := self.type_param_bound(),): + tok = self._tokenizer.get_last_non_whitespace_token() + end_lineno, end_col_offset = tok.end + return ( + ast.TypeVar( + name=a.string, + bound=b, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) + if sys.version_info >= (3, 12) + else object() + ) + self._reset(mark) + if ( + (self.expect("*")) + and (self.name()) + and (colon := self.expect(":")) + and (e := self.expression()) + ): + return self.raise_syntax_error_starting_from( + "cannot use constraints with TypeVarTuple" + if isinstance(e, ast.Tuple) + else "cannot use bound with TypeVarTuple", + colon, + ) + self._reset(mark) + if (self.expect("*")) and (a := self.name()): + tok = self._tokenizer.get_last_non_whitespace_token() + end_lineno, end_col_offset = tok.end + return ( + ast.TypeVarTuple( + name=a.string, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) + if sys.version_info >= (3, 12) + else object() + ) + self._reset(mark) + if ( + (self.expect("**")) + and (self.name()) + and (colon := self.expect(":")) + and (e := self.expression()) + ): + return self.raise_syntax_error_starting_from( + "cannot use constraints with ParamSpec" + if isinstance(e, ast.Tuple) + else "cannot use bound with ParamSpec", + colon, + ) + self._reset(mark) + if (self.expect("**")) and (a := self.name()): + tok = self._tokenizer.get_last_non_whitespace_token() + end_lineno, end_col_offset = tok.end + return ( + ast.ParamSpec( + name=a.string, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) + if sys.version_info >= (3, 12) + else object() + ) + self._reset(mark) + return None @memoize def type_param_bound(self) -> Optional[Any]: # type_param_bound: ":" expression mark = self._mark() - if ( - (self.expect(":")) - and - (e := self.expression()) - ): - return e; + if (self.expect(":")) and (e := self.expression()): + return e self._reset(mark) - return None; + return None @memoize def expressions(self) -> Optional[Any]: @@ -3824,30 +4182,36 @@ def expressions(self) -> Optional[Any]: start_lineno, start_col_offset = tok.start if ( (a := self.expression()) - and - (b := self._loop1_116()) - and - (self.expect(','),) + and (b := self._loop1_116()) + and (self.expect(","),) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . Tuple ( elts = [a] + b , ctx = Load , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.Tuple( + elts=[a] + b, + ctx=Load, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - if ( - (a := self.expression()) - and - (self.expect(',')) - ): + if (a := self.expression()) and (self.expect(",")): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . Tuple ( elts = [a] , ctx = Load , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.Tuple( + elts=[a], + ctx=Load, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - if ( - (expression := self.expression()) - ): - return expression; + if expression := self.expression(): + return expression self._reset(mark) - return None; + return None @memoize def expression(self) -> Optional[Any]: @@ -3855,46 +4219,38 @@ def expression(self) -> Optional[Any]: mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - self.call_invalid_rules - and - (self.invalid_expression()) - ): - return None # pragma: no cover; + if self.call_invalid_rules and (self.invalid_expression()): + return None # pragma: no cover self._reset(mark) - if ( - self.call_invalid_rules - and - (self.invalid_legacy_expression()) - ): - return None # pragma: no cover; + if self.call_invalid_rules and (self.invalid_legacy_expression()): + return None # pragma: no cover self._reset(mark) if ( (a := self.disjunction()) - and - (self.expect('if')) - and - (b := self.disjunction()) - and - (self.expect('else')) - and - (c := self.expression()) + and (self.expect("if")) + and (b := self.disjunction()) + and (self.expect("else")) + and (c := self.expression()) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . IfExp ( body = a , test = b , orelse = c , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.IfExp( + body=a, + test=b, + orelse=c, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - if ( - (disjunction := self.disjunction()) - ): - return disjunction; + if disjunction := self.disjunction(): + return disjunction self._reset(mark) - if ( - (lambdef := self.lambdef()) - ): - return lambdef; + if lambdef := self.lambdef(): + return lambdef self._reset(mark) - return None; + return None @memoize def yield_expr(self) -> Optional[Any]: @@ -3903,26 +4259,32 @@ def yield_expr(self) -> Optional[Any]: tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start if ( - (self.expect('yield')) - and - (self.expect('from')) - and - (a := self.expression()) + (self.expect("yield")) + and (self.expect("from")) + and (a := self.expression()) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . YieldFrom ( value = a , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.YieldFrom( + value=a, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - if ( - (self.expect('yield')) - and - (a := self.star_expressions(),) - ): + if (self.expect("yield")) and (a := self.star_expressions(),): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . Yield ( value = a , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.Yield( + value=a, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - return None; + return None @memoize def star_expressions(self) -> Optional[Any]: @@ -3932,30 +4294,36 @@ def star_expressions(self) -> Optional[Any]: start_lineno, start_col_offset = tok.start if ( (a := self.star_expression()) - and - (b := self._loop1_117()) - and - (self.expect(','),) + and (b := self._loop1_117()) + and (self.expect(","),) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . Tuple ( elts = [a] + b , ctx = Load , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.Tuple( + elts=[a] + b, + ctx=Load, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - if ( - (a := self.star_expression()) - and - (self.expect(',')) - ): + if (a := self.star_expression()) and (self.expect(",")): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . Tuple ( elts = [a] , ctx = Load , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.Tuple( + elts=[a], + ctx=Load, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - if ( - (star_expression := self.star_expression()) - ): - return star_expression; + if star_expression := self.star_expression(): + return star_expression self._reset(mark) - return None; + return None @memoize def star_expression(self) -> Optional[Any]: @@ -3963,34 +4331,31 @@ def star_expression(self) -> Optional[Any]: mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - (self.expect('*')) - and - (a := self.bitwise_or()) - ): + if (self.expect("*")) and (a := self.bitwise_or()): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . Starred ( value = a , ctx = Load , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.Starred( + value=a, + ctx=Load, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - if ( - (expression := self.expression()) - ): - return expression; + if expression := self.expression(): + return expression self._reset(mark) - return None; + return None @memoize def star_named_expressions(self) -> Optional[Any]: # star_named_expressions: ','.star_named_expression+ ','? mark = self._mark() - if ( - (a := self._gather_118()) - and - (self.expect(','),) - ): - return a; + if (a := self._gather_118()) and (self.expect(","),): + return a self._reset(mark) - return None; + return None @memoize def star_named_expression(self) -> Optional[Any]: @@ -3998,21 +4363,22 @@ def star_named_expression(self) -> Optional[Any]: mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - (self.expect('*')) - and - (a := self.bitwise_or()) - ): + if (self.expect("*")) and (a := self.bitwise_or()): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . Starred ( value = a , ctx = Load , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.Starred( + value=a, + ctx=Load, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - if ( - (named_expression := self.named_expression()) - ): - return named_expression; + if named_expression := self.named_expression(): + return named_expression self._reset(mark) - return None; + return None @memoize def assignment_expression(self) -> Optional[Any]: @@ -4023,45 +4389,50 @@ def assignment_expression(self) -> Optional[Any]: cut = False if ( (a := self.name()) - and - (self.expect(':=')) - and - (cut := True) - and - (b := self.expression()) - ): - tok = self._tokenizer.get_last_non_whitespace_token() - end_lineno, end_col_offset = tok.end - return self . check_version ( ( 3 , 8 ) , "The ':=' operator is" , ast . NamedExpr ( target = ast . Name ( id = a . string , ctx = Store , lineno = a . start [0] , col_offset = a . start [1] , end_lineno = a . end [0] , end_col_offset = a . end [1] ) , value = b , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset , ) ); + and (self.expect(":=")) + and (cut := True) + and (b := self.expression()) + ): + tok = self._tokenizer.get_last_non_whitespace_token() + end_lineno, end_col_offset = tok.end + return self.check_version( + (3, 8), + "The ':=' operator is", + ast.NamedExpr( + target=ast.Name( + id=a.string, + ctx=Store, + lineno=a.start[0], + col_offset=a.start[1], + end_lineno=a.end[0], + end_col_offset=a.end[1], + ), + value=b, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ), + ) self._reset(mark) if cut: - return None; - return None; + return None + return None @memoize def named_expression(self) -> Optional[Any]: # named_expression: assignment_expression | invalid_named_expression | expression !':=' mark = self._mark() - if ( - (assignment_expression := self.assignment_expression()) - ): - return assignment_expression; + if assignment_expression := self.assignment_expression(): + return assignment_expression self._reset(mark) - if ( - self.call_invalid_rules - and - (self.invalid_named_expression()) - ): - return None # pragma: no cover; + if self.call_invalid_rules and (self.invalid_named_expression()): + return None # pragma: no cover self._reset(mark) - if ( - (a := self.expression()) - and - (self.negative_lookahead(self.expect, ':=')) - ): - return a; + if (a := self.expression()) and (self.negative_lookahead(self.expect, ":=")): + return a self._reset(mark) - return None; + return None @memoize def disjunction(self) -> Optional[Any]: @@ -4069,21 +4440,22 @@ def disjunction(self) -> Optional[Any]: mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - (a := self.conjunction()) - and - (b := self._loop1_120()) - ): + if (a := self.conjunction()) and (b := self._loop1_120()): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . BoolOp ( op = ast . Or ( ) , values = [a] + b , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.BoolOp( + op=ast.Or(), + values=[a] + b, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - if ( - (conjunction := self.conjunction()) - ): - return conjunction; + if conjunction := self.conjunction(): + return conjunction self._reset(mark) - return None; + return None @memoize def conjunction(self) -> Optional[Any]: @@ -4091,21 +4463,22 @@ def conjunction(self) -> Optional[Any]: mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - (a := self.inversion()) - and - (b := self._loop1_121()) - ): + if (a := self.inversion()) and (b := self._loop1_121()): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . BoolOp ( op = ast . And ( ) , values = [a] + b , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.BoolOp( + op=ast.And(), + values=[a] + b, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - if ( - (inversion := self.inversion()) - ): - return inversion; + if inversion := self.inversion(): + return inversion self._reset(mark) - return None; + return None @memoize def inversion(self) -> Optional[Any]: @@ -4113,21 +4486,22 @@ def inversion(self) -> Optional[Any]: mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - (self.expect('not')) - and - (a := self.inversion()) - ): + if (self.expect("not")) and (a := self.inversion()): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . UnaryOp ( op = ast . Not ( ) , operand = a , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.UnaryOp( + op=ast.Not(), + operand=a, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - if ( - (comparison := self.comparison()) - ): - return comparison; + if comparison := self.comparison(): + return comparison self._reset(mark) - return None; + return None @memoize def comparison(self) -> Optional[Any]: @@ -4135,211 +4509,149 @@ def comparison(self) -> Optional[Any]: mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - (a := self.bitwise_or()) - and - (b := self._loop1_122()) - ): + if (a := self.bitwise_or()) and (b := self._loop1_122()): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . Compare ( left = a , ops = self . get_comparison_ops ( b ) , comparators = self . get_comparators ( b ) , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.Compare( + left=a, + ops=self.get_comparison_ops(b), + comparators=self.get_comparators(b), + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - if ( - (bitwise_or := self.bitwise_or()) - ): - return bitwise_or; + if bitwise_or := self.bitwise_or(): + return bitwise_or self._reset(mark) - return None; + return None @memoize def compare_op_bitwise_or_pair(self) -> Optional[Any]: # compare_op_bitwise_or_pair: eq_bitwise_or | noteq_bitwise_or | lte_bitwise_or | lt_bitwise_or | gte_bitwise_or | gt_bitwise_or | notin_bitwise_or | in_bitwise_or | isnot_bitwise_or | is_bitwise_or mark = self._mark() - if ( - (eq_bitwise_or := self.eq_bitwise_or()) - ): - return eq_bitwise_or; + if eq_bitwise_or := self.eq_bitwise_or(): + return eq_bitwise_or self._reset(mark) - if ( - (noteq_bitwise_or := self.noteq_bitwise_or()) - ): - return noteq_bitwise_or; + if noteq_bitwise_or := self.noteq_bitwise_or(): + return noteq_bitwise_or self._reset(mark) - if ( - (lte_bitwise_or := self.lte_bitwise_or()) - ): - return lte_bitwise_or; + if lte_bitwise_or := self.lte_bitwise_or(): + return lte_bitwise_or self._reset(mark) - if ( - (lt_bitwise_or := self.lt_bitwise_or()) - ): - return lt_bitwise_or; + if lt_bitwise_or := self.lt_bitwise_or(): + return lt_bitwise_or self._reset(mark) - if ( - (gte_bitwise_or := self.gte_bitwise_or()) - ): - return gte_bitwise_or; + if gte_bitwise_or := self.gte_bitwise_or(): + return gte_bitwise_or self._reset(mark) - if ( - (gt_bitwise_or := self.gt_bitwise_or()) - ): - return gt_bitwise_or; + if gt_bitwise_or := self.gt_bitwise_or(): + return gt_bitwise_or self._reset(mark) - if ( - (notin_bitwise_or := self.notin_bitwise_or()) - ): - return notin_bitwise_or; + if notin_bitwise_or := self.notin_bitwise_or(): + return notin_bitwise_or self._reset(mark) - if ( - (in_bitwise_or := self.in_bitwise_or()) - ): - return in_bitwise_or; + if in_bitwise_or := self.in_bitwise_or(): + return in_bitwise_or self._reset(mark) - if ( - (isnot_bitwise_or := self.isnot_bitwise_or()) - ): - return isnot_bitwise_or; + if isnot_bitwise_or := self.isnot_bitwise_or(): + return isnot_bitwise_or self._reset(mark) - if ( - (is_bitwise_or := self.is_bitwise_or()) - ): - return is_bitwise_or; + if is_bitwise_or := self.is_bitwise_or(): + return is_bitwise_or self._reset(mark) - return None; + return None @memoize def eq_bitwise_or(self) -> Optional[Any]: # eq_bitwise_or: '==' bitwise_or mark = self._mark() - if ( - (self.expect('==')) - and - (a := self.bitwise_or()) - ): - return ( ast . Eq ( ) , a ); + if (self.expect("==")) and (a := self.bitwise_or()): + return (ast.Eq(), a) self._reset(mark) - return None; + return None @memoize def noteq_bitwise_or(self) -> Optional[tuple]: # noteq_bitwise_or: '!=' bitwise_or mark = self._mark() - if ( - (self.expect('!=')) - and - (a := self.bitwise_or()) - ): - return ( ast . NotEq ( ) , a ); + if (self.expect("!=")) and (a := self.bitwise_or()): + return (ast.NotEq(), a) self._reset(mark) - return None; + return None @memoize def lte_bitwise_or(self) -> Optional[Any]: # lte_bitwise_or: '<=' bitwise_or mark = self._mark() - if ( - (self.expect('<=')) - and - (a := self.bitwise_or()) - ): - return ( ast . LtE ( ) , a ); + if (self.expect("<=")) and (a := self.bitwise_or()): + return (ast.LtE(), a) self._reset(mark) - return None; + return None @memoize def lt_bitwise_or(self) -> Optional[Any]: # lt_bitwise_or: '<' bitwise_or mark = self._mark() - if ( - (self.expect('<')) - and - (a := self.bitwise_or()) - ): - return ( ast . Lt ( ) , a ); + if (self.expect("<")) and (a := self.bitwise_or()): + return (ast.Lt(), a) self._reset(mark) - return None; + return None @memoize def gte_bitwise_or(self) -> Optional[Any]: # gte_bitwise_or: '>=' bitwise_or mark = self._mark() - if ( - (self.expect('>=')) - and - (a := self.bitwise_or()) - ): - return ( ast . GtE ( ) , a ); + if (self.expect(">=")) and (a := self.bitwise_or()): + return (ast.GtE(), a) self._reset(mark) - return None; + return None @memoize def gt_bitwise_or(self) -> Optional[Any]: # gt_bitwise_or: '>' bitwise_or mark = self._mark() - if ( - (self.expect('>')) - and - (a := self.bitwise_or()) - ): - return ( ast . Gt ( ) , a ); + if (self.expect(">")) and (a := self.bitwise_or()): + return (ast.Gt(), a) self._reset(mark) - return None; + return None @memoize def notin_bitwise_or(self) -> Optional[Any]: # notin_bitwise_or: 'not' 'in' bitwise_or mark = self._mark() - if ( - (self.expect('not')) - and - (self.expect('in')) - and - (a := self.bitwise_or()) - ): - return ( ast . NotIn ( ) , a ); + if (self.expect("not")) and (self.expect("in")) and (a := self.bitwise_or()): + return (ast.NotIn(), a) self._reset(mark) - return None; + return None @memoize def in_bitwise_or(self) -> Optional[Any]: # in_bitwise_or: 'in' bitwise_or mark = self._mark() - if ( - (self.expect('in')) - and - (a := self.bitwise_or()) - ): - return ( ast . In ( ) , a ); + if (self.expect("in")) and (a := self.bitwise_or()): + return (ast.In(), a) self._reset(mark) - return None; + return None @memoize def isnot_bitwise_or(self) -> Optional[Any]: # isnot_bitwise_or: 'is' 'not' bitwise_or mark = self._mark() - if ( - (self.expect('is')) - and - (self.expect('not')) - and - (a := self.bitwise_or()) - ): - return ( ast . IsNot ( ) , a ); + if (self.expect("is")) and (self.expect("not")) and (a := self.bitwise_or()): + return (ast.IsNot(), a) self._reset(mark) - return None; + return None @memoize def is_bitwise_or(self) -> Optional[Any]: # is_bitwise_or: 'is' bitwise_or mark = self._mark() - if ( - (self.expect('is')) - and - (a := self.bitwise_or()) - ): - return ( ast . Is ( ) , a ); + if (self.expect("is")) and (a := self.bitwise_or()): + return (ast.Is(), a) self._reset(mark) - return None; + return None @memoize_left_rec def bitwise_or(self) -> Optional[Any]: @@ -4349,21 +4661,25 @@ def bitwise_or(self) -> Optional[Any]: start_lineno, start_col_offset = tok.start if ( (a := self.bitwise_or()) - and - (self.expect('|')) - and - (b := self.bitwise_xor()) + and (self.expect("|")) + and (b := self.bitwise_xor()) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . BinOp ( left = a , op = ast . BitOr ( ) , right = b , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.BinOp( + left=a, + op=ast.BitOr(), + right=b, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - if ( - (bitwise_xor := self.bitwise_xor()) - ): - return bitwise_xor; + if bitwise_xor := self.bitwise_xor(): + return bitwise_xor self._reset(mark) - return None; + return None @memoize_left_rec def bitwise_xor(self) -> Optional[Any]: @@ -4373,21 +4689,25 @@ def bitwise_xor(self) -> Optional[Any]: start_lineno, start_col_offset = tok.start if ( (a := self.bitwise_xor()) - and - (self.expect('^')) - and - (b := self.bitwise_and()) + and (self.expect("^")) + and (b := self.bitwise_and()) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . BinOp ( left = a , op = ast . BitXor ( ) , right = b , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.BinOp( + left=a, + op=ast.BitXor(), + right=b, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - if ( - (bitwise_and := self.bitwise_and()) - ): - return bitwise_and; + if bitwise_and := self.bitwise_and(): + return bitwise_and self._reset(mark) - return None; + return None @memoize_left_rec def bitwise_and(self) -> Optional[Any]: @@ -4397,21 +4717,25 @@ def bitwise_and(self) -> Optional[Any]: start_lineno, start_col_offset = tok.start if ( (a := self.bitwise_and()) - and - (self.expect('&')) - and - (b := self.shift_expr()) + and (self.expect("&")) + and (b := self.shift_expr()) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . BinOp ( left = a , op = ast . BitAnd ( ) , right = b , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.BinOp( + left=a, + op=ast.BitAnd(), + right=b, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - if ( - (shift_expr := self.shift_expr()) - ): - return shift_expr; + if shift_expr := self.shift_expr(): + return shift_expr self._reset(mark) - return None; + return None @memoize_left_rec def shift_expr(self) -> Optional[Any]: @@ -4419,34 +4743,36 @@ def shift_expr(self) -> Optional[Any]: mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - (a := self.shift_expr()) - and - (self.expect('<<')) - and - (b := self.sum()) - ): + if (a := self.shift_expr()) and (self.expect("<<")) and (b := self.sum()): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . BinOp ( left = a , op = ast . LShift ( ) , right = b , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.BinOp( + left=a, + op=ast.LShift(), + right=b, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - if ( - (a := self.shift_expr()) - and - (self.expect('>>')) - and - (b := self.sum()) - ): + if (a := self.shift_expr()) and (self.expect(">>")) and (b := self.sum()): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . BinOp ( left = a , op = ast . RShift ( ) , right = b , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.BinOp( + left=a, + op=ast.RShift(), + right=b, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - if ( - (sum := self.sum()) - ): - return sum; + if sum := self.sum(): + return sum self._reset(mark) - return None; + return None @memoize_left_rec def sum(self) -> Optional[Any]: @@ -4454,34 +4780,36 @@ def sum(self) -> Optional[Any]: mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - (a := self.sum()) - and - (self.expect('+')) - and - (b := self.term()) - ): + if (a := self.sum()) and (self.expect("+")) and (b := self.term()): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . BinOp ( left = a , op = ast . Add ( ) , right = b , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.BinOp( + left=a, + op=ast.Add(), + right=b, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - if ( - (a := self.sum()) - and - (self.expect('-')) - and - (b := self.term()) - ): + if (a := self.sum()) and (self.expect("-")) and (b := self.term()): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . BinOp ( left = a , op = ast . Sub ( ) , right = b , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.BinOp( + left=a, + op=ast.Sub(), + right=b, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - if ( - (term := self.term()) - ): - return term; + if term := self.term(): + return term self._reset(mark) - return None; + return None @memoize_left_rec def term(self) -> Optional[Any]: @@ -4489,67 +4817,79 @@ def term(self) -> Optional[Any]: mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - (a := self.term()) - and - (self.expect('*')) - and - (b := self.factor()) - ): + if (a := self.term()) and (self.expect("*")) and (b := self.factor()): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . BinOp ( left = a , op = ast . Mult ( ) , right = b , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.BinOp( + left=a, + op=ast.Mult(), + right=b, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - if ( - (a := self.term()) - and - (self.expect('/')) - and - (b := self.factor()) - ): + if (a := self.term()) and (self.expect("/")) and (b := self.factor()): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . BinOp ( left = a , op = ast . Div ( ) , right = b , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.BinOp( + left=a, + op=ast.Div(), + right=b, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - if ( - (a := self.term()) - and - (self.expect('//')) - and - (b := self.factor()) - ): + if (a := self.term()) and (self.expect("//")) and (b := self.factor()): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . BinOp ( left = a , op = ast . FloorDiv ( ) , right = b , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.BinOp( + left=a, + op=ast.FloorDiv(), + right=b, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - if ( - (a := self.term()) - and - (self.expect('%')) - and - (b := self.factor()) - ): + if (a := self.term()) and (self.expect("%")) and (b := self.factor()): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . BinOp ( left = a , op = ast . Mod ( ) , right = b , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.BinOp( + left=a, + op=ast.Mod(), + right=b, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - if ( - (a := self.term()) - and - (self.expect('@')) - and - (b := self.factor()) - ): + if (a := self.term()) and (self.expect("@")) and (b := self.factor()): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return self . check_version ( ( 3 , 5 ) , "The '@' operator is" , ast . BinOp ( left = a , op = ast . MatMult ( ) , right = b , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ) ); + return self.check_version( + (3, 5), + "The '@' operator is", + ast.BinOp( + left=a, + op=ast.MatMult(), + right=b, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ), + ) self._reset(mark) - if ( - (factor := self.factor()) - ): - return factor; + if factor := self.factor(): + return factor self._reset(mark) - return None; + return None @memoize def factor(self) -> Optional[Any]: @@ -4557,39 +4897,46 @@ def factor(self) -> Optional[Any]: mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - (self.expect('+')) - and - (a := self.factor()) - ): + if (self.expect("+")) and (a := self.factor()): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . UnaryOp ( op = ast . UAdd ( ) , operand = a , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.UnaryOp( + op=ast.UAdd(), + operand=a, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - if ( - (self.expect('-')) - and - (a := self.factor()) - ): + if (self.expect("-")) and (a := self.factor()): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . UnaryOp ( op = ast . USub ( ) , operand = a , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.UnaryOp( + op=ast.USub(), + operand=a, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - if ( - (self.expect('~')) - and - (a := self.factor()) - ): + if (self.expect("~")) and (a := self.factor()): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . UnaryOp ( op = ast . Invert ( ) , operand = a , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.UnaryOp( + op=ast.Invert(), + operand=a, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - if ( - (power := self.power()) - ): - return power; + if power := self.power(): + return power self._reset(mark) - return None; + return None @memoize def power(self) -> Optional[Any]: @@ -4597,23 +4944,23 @@ def power(self) -> Optional[Any]: mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - (a := self.await_primary()) - and - (self.expect('**')) - and - (b := self.factor()) - ): + if (a := self.await_primary()) and (self.expect("**")) and (b := self.factor()): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . BinOp ( left = a , op = ast . Pow ( ) , right = b , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.BinOp( + left=a, + op=ast.Pow(), + right=b, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - if ( - (await_primary := self.await_primary()) - ): - return await_primary; + if await_primary := self.await_primary(): + return await_primary self._reset(mark) - return None; + return None @memoize def await_primary(self) -> Optional[Any]: @@ -4621,21 +4968,25 @@ def await_primary(self) -> Optional[Any]: mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - (self.expect('await')) - and - (a := self.primary()) - ): + if (self.expect("await")) and (a := self.primary()): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return self . check_version ( ( 3 , 5 ) , "Await expressions are" , ast . Await ( a , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ) ); + return self.check_version( + (3, 5), + "Await expressions are", + ast.Await( + a, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ), + ) self._reset(mark) - if ( - (primary := self.primary()) - ): - return primary; + if primary := self.primary(): + return primary self._reset(mark) - return None; + return None @memoize_left_rec def primary(self) -> Optional[Any]: @@ -4643,58 +4994,72 @@ def primary(self) -> Optional[Any]: mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - (a := self.primary()) - and - (self.expect('.')) - and - (b := self.name()) - ): + if (a := self.primary()) and (self.expect(".")) and (b := self.name()): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . Attribute ( value = a , attr = b . string , ctx = Load , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.Attribute( + value=a, + attr=b.string, + ctx=Load, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - if ( - (a := self.primary()) - and - (b := self.genexp()) - ): + if (a := self.primary()) and (b := self.genexp()): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . Call ( func = a , args = [b] , keywords = [] , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.Call( + func=a, + args=[b], + keywords=[], + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) if ( (a := self.primary()) - and - (self.expect('(')) - and - (b := self.arguments(),) - and - (self.expect(')')) + and (self.expect("(")) + and (b := self.arguments(),) + and (self.expect(")")) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . Call ( func = a , args = b [0] if b else [] , keywords = b [1] if b else [] , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset , ); + return ast.Call( + func=a, + args=b[0] if b else [], + keywords=b[1] if b else [], + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) if ( (a := self.primary()) - and - (self.expect('[')) - and - (b := self.slices()) - and - (self.expect(']')) + and (self.expect("[")) + and (b := self.slices()) + and (self.expect("]")) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . Subscript ( value = a , slice = b , ctx = Load , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.Subscript( + value=a, + slice=b, + ctx=Load, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - if ( - (atom := self.atom()) - ): - return atom; + if atom := self.atom(): + return atom self._reset(mark) - return None; + return None @memoize def slices(self) -> Optional[Any]: @@ -4702,23 +5067,49 @@ def slices(self) -> Optional[Any]: mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - (a := self.slice()) - and - (self.negative_lookahead(self.expect, ',')) - ): - return a; - self._reset(mark) - if ( - (a := self._gather_123()) - and - (self.expect(','),) - ): - tok = self._tokenizer.get_last_non_whitespace_token() - end_lineno, end_col_offset = tok.end - return ast . Tuple ( elts = a , ctx = Load , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ) if sys . version_info >= ( 3 , 9 ) else ( ast . ExtSlice ( dims = a , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ) if any ( isinstance ( e , ast . Slice ) for e in a ) else ast . Index ( value = ast . Tuple ( elts = [e . value for e in a] , ctx = Load , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ) , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ) ); - self._reset(mark) - return None; + if (a := self.slice()) and (self.negative_lookahead(self.expect, ",")): + return a + self._reset(mark) + if (a := self._gather_123()) and (self.expect(","),): + tok = self._tokenizer.get_last_non_whitespace_token() + end_lineno, end_col_offset = tok.end + return ( + ast.Tuple( + elts=a, + ctx=Load, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) + if sys.version_info >= (3, 9) + else ( + ast.ExtSlice( + dims=a, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) + if any(isinstance(e, ast.Slice) for e in a) + else ast.Index( + value=ast.Tuple( + elts=[e.value for e in a], + ctx=Load, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ), + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) + ) + ) + self._reset(mark) + return None @memoize def slice(self) -> Optional[Any]: @@ -4728,123 +5119,200 @@ def slice(self) -> Optional[Any]: start_lineno, start_col_offset = tok.start if ( (a := self.expression(),) - and - (self.expect(':')) - and - (b := self.expression(),) - and - (c := self._tmp_125(),) - ): - tok = self._tokenizer.get_last_non_whitespace_token() - end_lineno, end_col_offset = tok.end - return ast . Slice ( lower = a , upper = b , step = c , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); - self._reset(mark) - if ( - (a := self.named_expression()) - ): - return a if sys . version_info >= ( 3 , 9 ) or isinstance ( a , ast . Slice ) else ast . Index ( value = a , lineno = a . lineno , col_offset = a . col_offset , end_lineno = a . end_lineno , end_col_offset = a . end_col_offset ); - self._reset(mark) - return None; + and (self.expect(":")) + and (b := self.expression(),) + and (c := self._tmp_125(),) + ): + tok = self._tokenizer.get_last_non_whitespace_token() + end_lineno, end_col_offset = tok.end + return ast.Slice( + lower=a, + upper=b, + step=c, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) + self._reset(mark) + if a := self.named_expression(): + return ( + a + if sys.version_info >= (3, 9) or isinstance(a, ast.Slice) + else ast.Index( + value=a, + lineno=a.lineno, + col_offset=a.col_offset, + end_lineno=a.end_lineno, + end_col_offset=a.end_col_offset, + ) + ) + self._reset(mark) + return None @memoize def atom(self) -> Optional[Any]: - # atom: NAME | 'True' | 'False' | 'None' | &(STRING | FSTRING_START) strings | NUMBER | &'(' (tuple | group | genexp) | &'[' (list | listcomp) | &'{' (dict | set | dictcomp | setcomp) | '...' + # atom: NAME | 'True' | 'False' | 'None' | &(STRING | FSTRING_START | TSTRING_START) strings | NUMBER | &'(' (tuple | group | genexp) | &'[' (list | listcomp) | &'{' (dict | set | dictcomp | setcomp) | '...' mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - (a := self.name()) - ): - tok = self._tokenizer.get_last_non_whitespace_token() - end_lineno, end_col_offset = tok.end - return ast . Name ( id = a . string , ctx = Load , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); - self._reset(mark) - if ( - (self.expect('True')) - ): - tok = self._tokenizer.get_last_non_whitespace_token() - end_lineno, end_col_offset = tok.end - return ast . Constant ( value = True , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ) if sys . version_info >= ( 3 , 9 ) else ast . Constant ( value = True , kind = None , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); - self._reset(mark) - if ( - (self.expect('False')) - ): - tok = self._tokenizer.get_last_non_whitespace_token() - end_lineno, end_col_offset = tok.end - return ast . Constant ( value = False , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ) if sys . version_info >= ( 3 , 9 ) else ast . Constant ( value = False , kind = None , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); - self._reset(mark) - if ( - (self.expect('None')) - ): - tok = self._tokenizer.get_last_non_whitespace_token() - end_lineno, end_col_offset = tok.end - return ast . Constant ( value = None , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ) if sys . version_info >= ( 3 , 9 ) else ast . Constant ( value = None , kind = None , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); - self._reset(mark) - if ( - (self.positive_lookahead(self._tmp_126, )) - and - (strings := self.strings()) - ): - return strings; - self._reset(mark) - if ( - (a := self.number()) - ): - tok = self._tokenizer.get_last_non_whitespace_token() - end_lineno, end_col_offset = tok.end - return ast . Constant ( value = ast . literal_eval ( a . string ) , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ) if sys . version_info >= ( 3 , 9 ) else ast . Constant ( value = ast . literal_eval ( a . string ) , kind = None , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); - self._reset(mark) - if ( - (self.positive_lookahead(self.expect, '(')) - and - (_tmp_127 := self._tmp_127()) - ): - return _tmp_127; - self._reset(mark) - if ( - (self.positive_lookahead(self.expect, '[')) - and - (_tmp_128 := self._tmp_128()) - ): - return _tmp_128; - self._reset(mark) - if ( - (self.positive_lookahead(self.expect, '{')) - and - (_tmp_129 := self._tmp_129()) - ): - return _tmp_129; - self._reset(mark) - if ( - (self.expect('...')) - ): - tok = self._tokenizer.get_last_non_whitespace_token() - end_lineno, end_col_offset = tok.end - return ast . Constant ( value = Ellipsis , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ) if sys . version_info >= ( 3 , 9 ) else ast . Constant ( value = Ellipsis , kind = None , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); - self._reset(mark) - return None; + if a := self.name(): + tok = self._tokenizer.get_last_non_whitespace_token() + end_lineno, end_col_offset = tok.end + return ast.Name( + id=a.string, + ctx=Load, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) + self._reset(mark) + if self.expect("True"): + tok = self._tokenizer.get_last_non_whitespace_token() + end_lineno, end_col_offset = tok.end + return ( + ast.Constant( + value=True, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) + if sys.version_info >= (3, 9) + else ast.Constant( + value=True, + kind=None, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) + ) + self._reset(mark) + if self.expect("False"): + tok = self._tokenizer.get_last_non_whitespace_token() + end_lineno, end_col_offset = tok.end + return ( + ast.Constant( + value=False, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) + if sys.version_info >= (3, 9) + else ast.Constant( + value=False, + kind=None, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) + ) + self._reset(mark) + if self.expect("None"): + tok = self._tokenizer.get_last_non_whitespace_token() + end_lineno, end_col_offset = tok.end + return ( + ast.Constant( + value=None, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) + if sys.version_info >= (3, 9) + else ast.Constant( + value=None, + kind=None, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) + ) + self._reset(mark) + if ( + self.positive_lookahead( + self._tmp_126, + ) + ) and (strings := self.strings()): + return strings + self._reset(mark) + if a := self.number(): + tok = self._tokenizer.get_last_non_whitespace_token() + end_lineno, end_col_offset = tok.end + return ( + ast.Constant( + value=ast.literal_eval(a.string), + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) + if sys.version_info >= (3, 9) + else ast.Constant( + value=ast.literal_eval(a.string), + kind=None, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) + ) + self._reset(mark) + if (self.positive_lookahead(self.expect, "(")) and ( + _tmp_127 := self._tmp_127() + ): + return _tmp_127 + self._reset(mark) + if (self.positive_lookahead(self.expect, "[")) and ( + _tmp_128 := self._tmp_128() + ): + return _tmp_128 + self._reset(mark) + if (self.positive_lookahead(self.expect, "{")) and ( + _tmp_129 := self._tmp_129() + ): + return _tmp_129 + self._reset(mark) + if self.expect("..."): + tok = self._tokenizer.get_last_non_whitespace_token() + end_lineno, end_col_offset = tok.end + return ( + ast.Constant( + value=Ellipsis, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) + if sys.version_info >= (3, 9) + else ast.Constant( + value=Ellipsis, + kind=None, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) + ) + self._reset(mark) + return None @memoize def group(self) -> Optional[Any]: # group: '(' (yield_expr | named_expression) ')' | invalid_group mark = self._mark() - if ( - (self.expect('(')) - and - (a := self._tmp_130()) - and - (self.expect(')')) - ): - return a; + if (self.expect("(")) and (a := self._tmp_130()) and (self.expect(")")): + return a self._reset(mark) - if ( - self.call_invalid_rules - and - (self.invalid_group()) - ): - return None # pragma: no cover; + if self.call_invalid_rules and (self.invalid_group()): + return None # pragma: no cover self._reset(mark) - return None; + return None @memoize def lambdef(self) -> Optional[Any]: @@ -4853,279 +5321,227 @@ def lambdef(self) -> Optional[Any]: tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start if ( - (self.expect('lambda')) - and - (a := self.lambda_params(),) - and - (self.expect(':')) - and - (b := self.expression()) + (self.expect("lambda")) + and (a := self.lambda_params(),) + and (self.expect(":")) + and (b := self.expression()) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . Lambda ( args = a or self . make_arguments ( None , [] , None , [] , ( None , [] , None ) ) , body = b , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.Lambda( + args=a or self.make_arguments(None, [], None, [], (None, [], None)), + body=b, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - return None; + return None @memoize def lambda_params(self) -> Optional[Any]: # lambda_params: invalid_lambda_parameters | lambda_parameters mark = self._mark() - if ( - self.call_invalid_rules - and - (self.invalid_lambda_parameters()) - ): - return None # pragma: no cover; + if self.call_invalid_rules and (self.invalid_lambda_parameters()): + return None # pragma: no cover self._reset(mark) - if ( - (lambda_parameters := self.lambda_parameters()) - ): - return lambda_parameters; + if lambda_parameters := self.lambda_parameters(): + return lambda_parameters self._reset(mark) - return None; + return None @memoize - def lambda_parameters(self) -> Optional[ast . arguments]: + def lambda_parameters(self) -> Optional[ast.arguments]: # lambda_parameters: lambda_slash_no_default lambda_param_no_default* lambda_param_with_default* lambda_star_etc? | lambda_slash_with_default lambda_param_with_default* lambda_star_etc? | lambda_param_no_default+ lambda_param_with_default* lambda_star_etc? | lambda_param_with_default+ lambda_star_etc? | lambda_star_etc mark = self._mark() if ( (a := self.lambda_slash_no_default()) - and - (b := self._loop0_131(),) - and - (c := self._loop0_132(),) - and - (d := self.lambda_star_etc(),) + and (b := self._loop0_131(),) + and (c := self._loop0_132(),) + and (d := self.lambda_star_etc(),) ): - return self . make_arguments ( a , [] , b , c , d ); + return self.make_arguments(a, [], b, c, d) self._reset(mark) if ( (a := self.lambda_slash_with_default()) - and - (b := self._loop0_133(),) - and - (c := self.lambda_star_etc(),) + and (b := self._loop0_133(),) + and (c := self.lambda_star_etc(),) ): - return self . make_arguments ( None , a , None , b , c ); + return self.make_arguments(None, a, None, b, c) self._reset(mark) if ( (a := self._loop1_134()) - and - (b := self._loop0_135(),) - and - (c := self.lambda_star_etc(),) + and (b := self._loop0_135(),) + and (c := self.lambda_star_etc(),) ): - return self . make_arguments ( None , [] , a , b , c ); + return self.make_arguments(None, [], a, b, c) self._reset(mark) - if ( - (a := self._loop1_136()) - and - (b := self.lambda_star_etc(),) - ): - return self . make_arguments ( None , [] , None , a , b ); + if (a := self._loop1_136()) and (b := self.lambda_star_etc(),): + return self.make_arguments(None, [], None, a, b) self._reset(mark) - if ( - (a := self.lambda_star_etc()) - ): - return self . make_arguments ( None , [] , None , [] , a ); + if a := self.lambda_star_etc(): + return self.make_arguments(None, [], None, [], a) self._reset(mark) - return None; + return None @memoize - def lambda_slash_no_default(self) -> Optional[List [Tuple [ast . arg , None]]]: + def lambda_slash_no_default(self) -> Optional[List[Tuple[ast.arg, None]]]: # lambda_slash_no_default: lambda_param_no_default+ '/' ',' | lambda_param_no_default+ '/' &':' mark = self._mark() - if ( - (a := self._loop1_137()) - and - (self.expect('/')) - and - (self.expect(',')) - ): - return [( p , None ) for p in a]; + if (a := self._loop1_137()) and (self.expect("/")) and (self.expect(",")): + return [(p, None) for p in a] self._reset(mark) if ( (a := self._loop1_138()) - and - (self.expect('/')) - and - (self.positive_lookahead(self.expect, ':')) + and (self.expect("/")) + and (self.positive_lookahead(self.expect, ":")) ): - return [( p , None ) for p in a]; + return [(p, None) for p in a] self._reset(mark) - return None; + return None @memoize - def lambda_slash_with_default(self) -> Optional[List [Tuple [ast . arg , Any]]]: + def lambda_slash_with_default(self) -> Optional[List[Tuple[ast.arg, Any]]]: # lambda_slash_with_default: lambda_param_no_default* lambda_param_with_default+ '/' ',' | lambda_param_no_default* lambda_param_with_default+ '/' &':' mark = self._mark() if ( (a := self._loop0_139(),) - and - (b := self._loop1_140()) - and - (self.expect('/')) - and - (self.expect(',')) + and (b := self._loop1_140()) + and (self.expect("/")) + and (self.expect(",")) ): - return ( [( p , None ) for p in a] if a else [] ) + b; + return ([(p, None) for p in a] if a else []) + b self._reset(mark) if ( (a := self._loop0_141(),) - and - (b := self._loop1_142()) - and - (self.expect('/')) - and - (self.positive_lookahead(self.expect, ':')) + and (b := self._loop1_142()) + and (self.expect("/")) + and (self.positive_lookahead(self.expect, ":")) ): - return ( [( p , None ) for p in a] if a else [] ) + b; + return ([(p, None) for p in a] if a else []) + b self._reset(mark) - return None; + return None @memoize - def lambda_star_etc(self) -> Optional[Tuple [Optional [ast . arg] , List [Tuple [ast . arg , Any]] , Optional [ast . arg]]]: + def lambda_star_etc( + self, + ) -> Optional[ + Tuple[Optional[ast.arg], List[Tuple[ast.arg, Any]], Optional[ast.arg]] + ]: # lambda_star_etc: invalid_lambda_star_etc | '*' lambda_param_no_default lambda_param_maybe_default* lambda_kwds? | '*' ',' lambda_param_maybe_default+ lambda_kwds? | lambda_kwds mark = self._mark() - if ( - self.call_invalid_rules - and - (self.invalid_lambda_star_etc()) - ): - return None # pragma: no cover; + if self.call_invalid_rules and (self.invalid_lambda_star_etc()): + return None # pragma: no cover self._reset(mark) if ( - (self.expect('*')) - and - (a := self.lambda_param_no_default()) - and - (b := self._loop0_143(),) - and - (c := self.lambda_kwds(),) + (self.expect("*")) + and (a := self.lambda_param_no_default()) + and (b := self._loop0_143(),) + and (c := self.lambda_kwds(),) ): - return ( a , b , c ); + return (a, b, c) self._reset(mark) if ( - (self.expect('*')) - and - (self.expect(',')) - and - (b := self._loop1_144()) - and - (c := self.lambda_kwds(),) + (self.expect("*")) + and (self.expect(",")) + and (b := self._loop1_144()) + and (c := self.lambda_kwds(),) ): - return ( None , b , c ); + return (None, b, c) self._reset(mark) - if ( - (a := self.lambda_kwds()) - ): - return ( None , [] , a ); + if a := self.lambda_kwds(): + return (None, [], a) self._reset(mark) - return None; + return None @memoize - def lambda_kwds(self) -> Optional[ast . arg]: + def lambda_kwds(self) -> Optional[ast.arg]: # lambda_kwds: invalid_lambda_kwds | '**' lambda_param_no_default mark = self._mark() - if ( - self.call_invalid_rules - and - (self.invalid_lambda_kwds()) - ): - return None # pragma: no cover; + if self.call_invalid_rules and (self.invalid_lambda_kwds()): + return None # pragma: no cover self._reset(mark) - if ( - (self.expect('**')) - and - (a := self.lambda_param_no_default()) - ): - return a; + if (self.expect("**")) and (a := self.lambda_param_no_default()): + return a self._reset(mark) - return None; + return None @memoize - def lambda_param_no_default(self) -> Optional[ast . arg]: + def lambda_param_no_default(self) -> Optional[ast.arg]: # lambda_param_no_default: lambda_param ',' | lambda_param &':' mark = self._mark() - if ( - (a := self.lambda_param()) - and - (self.expect(',')) - ): - return a; + if (a := self.lambda_param()) and (self.expect(",")): + return a self._reset(mark) - if ( - (a := self.lambda_param()) - and - (self.positive_lookahead(self.expect, ':')) - ): - return a; + if (a := self.lambda_param()) and (self.positive_lookahead(self.expect, ":")): + return a self._reset(mark) - return None; + return None @memoize - def lambda_param_with_default(self) -> Optional[Tuple [ast . arg , Any]]: + def lambda_param_with_default(self) -> Optional[Tuple[ast.arg, Any]]: # lambda_param_with_default: lambda_param default ',' | lambda_param default &':' mark = self._mark() - if ( - (a := self.lambda_param()) - and - (c := self.default()) - and - (self.expect(',')) - ): - return ( a , c ); + if (a := self.lambda_param()) and (c := self.default()) and (self.expect(",")): + return (a, c) self._reset(mark) if ( (a := self.lambda_param()) - and - (c := self.default()) - and - (self.positive_lookahead(self.expect, ':')) + and (c := self.default()) + and (self.positive_lookahead(self.expect, ":")) ): - return ( a , c ); + return (a, c) self._reset(mark) - return None; + return None @memoize - def lambda_param_maybe_default(self) -> Optional[Tuple [ast . arg , Any]]: + def lambda_param_maybe_default(self) -> Optional[Tuple[ast.arg, Any]]: # lambda_param_maybe_default: lambda_param default? ',' | lambda_param default? &':' mark = self._mark() - if ( - (a := self.lambda_param()) - and - (c := self.default(),) - and - (self.expect(',')) - ): - return ( a , c ); + if (a := self.lambda_param()) and (c := self.default(),) and (self.expect(",")): + return (a, c) self._reset(mark) if ( (a := self.lambda_param()) - and - (c := self.default(),) - and - (self.positive_lookahead(self.expect, ':')) + and (c := self.default(),) + and (self.positive_lookahead(self.expect, ":")) ): - return ( a , c ); + return (a, c) self._reset(mark) - return None; + return None @memoize - def lambda_param(self) -> Optional[ast . arg]: + def lambda_param(self) -> Optional[ast.arg]: # lambda_param: NAME mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - (a := self.name()) - ): - tok = self._tokenizer.get_last_non_whitespace_token() - end_lineno, end_col_offset = tok.end - return ast . arg ( arg = a . string , annotation = None , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ) if sys . version_info >= ( 3 , 9 ) else ast . arg ( arg = a . string , annotation = None , type_comment = None , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); - self._reset(mark) - return None; + if a := self.name(): + tok = self._tokenizer.get_last_non_whitespace_token() + end_lineno, end_col_offset = tok.end + return ( + ast.arg( + arg=a.string, + annotation=None, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) + if sys.version_info >= (3, 9) + else ast.arg( + arg=a.string, + annotation=None, + type_comment=None, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) + ) + self._reset(mark) + return None @memoize def fstring_mid(self) -> Optional[Any]: @@ -5133,64 +5549,53 @@ def fstring_mid(self) -> Optional[Any]: mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - (fstring_replacement_field := self.fstring_replacement_field()) - ): - return fstring_replacement_field; + if fstring_replacement_field := self.fstring_replacement_field(): + return fstring_replacement_field self._reset(mark) - if ( - (t := self.fstring_middle()) - ): + if t := self.fstring_middle(): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . Constant ( value = t . string , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.Constant( + value=self._decode_fstring_literal( + t.string, raw=self._is_raw_fstring() + ), + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - return None; + return None @memoize def fstring_replacement_field(self) -> Optional[Any]: - # fstring_replacement_field: '{' (yield_expr | star_expressions) "="? fstring_conversion? fstring_full_format_spec? '}' | invalid_replacement_field + # fstring_replacement_field: '{' annotated_rhs '='? fstring_conversion? fstring_full_format_spec? '}' | invalid_replacement_field mark = self._mark() - tok = self._tokenizer.peek() - start_lineno, start_col_offset = tok.start if ( - (self.expect('{')) - and - (a := self._tmp_145()) - and - (debug_expr := self.expect("="),) - and - (conversion := self.fstring_conversion(),) - and - (format := self.fstring_full_format_spec(),) - and - (self.expect('}')) + (lbrace := self.expect("{")) + and (a := self.annotated_rhs()) + and (debug_expr := self.expect("="),) + and (conversion := self.fstring_conversion(),) + and (format := self.fstring_full_format_spec(),) + and (rbrace := self.expect("}")) ): - tok = self._tokenizer.get_last_non_whitespace_token() - end_lineno, end_col_offset = tok.end - return ast . FormattedValue ( value = a , conversion = ( conversion . decode ( ) [0] if conversion else ( b'r' [0] if debug_expr else - 1 ) ) , format_spec = format , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return self.fstring_debug_value( + a, lbrace, debug_expr, conversion, format, rbrace + ) self._reset(mark) - if ( - self.call_invalid_rules - and - (self.invalid_replacement_field()) - ): - return None # pragma: no cover; + if self.call_invalid_rules and (self.invalid_replacement_field()): + return None # pragma: no cover self._reset(mark) - return None; + return None @memoize def fstring_conversion(self) -> Optional[int]: # fstring_conversion: "!" NAME mark = self._mark() - if ( - (conv_token := self.expect("!")) - and - (conv := self.name()) - ): - return self . check_fstring_conversion ( conv_token , conv ); + if (conv_token := self.expect("!")) and (conv := self.name()): + return self.check_fstring_conversion(conv_token, conv) self._reset(mark) - return None; + return None @memoize def fstring_full_format_spec(self) -> Optional[Any]: @@ -5198,16 +5603,18 @@ def fstring_full_format_spec(self) -> Optional[Any]: mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - (self.expect(':')) - and - (spec := self._loop0_146(),) - ): + if (self.expect(":")) and (spec := self._loop0_145(),): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . JoinedStr ( values = spec if spec and ( len ( spec ) > 1 or spec [0] . value ) else [] , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset , ); + return ast.JoinedStr( + values=self._flatten_joinedstr_values(spec), + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - return None; + return None @memoize def fstring_format_spec(self) -> Optional[Any]: @@ -5215,19 +5622,23 @@ def fstring_format_spec(self) -> Optional[Any]: mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - (t := self.fstring_middle()) - ): + if t := self.fstring_middle(): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . Constant ( value = t . string , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.Constant( + value=self._decode_fstring_literal( + t.string, raw=self._is_raw_fstring() + ), + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - if ( - (fstring_replacement_field := self.fstring_replacement_field()) - ): - return fstring_replacement_field; + if fstring_replacement_field := self.fstring_replacement_field(): + return fstring_replacement_field self._reset(mark) - return None; + return None @memoize def fstring(self) -> Optional[Any]: @@ -5237,399 +5648,498 @@ def fstring(self) -> Optional[Any]: start_lineno, start_col_offset = tok.start if ( (self.fstring_start()) - and - (b := self._loop0_147(),) - and - (self.fstring_end()) + and (b := self._loop0_146(),) + and (self.fstring_end()) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . JoinedStr ( values = b , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.JoinedStr( + values=self._flatten_joinedstr_values(b), + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - return None; + return None @memoize - def strings(self) -> Optional[Any]: - # strings: ((fstring | STRING))+ + def tstring_mid(self) -> Optional[Any]: + # tstring_mid: tstring_replacement_field | TSTRING_MIDDLE + mark = self._mark() + tok = self._tokenizer.peek() + start_lineno, start_col_offset = tok.start + if tstring_replacement_field := self.tstring_replacement_field(): + return tstring_replacement_field + self._reset(mark) + if t := self.TSTRING_MIDDLE(): + tok = self._tokenizer.get_last_non_whitespace_token() + end_lineno, end_col_offset = tok.end + return ast.Constant( + value=self._decode_tstring_literal( + t.string, raw=self._is_raw_tstring() + ), + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) + self._reset(mark) + return None + + @memoize + def tstring_replacement_field(self) -> Optional[Any]: + # tstring_replacement_field: '{' annotated_rhs '='? fstring_conversion? tstring_full_format_spec? '}' | invalid_tstring_replacement_field mark = self._mark() if ( - (a := self._loop1_148()) + (lbrace := self.expect("{")) + and (a := self.annotated_rhs()) + and (debug_expr := self.expect("="),) + and (conversion := self.fstring_conversion(),) + and (format := self.tstring_full_format_spec(),) + and (rbrace := self.expect("}")) ): - return self . concatenate_strings ( a ) if sys . version_info >= ( 3 , 12 ) else self . generate_ast_for_string ( a ); + return self.tstring_debug_value( + a, lbrace, debug_expr, conversion, format, rbrace + ) self._reset(mark) - return None; + if self.call_invalid_rules and (self.invalid_tstring_replacement_field()): + return None # pragma: no cover + self._reset(mark) + return None @memoize - def list(self) -> Optional[ast . List]: - # list: '[' star_named_expressions? ']' + def tstring_full_format_spec(self) -> Optional[Any]: + # tstring_full_format_spec: ':' tstring_format_spec* + mark = self._mark() + tok = self._tokenizer.peek() + start_lineno, start_col_offset = tok.start + if (self.expect(":")) and (spec := self._loop0_147(),): + tok = self._tokenizer.get_last_non_whitespace_token() + end_lineno, end_col_offset = tok.end + return ast.JoinedStr( + values=self._flatten_joinedstr_values(spec), + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) + self._reset(mark) + return None + + @memoize + def tstring_format_spec(self) -> Optional[Any]: + # tstring_format_spec: TSTRING_MIDDLE | fstring_replacement_field + mark = self._mark() + tok = self._tokenizer.peek() + start_lineno, start_col_offset = tok.start + if t := self.TSTRING_MIDDLE(): + tok = self._tokenizer.get_last_non_whitespace_token() + end_lineno, end_col_offset = tok.end + return ast.Constant( + value=self._decode_tstring_literal( + t.string, raw=self._is_raw_tstring() + ), + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) + self._reset(mark) + if fstring_replacement_field := self.fstring_replacement_field(): + return fstring_replacement_field + self._reset(mark) + return None + + @memoize + def tstring(self) -> Optional[Any]: + # tstring: TSTRING_START tstring_mid* TSTRING_END mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start if ( - (self.expect('[')) - and - (a := self.star_named_expressions(),) - and - (self.expect(']')) + (self.TSTRING_START()) + and (b := self._loop0_148(),) + and (self.TSTRING_END()) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . List ( elts = a or [] , ctx = Load , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.TemplateStr( + values=self._flatten_joinedstr_values(b), + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - return None; + return None @memoize - def tuple(self) -> Optional[ast . Tuple]: - # tuple: '(' [star_named_expression ',' star_named_expressions?] ')' + def strings(self) -> Optional[Any]: + # strings: invalid_string_tstring_concat | ((fstring | STRING))+ | tstring+ + mark = self._mark() + if self.call_invalid_rules and (self.invalid_string_tstring_concat()): + return None # pragma: no cover + self._reset(mark) + if a := self._loop1_149(): + return ( + self.concatenate_strings(a) + if sys.version_info >= (3, 12) + else self.generate_ast_for_string(a) + ) + self._reset(mark) + if a := self._loop1_150(): + return ( + self.concatenate_strings(a) + if sys.version_info >= (3, 12) + else self.generate_ast_for_string(a) + ) + self._reset(mark) + return None + + @memoize + def list(self) -> Optional[ast.List]: + # list: '[' star_named_expressions? ']' mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start if ( - (self.expect('(')) - and - (a := self._tmp_149(),) - and - (self.expect(')')) + (self.expect("[")) + and (a := self.star_named_expressions(),) + and (self.expect("]")) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . Tuple ( elts = a or [] , ctx = Load , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.List( + elts=a or [], + ctx=Load, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) + self._reset(mark) + return None + + @memoize + def tuple(self) -> Optional[ast.Tuple]: + # tuple: '(' [star_named_expression ',' star_named_expressions?] ')' + mark = self._mark() + tok = self._tokenizer.peek() + start_lineno, start_col_offset = tok.start + if (self.expect("(")) and (a := self._tmp_151(),) and (self.expect(")")): + tok = self._tokenizer.get_last_non_whitespace_token() + end_lineno, end_col_offset = tok.end + return ast.Tuple( + elts=a or [], + ctx=Load, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - return None; + return None @memoize - def set(self) -> Optional[ast . Set]: + def set(self) -> Optional[ast.Set]: # set: '{' star_named_expressions '}' mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start if ( - (self.expect('{')) - and - (a := self.star_named_expressions()) - and - (self.expect('}')) + (self.expect("{")) + and (a := self.star_named_expressions()) + and (self.expect("}")) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . Set ( elts = a , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.Set( + elts=a, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - return None; + return None @memoize - def dict(self) -> Optional[ast . Dict]: + def dict(self) -> Optional[ast.Dict]: # dict: '{' double_starred_kvpairs? '}' | '{' invalid_double_starred_kvpairs '}' mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start if ( - (self.expect('{')) - and - (a := self.double_starred_kvpairs(),) - and - (self.expect('}')) + (self.expect("{")) + and (a := self.double_starred_kvpairs(),) + and (self.expect("}")) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . Dict ( keys = [kv [0] for kv in ( a or [] )] , values = [kv [1] for kv in ( a or [] )] , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.Dict( + keys=[kv[0] for kv in (a or [])], + values=[kv[1] for kv in (a or [])], + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) if ( self.call_invalid_rules - and - (self.expect('{')) - and - (self.invalid_double_starred_kvpairs()) - and - (self.expect('}')) + and (self.expect("{")) + and (self.invalid_double_starred_kvpairs()) + and (self.expect("}")) ): - return None # pragma: no cover; + return None # pragma: no cover self._reset(mark) - return None; + return None @memoize def double_starred_kvpairs(self) -> Optional[list]: # double_starred_kvpairs: ','.double_starred_kvpair+ ','? mark = self._mark() - if ( - (a := self._gather_150()) - and - (self.expect(','),) - ): - return a; + if (a := self._gather_152()) and (self.expect(","),): + return a self._reset(mark) - return None; + return None @memoize def double_starred_kvpair(self) -> Optional[Any]: # double_starred_kvpair: '**' bitwise_or | kvpair mark = self._mark() - if ( - (self.expect('**')) - and - (a := self.bitwise_or()) - ): - return ( None , a ); + if (self.expect("**")) and (a := self.bitwise_or()): + return (None, a) self._reset(mark) - if ( - (kvpair := self.kvpair()) - ): - return kvpair; + if kvpair := self.kvpair(): + return kvpair self._reset(mark) - return None; + return None @memoize def kvpair(self) -> Optional[tuple]: # kvpair: expression ':' expression mark = self._mark() - if ( - (a := self.expression()) - and - (self.expect(':')) - and - (b := self.expression()) - ): - return ( a , b ); + if (a := self.expression()) and (self.expect(":")) and (b := self.expression()): + return (a, b) self._reset(mark) - return None; + return None @memoize - def for_if_clauses(self) -> Optional[List [ast . comprehension]]: + def for_if_clauses(self) -> Optional[List[ast.comprehension]]: # for_if_clauses: for_if_clause+ mark = self._mark() - if ( - (a := self._loop1_152()) - ): - return a; + if a := self._loop1_154(): + return a self._reset(mark) - return None; + return None @memoize - def for_if_clause(self) -> Optional[ast . comprehension]: + def for_if_clause(self) -> Optional[ast.comprehension]: # for_if_clause: 'async' 'for' star_targets 'in' ~ disjunction (('if' disjunction))* | 'for' star_targets 'in' ~ disjunction (('if' disjunction))* | invalid_for_target mark = self._mark() cut = False if ( - (self.expect('async')) - and - (self.expect('for')) - and - (a := self.star_targets()) - and - (self.expect('in')) - and - (cut := True) - and - (b := self.disjunction()) - and - (c := self._loop0_153(),) - ): - return self . check_version ( ( 3 , 6 ) , "Async comprehensions are" , ast . comprehension ( target = a , iter = b , ifs = c , is_async = 1 ) ); + (self.expect("async")) + and (self.expect("for")) + and (a := self.star_targets()) + and (self.expect("in")) + and (cut := True) + and (b := self.disjunction()) + and (c := self._loop0_155(),) + ): + return self.check_version( + (3, 6), + "Async comprehensions are", + ast.comprehension(target=a, iter=b, ifs=c, is_async=1), + ) self._reset(mark) if cut: - return None; + return None cut = False if ( - (self.expect('for')) - and - (a := self.star_targets()) - and - (self.expect('in')) - and - (cut := True) - and - (b := self.disjunction()) - and - (c := self._loop0_154(),) + (self.expect("for")) + and (a := self.star_targets()) + and (self.expect("in")) + and (cut := True) + and (b := self.disjunction()) + and (c := self._loop0_156(),) ): - return ast . comprehension ( target = a , iter = b , ifs = c , is_async = 0 ); + return ast.comprehension(target=a, iter=b, ifs=c, is_async=0) self._reset(mark) if cut: - return None; - if ( - self.call_invalid_rules - and - (self.invalid_for_target()) - ): - return None # pragma: no cover; + return None + if self.call_invalid_rules and (self.invalid_for_target()): + return None # pragma: no cover self._reset(mark) - return None; + return None @memoize - def listcomp(self) -> Optional[ast . ListComp]: + def listcomp(self) -> Optional[ast.ListComp]: # listcomp: '[' named_expression for_if_clauses ']' | invalid_comprehension mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start if ( - (self.expect('[')) - and - (a := self.named_expression()) - and - (b := self.for_if_clauses()) - and - (self.expect(']')) + (self.expect("[")) + and (a := self.named_expression()) + and (b := self.for_if_clauses()) + and (self.expect("]")) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . ListComp ( elt = a , generators = b , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.ListComp( + elt=a, + generators=b, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - if ( - self.call_invalid_rules - and - (self.invalid_comprehension()) - ): - return None # pragma: no cover; + if self.call_invalid_rules and (self.invalid_comprehension()): + return None # pragma: no cover self._reset(mark) - return None; + return None @memoize - def setcomp(self) -> Optional[ast . SetComp]: + def setcomp(self) -> Optional[ast.SetComp]: # setcomp: '{' named_expression for_if_clauses '}' | invalid_comprehension mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start if ( - (self.expect('{')) - and - (a := self.named_expression()) - and - (b := self.for_if_clauses()) - and - (self.expect('}')) + (self.expect("{")) + and (a := self.named_expression()) + and (b := self.for_if_clauses()) + and (self.expect("}")) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . SetComp ( elt = a , generators = b , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.SetComp( + elt=a, + generators=b, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - if ( - self.call_invalid_rules - and - (self.invalid_comprehension()) - ): - return None # pragma: no cover; + if self.call_invalid_rules and (self.invalid_comprehension()): + return None # pragma: no cover self._reset(mark) - return None; + return None @memoize - def genexp(self) -> Optional[ast . GeneratorExp]: + def genexp(self) -> Optional[ast.GeneratorExp]: # genexp: '(' (assignment_expression | expression !':=') for_if_clauses ')' | invalid_comprehension mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start if ( - (self.expect('(')) - and - (a := self._tmp_155()) - and - (b := self.for_if_clauses()) - and - (self.expect(')')) + (self.expect("(")) + and (a := self._tmp_157()) + and (b := self.for_if_clauses()) + and (self.expect(")")) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . GeneratorExp ( elt = a , generators = b , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.GeneratorExp( + elt=a, + generators=b, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - if ( - self.call_invalid_rules - and - (self.invalid_comprehension()) - ): - return None # pragma: no cover; + if self.call_invalid_rules and (self.invalid_comprehension()): + return None # pragma: no cover self._reset(mark) - return None; + return None @memoize - def dictcomp(self) -> Optional[ast . DictComp]: + def dictcomp(self) -> Optional[ast.DictComp]: # dictcomp: '{' kvpair for_if_clauses '}' | invalid_dict_comprehension mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start if ( - (self.expect('{')) - and - (a := self.kvpair()) - and - (b := self.for_if_clauses()) - and - (self.expect('}')) + (self.expect("{")) + and (a := self.kvpair()) + and (b := self.for_if_clauses()) + and (self.expect("}")) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . DictComp ( key = a [0] , value = a [1] , generators = b , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.DictComp( + key=a[0], + value=a[1], + generators=b, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - if ( - self.call_invalid_rules - and - (self.invalid_dict_comprehension()) - ): - return None # pragma: no cover; + if self.call_invalid_rules and (self.invalid_dict_comprehension()): + return None # pragma: no cover self._reset(mark) - return None; + return None @memoize - def arguments(self) -> Optional[Tuple [list , list]]: + def arguments(self) -> Optional[Tuple[list, list]]: # arguments: args ','? &')' | invalid_arguments mark = self._mark() if ( (a := self.args()) - and - (self.expect(','),) - and - (self.positive_lookahead(self.expect, ')')) + and (self.expect(","),) + and (self.positive_lookahead(self.expect, ")")) ): - return a; + return a self._reset(mark) - if ( - self.call_invalid_rules - and - (self.invalid_arguments()) - ): - return None # pragma: no cover; + if self.call_invalid_rules and (self.invalid_arguments()): + return None # pragma: no cover self._reset(mark) - return None; + return None @memoize - def args(self) -> Optional[Tuple [list , list]]: + def args(self) -> Optional[Tuple[list, list]]: # args: ','.(starred_expression | (assignment_expression | expression !':=') !'=')+ [',' kwargs] | kwargs mark = self._mark() - if ( - (a := self._gather_156()) - and - (b := self._tmp_158(),) - ): - return ( a + ( [e for e in b if isinstance ( e , ast . Starred )] if b else [] ) , ( [e for e in b if not isinstance ( e , ast . Starred )] if b else [] ) ); + if (a := self._gather_158()) and (b := self._tmp_160(),): + return ( + a + ([e for e in b if isinstance(e, ast.Starred)] if b else []), + ([e for e in b if not isinstance(e, ast.Starred)] if b else []), + ) self._reset(mark) - if ( - (a := self.kwargs()) - ): - return ( [e for e in a if isinstance ( e , ast . Starred )] , [e for e in a if not isinstance ( e , ast . Starred )] ); + if a := self.kwargs(): + return ( + [e for e in a if isinstance(e, ast.Starred)], + [e for e in a if not isinstance(e, ast.Starred)], + ) self._reset(mark) - return None; + return None @memoize def kwargs(self) -> Optional[list]: # kwargs: ','.kwarg_or_starred+ ',' ','.kwarg_or_double_starred+ | ','.kwarg_or_starred+ | ','.kwarg_or_double_starred+ mark = self._mark() if ( - (a := self._gather_159()) - and - (self.expect(',')) - and - (b := self._gather_161()) + (a := self._gather_161()) + and (self.expect(",")) + and (b := self._gather_163()) ): - return a + b; + return a + b self._reset(mark) - if ( - (_gather_163 := self._gather_163()) - ): - return _gather_163; + if _gather_165 := self._gather_165(): + return _gather_165 self._reset(mark) - if ( - (_gather_165 := self._gather_165()) - ): - return _gather_165; + if _gather_167 := self._gather_167(): + return _gather_167 self._reset(mark) - return None; + return None @memoize def starred_expression(self) -> Optional[Any]: @@ -5637,23 +6147,22 @@ def starred_expression(self) -> Optional[Any]: mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - self.call_invalid_rules - and - (self.invalid_starred_expression()) - ): - return None # pragma: no cover; + if self.call_invalid_rules and (self.invalid_starred_expression()): + return None # pragma: no cover self._reset(mark) - if ( - (self.expect('*')) - and - (a := self.expression()) - ): + if (self.expect("*")) and (a := self.expression()): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . Starred ( value = a , ctx = Load , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.Starred( + value=a, + ctx=Load, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - return None; + return None @memoize def kwarg_or_starred(self) -> Optional[Any]: @@ -5661,30 +6170,25 @@ def kwarg_or_starred(self) -> Optional[Any]: mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - self.call_invalid_rules - and - (self.invalid_kwarg()) - ): - return None # pragma: no cover; + if self.call_invalid_rules and (self.invalid_kwarg()): + return None # pragma: no cover self._reset(mark) - if ( - (a := self.name()) - and - (self.expect('=')) - and - (b := self.expression()) - ): + if (a := self.name()) and (self.expect("=")) and (b := self.expression()): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . keyword ( arg = a . string , value = b , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.keyword( + arg=a.string, + value=b, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - if ( - (a := self.starred_expression()) - ): - return a; + if a := self.starred_expression(): + return a self._reset(mark) - return None; + return None @memoize def kwarg_or_double_starred(self) -> Optional[Any]: @@ -5692,34 +6196,34 @@ def kwarg_or_double_starred(self) -> Optional[Any]: mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - self.call_invalid_rules - and - (self.invalid_kwarg()) - ): - return None # pragma: no cover; + if self.call_invalid_rules and (self.invalid_kwarg()): + return None # pragma: no cover self._reset(mark) - if ( - (a := self.name()) - and - (self.expect('=')) - and - (b := self.expression()) - ): + if (a := self.name()) and (self.expect("=")) and (b := self.expression()): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . keyword ( arg = a . string , value = b , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.keyword( + arg=a.string, + value=b, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - if ( - (self.expect('**')) - and - (a := self.expression()) - ): + if (self.expect("**")) and (a := self.expression()): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . keyword ( arg = None , value = a , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.keyword( + arg=None, + value=a, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - return None; + return None @memoize def star_targets(self) -> Optional[Any]: @@ -5727,38 +6231,35 @@ def star_targets(self) -> Optional[Any]: mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - (a := self.star_target()) - and - (self.negative_lookahead(self.expect, ',')) - ): - return a; + if (a := self.star_target()) and (self.negative_lookahead(self.expect, ",")): + return a self._reset(mark) if ( (a := self.star_target()) - and - (b := self._loop0_167(),) - and - (self.expect(','),) + and (b := self._loop0_169(),) + and (self.expect(","),) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . Tuple ( elts = [a] + b , ctx = Store , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.Tuple( + elts=[a] + b, + ctx=Store, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - return None; + return None @memoize def star_targets_list_seq(self) -> Optional[list]: # star_targets_list_seq: ','.star_target+ ','? mark = self._mark() - if ( - (a := self._gather_168()) - and - (self.expect(','),) - ): - return a; + if (a := self._gather_170()) and (self.expect(","),): + return a self._reset(mark) - return None; + return None @memoize def star_targets_tuple_seq(self) -> Optional[list]: @@ -5766,21 +6267,15 @@ def star_targets_tuple_seq(self) -> Optional[list]: mark = self._mark() if ( (a := self.star_target()) - and - (b := self._loop1_170()) - and - (self.expect(','),) + and (b := self._loop1_172()) + and (self.expect(","),) ): - return [a] + b; + return [a] + b self._reset(mark) - if ( - (a := self.star_target()) - and - (self.expect(',')) - ): - return [a]; + if (a := self.star_target()) and (self.expect(",")): + return [a] self._reset(mark) - return None; + return None @memoize def star_target(self) -> Optional[Any]: @@ -5788,21 +6283,22 @@ def star_target(self) -> Optional[Any]: mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - (self.expect('*')) - and - (a := self._tmp_171()) - ): + if (self.expect("*")) and (a := self._tmp_173()): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . Starred ( value = self . set_expr_context ( a , Store ) , ctx = Store , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.Starred( + value=self.set_expr_context(a, Store), + ctx=Store, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - if ( - (target_with_star_atom := self.target_with_star_atom()) - ): - return target_with_star_atom; + if target_with_star_atom := self.target_with_star_atom(): + return target_with_star_atom self._reset(mark) - return None; + return None @memoize def target_with_star_atom(self) -> Optional[Any]: @@ -5812,38 +6308,53 @@ def target_with_star_atom(self) -> Optional[Any]: start_lineno, start_col_offset = tok.start if ( (a := self.t_primary()) - and - (self.expect('.')) - and - (b := self.name()) - and - (self.negative_lookahead(self.t_lookahead, )) + and (self.expect(".")) + and (b := self.name()) + and ( + self.negative_lookahead( + self.t_lookahead, + ) + ) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . Attribute ( value = a , attr = b . string , ctx = Store , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.Attribute( + value=a, + attr=b.string, + ctx=Store, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) if ( (a := self.t_primary()) - and - (self.expect('[')) - and - (b := self.slices()) - and - (self.expect(']')) - and - (self.negative_lookahead(self.t_lookahead, )) + and (self.expect("[")) + and (b := self.slices()) + and (self.expect("]")) + and ( + self.negative_lookahead( + self.t_lookahead, + ) + ) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . Subscript ( value = a , slice = b , ctx = Store , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.Subscript( + value=a, + slice=b, + ctx=Store, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - if ( - (star_atom := self.star_atom()) - ): - return star_atom; + if star_atom := self.star_atom(): + return star_atom self._reset(mark) - return None; + return None @memoize def star_atom(self) -> Optional[Any]: @@ -5851,45 +6362,58 @@ def star_atom(self) -> Optional[Any]: mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - (a := self.name()) - ): + if a := self.name(): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . Name ( id = a . string , ctx = Store , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.Name( + id=a.string, + ctx=Store, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) if ( - (self.expect('(')) - and - (a := self.target_with_star_atom()) - and - (self.expect(')')) + (self.expect("(")) + and (a := self.target_with_star_atom()) + and (self.expect(")")) ): - return self . set_expr_context ( a , Store ); + return self.set_expr_context(a, Store) self._reset(mark) if ( - (self.expect('(')) - and - (a := self.star_targets_tuple_seq(),) - and - (self.expect(')')) + (self.expect("(")) + and (a := self.star_targets_tuple_seq(),) + and (self.expect(")")) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . Tuple ( elts = a , ctx = Store , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.Tuple( + elts=a, + ctx=Store, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) if ( - (self.expect('[')) - and - (a := self.star_targets_list_seq(),) - and - (self.expect(']')) + (self.expect("[")) + and (a := self.star_targets_list_seq(),) + and (self.expect("]")) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . List ( elts = a , ctx = Store , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.List( + elts=a, + ctx=Store, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - return None; + return None @memoize def single_target(self) -> Optional[Any]: @@ -5898,27 +6422,27 @@ def single_target(self) -> Optional[Any]: tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start if ( - (single_subscript_attribute_target := self.single_subscript_attribute_target()) + single_subscript_attribute_target + := self.single_subscript_attribute_target() ): - return single_subscript_attribute_target; + return single_subscript_attribute_target self._reset(mark) - if ( - (a := self.name()) - ): + if a := self.name(): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . Name ( id = a . string , ctx = Store , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.Name( + id=a.string, + ctx=Store, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - if ( - (self.expect('(')) - and - (a := self.single_target()) - and - (self.expect(')')) - ): - return a; + if (self.expect("(")) and (a := self.single_target()) and (self.expect(")")): + return a self._reset(mark) - return None; + return None @memoize def single_subscript_attribute_target(self) -> Optional[Any]: @@ -5928,33 +6452,50 @@ def single_subscript_attribute_target(self) -> Optional[Any]: start_lineno, start_col_offset = tok.start if ( (a := self.t_primary()) - and - (self.expect('.')) - and - (b := self.name()) - and - (self.negative_lookahead(self.t_lookahead, )) + and (self.expect(".")) + and (b := self.name()) + and ( + self.negative_lookahead( + self.t_lookahead, + ) + ) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . Attribute ( value = a , attr = b . string , ctx = Store , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.Attribute( + value=a, + attr=b.string, + ctx=Store, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) if ( (a := self.t_primary()) - and - (self.expect('[')) - and - (b := self.slices()) - and - (self.expect(']')) - and - (self.negative_lookahead(self.t_lookahead, )) + and (self.expect("[")) + and (b := self.slices()) + and (self.expect("]")) + and ( + self.negative_lookahead( + self.t_lookahead, + ) + ) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . Subscript ( value = a , slice = b , ctx = Store , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.Subscript( + value=a, + slice=b, + ctx=Store, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - return None; + return None @memoize_left_rec def t_primary(self) -> Optional[Any]: @@ -5964,100 +6505,125 @@ def t_primary(self) -> Optional[Any]: start_lineno, start_col_offset = tok.start if ( (a := self.t_primary()) - and - (self.expect('.')) - and - (b := self.name()) - and - (self.positive_lookahead(self.t_lookahead, )) + and (self.expect(".")) + and (b := self.name()) + and ( + self.positive_lookahead( + self.t_lookahead, + ) + ) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . Attribute ( value = a , attr = b . string , ctx = Load , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.Attribute( + value=a, + attr=b.string, + ctx=Load, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) if ( (a := self.t_primary()) - and - (self.expect('[')) - and - (b := self.slices()) - and - (self.expect(']')) - and - (self.positive_lookahead(self.t_lookahead, )) + and (self.expect("[")) + and (b := self.slices()) + and (self.expect("]")) + and ( + self.positive_lookahead( + self.t_lookahead, + ) + ) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . Subscript ( value = a , slice = b , ctx = Load , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.Subscript( + value=a, + slice=b, + ctx=Load, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) if ( (a := self.t_primary()) - and - (b := self.genexp()) - and - (self.positive_lookahead(self.t_lookahead, )) + and (b := self.genexp()) + and ( + self.positive_lookahead( + self.t_lookahead, + ) + ) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . Call ( func = a , args = [b] , keywords = [] , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.Call( + func=a, + args=[b], + keywords=[], + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) if ( (a := self.t_primary()) - and - (self.expect('(')) - and - (b := self.arguments(),) - and - (self.expect(')')) - and - (self.positive_lookahead(self.t_lookahead, )) + and (self.expect("(")) + and (b := self.arguments(),) + and (self.expect(")")) + and ( + self.positive_lookahead( + self.t_lookahead, + ) + ) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . Call ( func = a , args = b [0] if b else [] , keywords = b [1] if b else [] , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset , ); + return ast.Call( + func=a, + args=b[0] if b else [], + keywords=b[1] if b else [], + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - if ( - (a := self.atom()) - and - (self.positive_lookahead(self.t_lookahead, )) + if (a := self.atom()) and ( + self.positive_lookahead( + self.t_lookahead, + ) ): - return a; + return a self._reset(mark) - return None; + return None @memoize def t_lookahead(self) -> Optional[Any]: # t_lookahead: '(' | '[' | '.' mark = self._mark() - if ( - (literal := self.expect('(')) - ): - return literal; + if literal := self.expect("("): + return literal self._reset(mark) - if ( - (literal := self.expect('[')) - ): - return literal; + if literal := self.expect("["): + return literal self._reset(mark) - if ( - (literal := self.expect('.')) - ): - return literal; + if literal := self.expect("."): + return literal self._reset(mark) - return None; + return None @memoize def del_targets(self) -> Optional[Any]: # del_targets: ','.del_target+ ','? mark = self._mark() - if ( - (a := self._gather_172()) - and - (self.expect(','),) - ): - return a; + if (a := self._gather_174()) and (self.expect(","),): + return a self._reset(mark) - return None; + return None @memoize def del_target(self) -> Optional[Any]: @@ -6067,38 +6633,53 @@ def del_target(self) -> Optional[Any]: start_lineno, start_col_offset = tok.start if ( (a := self.t_primary()) - and - (self.expect('.')) - and - (b := self.name()) - and - (self.negative_lookahead(self.t_lookahead, )) + and (self.expect(".")) + and (b := self.name()) + and ( + self.negative_lookahead( + self.t_lookahead, + ) + ) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . Attribute ( value = a , attr = b . string , ctx = Del , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.Attribute( + value=a, + attr=b.string, + ctx=Del, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) if ( (a := self.t_primary()) - and - (self.expect('[')) - and - (b := self.slices()) - and - (self.expect(']')) - and - (self.negative_lookahead(self.t_lookahead, )) + and (self.expect("[")) + and (b := self.slices()) + and (self.expect("]")) + and ( + self.negative_lookahead( + self.t_lookahead, + ) + ) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . Subscript ( value = a , slice = b , ctx = Del , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.Subscript( + value=a, + slice=b, + ctx=Del, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - if ( - (del_t_atom := self.del_t_atom()) - ): - return del_t_atom; + if del_t_atom := self.del_t_atom(): + return del_t_atom self._reset(mark) - return None; + return None @memoize def del_t_atom(self) -> Optional[Any]: @@ -6106,271 +6687,247 @@ def del_t_atom(self) -> Optional[Any]: mark = self._mark() tok = self._tokenizer.peek() start_lineno, start_col_offset = tok.start - if ( - (a := self.name()) - ): + if a := self.name(): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . Name ( id = a . string , ctx = Del , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.Name( + id=a.string, + ctx=Del, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - if ( - (self.expect('(')) - and - (a := self.del_target()) - and - (self.expect(')')) - ): - return self . set_expr_context ( a , Del ); + if (self.expect("(")) and (a := self.del_target()) and (self.expect(")")): + return self.set_expr_context(a, Del) self._reset(mark) - if ( - (self.expect('(')) - and - (a := self.del_targets(),) - and - (self.expect(')')) - ): + if (self.expect("(")) and (a := self.del_targets(),) and (self.expect(")")): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . Tuple ( elts = a , ctx = Del , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.Tuple( + elts=a, + ctx=Del, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - if ( - (self.expect('[')) - and - (a := self.del_targets(),) - and - (self.expect(']')) - ): + if (self.expect("[")) and (a := self.del_targets(),) and (self.expect("]")): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end - return ast . List ( elts = a , ctx = Del , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); + return ast.List( + elts=a, + ctx=Del, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) self._reset(mark) - return None; + return None @memoize def type_expressions(self) -> Optional[list]: # type_expressions: ','.expression+ ',' '*' expression ',' '**' expression | ','.expression+ ',' '*' expression | ','.expression+ ',' '**' expression | '*' expression ',' '**' expression | '*' expression | '**' expression | ','.expression+ mark = self._mark() - if ( - (a := self._gather_174()) - and - (self.expect(',')) - and - (self.expect('*')) - and - (b := self.expression()) - and - (self.expect(',')) - and - (self.expect('**')) - and - (c := self.expression()) - ): - return a + [b , c]; - self._reset(mark) if ( (a := self._gather_176()) - and - (self.expect(',')) - and - (self.expect('*')) - and - (b := self.expression()) + and (self.expect(",")) + and (self.expect("*")) + and (b := self.expression()) + and (self.expect(",")) + and (self.expect("**")) + and (c := self.expression()) ): - return a + [b]; + return a + [b, c] self._reset(mark) if ( (a := self._gather_178()) - and - (self.expect(',')) - and - (self.expect('**')) - and - (b := self.expression()) + and (self.expect(",")) + and (self.expect("*")) + and (b := self.expression()) ): - return a + [b]; + return a + [b] self._reset(mark) if ( - (self.expect('*')) - and - (a := self.expression()) - and - (self.expect(',')) - and - (self.expect('**')) - and - (b := self.expression()) + (a := self._gather_180()) + and (self.expect(",")) + and (self.expect("**")) + and (b := self.expression()) ): - return [a , b]; + return a + [b] self._reset(mark) if ( - (self.expect('*')) - and - (a := self.expression()) + (self.expect("*")) + and (a := self.expression()) + and (self.expect(",")) + and (self.expect("**")) + and (b := self.expression()) ): - return [a]; + return [a, b] self._reset(mark) - if ( - (self.expect('**')) - and - (a := self.expression()) - ): - return [a]; + if (self.expect("*")) and (a := self.expression()): + return [a] self._reset(mark) - if ( - (a := self._gather_180()) - ): - return a; + if (self.expect("**")) and (a := self.expression()): + return [a] self._reset(mark) - return None; + if a := self._gather_182(): + return a + self._reset(mark) + return None @memoize def func_type_comment(self) -> Optional[Any]: # func_type_comment: NEWLINE TYPE_COMMENT &(NEWLINE INDENT) | invalid_double_type_comments | TYPE_COMMENT mark = self._mark() if ( - (self.expect('NEWLINE')) - and - (t := self.type_comment()) - and - (self.positive_lookahead(self._tmp_182, )) + (self.expect("NEWLINE")) + and (t := self.type_comment()) + and ( + self.positive_lookahead( + self._tmp_184, + ) + ) ): - return t . string; + return t.string self._reset(mark) - if ( - self.call_invalid_rules - and - (self.invalid_double_type_comments()) - ): - return None # pragma: no cover; + if self.call_invalid_rules and (self.invalid_double_type_comments()): + return None # pragma: no cover self._reset(mark) - if ( - (type_comment := self.type_comment()) - ): - return type_comment; + if type_comment := self.type_comment(): + return type_comment self._reset(mark) - return None; + return None @memoize def invalid_arguments(self) -> Optional[NoReturn]: - # invalid_arguments: args ',' '*' | expression for_if_clauses ',' [args | expression for_if_clauses] | NAME '=' expression for_if_clauses | [(args ',')] NAME '=' &(',' | ')') | args for_if_clauses | args ',' expression for_if_clauses | args ',' args + # invalid_arguments: ((','.(starred_expression | (assignment_expression | expression !':=') !'=')+ ',' kwargs) | kwargs) ',' ','.(starred_expression !'=')+ | expression for_if_clauses ',' [args | expression for_if_clauses] | NAME '=' expression for_if_clauses | [(args ',')] NAME '=' &(',' | ')') | args for_if_clauses | args ',' expression for_if_clauses | args ',' args mark = self._mark() - if ( - (a := self.args()) - and - (self.expect(',')) - and - (self.expect('*')) - ): - return self . raise_syntax_error_known_location ( "iterable argument unpacking follows keyword argument unpacking" , a [1] [- 1] if a [1] else a [0] [- 1] , ); + if (self._tmp_185()) and (a := self.expect(",")) and (self._gather_186()): + return self.raise_syntax_error_starting_from( + "iterable argument unpacking follows keyword argument unpacking", + a, + ) self._reset(mark) if ( (a := self.expression()) - and - (b := self.for_if_clauses()) - and - (self.expect(',')) - and - (self._tmp_183(),) - ): - return self . raise_syntax_error_known_range ( "Generator expression must be parenthesized" , a , ( b [- 1] . ifs [- 1] if b [- 1] . ifs else b [- 1] . iter ) ); - self._reset(mark) - if ( - (a := self.name()) - and - (b := self.expect('=')) - and - (self.expression()) - and - (self.for_if_clauses()) + and (b := self.for_if_clauses()) + and (self.expect(",")) + and (self._tmp_188(),) ): - return self . raise_syntax_error_known_range ( "invalid syntax. Maybe you meant '==' or ':=' instead of '='?" , a , b ); + return self.raise_syntax_error_known_range( + "Generator expression must be parenthesized", + a, + (b[-1].ifs[-1] if b[-1].ifs else b[-1].iter), + ) self._reset(mark) if ( - (self._tmp_184(),) - and (a := self.name()) - and - (b := self.expect('=')) - and - (self.positive_lookahead(self._tmp_185, )) - ): - return self . raise_syntax_error_known_range ( "expected argument value expression" , a , b ); - self._reset(mark) - if ( - (a := self.args()) - and - (b := self.for_if_clauses()) - ): - return self . raise_syntax_error_known_range ( "Generator expression must be parenthesized" , a [0] [- 1] , ( b [- 1] . ifs [- 1] if b [- 1] . ifs else b [- 1] . iter ) , ) if len ( a [0] ) > 1 else None; + and (b := self.expect("=")) + and (self.expression()) + and (self.for_if_clauses()) + ): + return self.raise_syntax_error_known_range( + "invalid syntax. Maybe you meant '==' or ':=' instead of '='?", a, b + ) + self._reset(mark) + if ( + (self._tmp_189(),) + and (a := self.name()) + and (b := self.expect("=")) + and ( + self.positive_lookahead( + self._tmp_190, + ) + ) + ): + return self.raise_syntax_error_known_range( + "expected argument value expression", a, b + ) + self._reset(mark) + if (a := self.args()) and (b := self.for_if_clauses()): + return ( + self.raise_syntax_error_known_range( + "Generator expression must be parenthesized", + a[0][-1], + (b[-1].ifs[-1] if b[-1].ifs else b[-1].iter), + ) + if len(a[0]) > 1 + else None + ) self._reset(mark) if ( (self.args()) - and - (self.expect(',')) - and - (a := self.expression()) - and - (b := self.for_if_clauses()) + and (self.expect(",")) + and (a := self.expression()) + and (b := self.for_if_clauses()) ): - return self . raise_syntax_error_known_range ( "Generator expression must be parenthesized" , a , ( b [- 1] . ifs [- 1] if b [- 1] . ifs else b [- 1] . iter ) , ); + return self.raise_syntax_error_known_range( + "Generator expression must be parenthesized", + a, + (b[-1].ifs[-1] if b[-1].ifs else b[-1].iter), + ) self._reset(mark) - if ( - (a := self.args()) - and - (self.expect(',')) - and - (self.args()) - ): - return self . raise_syntax_error ( "positional argument follows keyword argument unpacking" if a [1] [- 1] . arg is None else "positional argument follows keyword argument" , ); + if (a := self.args()) and (self.expect(",")) and (self.args()): + return self.raise_syntax_error( + "positional argument follows keyword argument unpacking" + if a[1][-1].arg is None + else "positional argument follows keyword argument", + ) self._reset(mark) - return None; + return None @memoize def invalid_kwarg(self) -> Optional[NoReturn]: # invalid_kwarg: ('True' | 'False' | 'None') '=' | NAME '=' expression for_if_clauses | !(NAME '=') expression '=' | '**' expression '=' expression mark = self._mark() - if ( - (a := self._tmp_186()) - and - (b := self.expect('=')) - ): - return self . raise_syntax_error_known_range ( f"cannot assign to {a.string}" , a , b ); + if (a := self._tmp_191()) and (b := self.expect("=")): + return self.raise_syntax_error_known_range( + f"cannot assign to {a.string}", a, b + ) self._reset(mark) if ( (a := self.name()) - and - (b := self.expect('=')) - and - (self.expression()) - and - (self.for_if_clauses()) + and (b := self.expect("=")) + and (self.expression()) + and (self.for_if_clauses()) ): - return self . raise_syntax_error_known_range ( "invalid syntax. Maybe you meant '==' or ':=' instead of '='?" , a , b ); + return self.raise_syntax_error_known_range( + "invalid syntax. Maybe you meant '==' or ':=' instead of '='?", a, b + ) self._reset(mark) if ( - (self.negative_lookahead(self._tmp_187, )) - and - (a := self.expression()) - and - (b := self.expect('=')) + ( + self.negative_lookahead( + self._tmp_192, + ) + ) + and (a := self.expression()) + and (b := self.expect("=")) ): - return self . raise_syntax_error_known_range ( "expression cannot contain assignment, perhaps you meant \"==\"?" , a , b , ); + return self.raise_syntax_error_known_range( + 'expression cannot contain assignment, perhaps you meant "=="?', + a, + b, + ) self._reset(mark) if ( - (a := self.expect('**')) - and - (self.expression()) - and - (self.expect('=')) - and - (b := self.expression()) + (a := self.expect("**")) + and (self.expression()) + and (self.expect("=")) + and (b := self.expression()) ): - return self . raise_syntax_error_known_range ( "cannot assign to keyword argument unpacking" , a , b ); + return self.raise_syntax_error_known_range( + "cannot assign to keyword argument unpacking", a, b + ) self._reset(mark) - return None; + return None @memoize - def expression_without_invalid(self) -> Optional[ast . AST]: + def expression_without_invalid(self) -> Optional[ast.AST]: # expression_without_invalid: disjunction 'if' disjunction 'else' expression | disjunction | lambdef _prev_call_invalid = self.call_invalid_rules self.call_invalid_rules = False @@ -6379,34 +6936,34 @@ def expression_without_invalid(self) -> Optional[ast . AST]: start_lineno, start_col_offset = tok.start if ( (a := self.disjunction()) - and - (self.expect('if')) - and - (b := self.disjunction()) - and - (self.expect('else')) - and - (c := self.expression()) + and (self.expect("if")) + and (b := self.disjunction()) + and (self.expect("else")) + and (c := self.expression()) ): tok = self._tokenizer.get_last_non_whitespace_token() end_lineno, end_col_offset = tok.end self.call_invalid_rules = _prev_call_invalid - return ast . IfExp ( body = b , test = a , orelse = c , lineno=start_lineno, col_offset=start_col_offset, end_lineno=end_lineno, end_col_offset=end_col_offset ); - self._reset(mark) - if ( - (disjunction := self.disjunction()) - ): + return ast.IfExp( + body=b, + test=a, + orelse=c, + lineno=start_lineno, + col_offset=start_col_offset, + end_lineno=end_lineno, + end_col_offset=end_col_offset, + ) + self._reset(mark) + if disjunction := self.disjunction(): self.call_invalid_rules = _prev_call_invalid - return disjunction; + return disjunction self._reset(mark) - if ( - (lambdef := self.lambdef()) - ): + if lambdef := self.lambdef(): self.call_invalid_rules = _prev_call_invalid - return lambdef; + return lambdef self._reset(mark) self.call_invalid_rules = _prev_call_invalid - return None; + return None @memoize def invalid_legacy_expression(self) -> Optional[Any]: @@ -6414,90 +6971,124 @@ def invalid_legacy_expression(self) -> Optional[Any]: mark = self._mark() if ( (a := self.name()) - and - (self.negative_lookahead(self.expect, '(')) - and - (b := self.star_expressions()) + and (self.negative_lookahead(self.expect, "(")) + and (b := self.star_expressions()) ): - return self . raise_syntax_error_known_range ( f"Missing parentheses in call to '{a.string}' . Did you mean {a.string}(...)?" , a , b , ) if a . string in ( "exec" , "print" ) else None; + return ( + self.raise_syntax_error_known_range( + f"Missing parentheses in call to '{a.string}' . Did you mean {a.string}(...)?", + a, + b, + ) + if a.string in ("exec", "print") + else None + ) self._reset(mark) - return None; + return None @memoize def invalid_expression(self) -> Optional[NoReturn]: # invalid_expression: !(NAME STRING | SOFT_KEYWORD) disjunction expression_without_invalid | disjunction 'if' disjunction !('else' | ':') | 'lambda' lambda_params? ':' &(FSTRING_MIDDLE | fstring_replacement_field) mark = self._mark() if ( - (self.negative_lookahead(self._tmp_188, )) - and - (a := self.disjunction()) - and - (b := self.expression_without_invalid()) + ( + self.negative_lookahead( + self._tmp_193, + ) + ) + and (a := self.disjunction()) + and (b := self.expression_without_invalid()) ): - return ( self . raise_syntax_error_known_range ( "invalid syntax. Perhaps you forgot a comma?" , a , b ) if not isinstance ( a , ast . Name ) or a . id not in ( "print" , "exec" ) else None ); + return ( + self.raise_syntax_error_known_range( + "invalid syntax. Perhaps you forgot a comma?", a, b + ) + if not isinstance(a, ast.Name) or a.id not in ("print", "exec") + else None + ) self._reset(mark) if ( (a := self.disjunction()) - and - (self.expect('if')) - and - (b := self.disjunction()) - and - (self.negative_lookahead(self._tmp_189, )) + and (self.expect("if")) + and (b := self.disjunction()) + and ( + self.negative_lookahead( + self._tmp_194, + ) + ) ): - return self . raise_syntax_error_known_range ( "expected 'else' after 'if' expression" , a , b ); + return self.raise_syntax_error_known_range( + "expected 'else' after 'if' expression", a, b + ) self._reset(mark) if ( - (a := self.expect('lambda')) - and - (self.lambda_params(),) - and - (b := self.expect(':')) - and - (self.positive_lookahead(self._tmp_190, )) + (a := self.expect("lambda")) + and (self.lambda_params(),) + and (b := self.expect(":")) + and ( + self.positive_lookahead( + self._tmp_195, + ) + ) ): - return self . raise_syntax_error_known_range ( "f-string: lambda expressions are not allowed without parentheses" , a , b ); + return self.raise_syntax_error_known_range( + "f-string: lambda expressions are not allowed without parentheses", a, b + ) self._reset(mark) - return None; + return None @memoize def invalid_named_expression(self) -> Optional[NoReturn]: # invalid_named_expression: expression ':=' expression | NAME '=' bitwise_or !('=' | ':=') | !(list | tuple | genexp | 'True' | 'None' | 'False') bitwise_or '=' bitwise_or !('=' | ':=') mark = self._mark() - if ( - (a := self.expression()) - and - (self.expect(':=')) - and - (self.expression()) - ): - return self . raise_syntax_error_known_location ( f"cannot use assignment expressions with {self.get_expr_name(a)}" , a ); + if (a := self.expression()) and (self.expect(":=")) and (self.expression()): + return self.raise_syntax_error_known_location( + f"cannot use assignment expressions with {self.get_expr_name(a)}", a + ) self._reset(mark) if ( (a := self.name()) - and - (self.expect('=')) - and - (b := self.bitwise_or()) - and - (self.negative_lookahead(self._tmp_191, )) - ): - return ( None if self . in_recursive_rule else self . raise_syntax_error_known_range ( "invalid syntax. Maybe you meant '==' or ':=' instead of '='?" , a , b ) ); - self._reset(mark) - if ( - (self.negative_lookahead(self._tmp_192, )) - and - (a := self.bitwise_or()) - and - (self.expect('=')) - and - (self.bitwise_or()) - and - (self.negative_lookahead(self._tmp_193, )) - ): - return ( None if self . in_recursive_rule else self . raise_syntax_error_known_location ( f"cannot assign to {self.get_expr_name(a)} here. Maybe you meant '==' instead of '='?" , a ) ); - self._reset(mark) - return None; + and (self.expect("=")) + and (b := self.bitwise_or()) + and ( + self.negative_lookahead( + self._tmp_196, + ) + ) + ): + return ( + None + if self.in_recursive_rule + else self.raise_syntax_error_known_range( + "invalid syntax. Maybe you meant '==' or ':=' instead of '='?", a, b + ) + ) + self._reset(mark) + if ( + ( + self.negative_lookahead( + self._tmp_197, + ) + ) + and (a := self.bitwise_or()) + and (self.expect("=")) + and (self.bitwise_or()) + and ( + self.negative_lookahead( + self._tmp_198, + ) + ) + ): + return ( + None + if self.in_recursive_rule + else self.raise_syntax_error_known_location( + f"cannot assign to {self.get_expr_name(a)} here. Maybe you meant '==' instead of '='?", + a, + ) + ) + self._reset(mark) + return None @memoize def invalid_assignment(self) -> Optional[NoReturn]: @@ -6505,518 +7096,400 @@ def invalid_assignment(self) -> Optional[NoReturn]: mark = self._mark() if ( self.call_invalid_rules - and - (a := self.invalid_ann_assign_target()) - and - (self.expect(':')) - and - (self.expression()) + and (a := self.invalid_ann_assign_target()) + and (self.expect(":")) + and (self.expression()) ): - return self . raise_syntax_error_known_location ( f"only single target (not {self.get_expr_name(a)}) can be annotated" , a ); + return self.raise_syntax_error_known_location( + f"only single target (not {self.get_expr_name(a)}) can be annotated", a + ) self._reset(mark) if ( (a := self.star_named_expression()) - and - (self.expect(',')) - and - (self._loop0_194(),) - and - (self.expect(':')) - and - (self.expression()) + and (self.expect(",")) + and (self._loop0_199(),) + and (self.expect(":")) + and (self.expression()) ): - return self . raise_syntax_error_known_location ( "only single target (not tuple) can be annotated" , a ); + return self.raise_syntax_error_known_location( + "only single target (not tuple) can be annotated", a + ) self._reset(mark) - if ( - (a := self.expression()) - and - (self.expect(':')) - and - (self.expression()) - ): - return self . raise_syntax_error_known_location ( "illegal target for annotation" , a ); + if (a := self.expression()) and (self.expect(":")) and (self.expression()): + return self.raise_syntax_error_known_location( + "illegal target for annotation", a + ) self._reset(mark) if ( - (self._loop0_195(),) - and - (a := self.star_expressions()) - and - (self.expect('=')) + (self._loop0_200(),) + and (a := self.star_expressions()) + and (self.expect("=")) ): - return self . raise_syntax_error_invalid_target ( Target . STAR_TARGETS , a ); + return self.raise_syntax_error_invalid_target(Target.STAR_TARGETS, a) self._reset(mark) - if ( - (self._loop0_196(),) - and - (a := self.yield_expr()) - and - (self.expect('=')) - ): - return self . raise_syntax_error_known_location ( "assignment to yield expression not possible" , a ); + if (self._loop0_201(),) and (a := self.yield_expr()) and (self.expect("=")): + return self.raise_syntax_error_known_location( + "assignment to yield expression not possible", a + ) self._reset(mark) - if ( - (a := self.star_expressions()) - and - (self.augassign()) - and - (self._tmp_197()) - ): - return self . raise_syntax_error_known_location ( f"'{self.get_expr_name(a)}' is an illegal expression for augmented assignment" , a ); + if (a := self.star_expressions()) and (self.augassign()) and (self._tmp_202()): + return self.raise_syntax_error_known_location( + f"'{self.get_expr_name(a)}' is an illegal expression for augmented assignment", + a, + ) self._reset(mark) - return None; + return None @memoize - def invalid_ann_assign_target(self) -> Optional[ast . AST]: + def invalid_ann_assign_target(self) -> Optional[ast.AST]: # invalid_ann_assign_target: list | tuple | '(' invalid_ann_assign_target ')' mark = self._mark() - if ( - (a := self.list()) - ): - return a; + if a := self.list(): + return a self._reset(mark) - if ( - (a := self.tuple()) - ): - return a; + if a := self.tuple(): + return a self._reset(mark) if ( self.call_invalid_rules - and - (self.expect('(')) - and - (a := self.invalid_ann_assign_target()) - and - (self.expect(')')) + and (self.expect("(")) + and (a := self.invalid_ann_assign_target()) + and (self.expect(")")) ): - return a; + return a self._reset(mark) - return None; + return None @memoize def invalid_del_stmt(self) -> Optional[NoReturn]: # invalid_del_stmt: 'del' star_expressions mark = self._mark() - if ( - (self.expect('del')) - and - (a := self.star_expressions()) - ): - return self . raise_syntax_error_invalid_target ( Target . DEL_TARGETS , a ); + if (self.expect("del")) and (a := self.star_expressions()): + return self.raise_syntax_error_invalid_target(Target.DEL_TARGETS, a) self._reset(mark) - return None; + return None @memoize def invalid_block(self) -> Optional[NoReturn]: # invalid_block: NEWLINE !INDENT mark = self._mark() - if ( - (self.expect('NEWLINE')) - and - (self.negative_lookahead(self.expect, 'INDENT')) + if (self.expect("NEWLINE")) and ( + self.negative_lookahead(self.expect, "INDENT") ): - return self . raise_indentation_error ( "expected an indented block" ); + return self.raise_indentation_error("expected an indented block") self._reset(mark) - return None; + return None @memoize def invalid_comprehension(self) -> Optional[NoReturn]: # invalid_comprehension: ('[' | '(' | '{') starred_expression for_if_clauses | ('[' | '{') star_named_expression ',' star_named_expressions for_if_clauses | ('[' | '{') star_named_expression ',' for_if_clauses mark = self._mark() if ( - (self._tmp_198()) - and - (a := self.starred_expression()) - and - (self.for_if_clauses()) + (self._tmp_203()) + and (a := self.starred_expression()) + and (self.for_if_clauses()) ): - return self . raise_syntax_error_known_location ( "iterable unpacking cannot be used in comprehension" , a ); + return self.raise_syntax_error_known_location( + "iterable unpacking cannot be used in comprehension", a + ) self._reset(mark) if ( - (self._tmp_199()) - and - (a := self.star_named_expression()) - and - (self.expect(',')) - and - (b := self.star_named_expressions()) - and - (self.for_if_clauses()) + (self._tmp_204()) + and (a := self.star_named_expression()) + and (self.expect(",")) + and (b := self.star_named_expressions()) + and (self.for_if_clauses()) ): - return self . raise_syntax_error_known_range ( "did you forget parentheses around the comprehension target?" , a , b [- 1] ); + return self.raise_syntax_error_known_range( + "did you forget parentheses around the comprehension target?", a, b[-1] + ) self._reset(mark) if ( - (self._tmp_200()) - and - (a := self.star_named_expression()) - and - (b := self.expect(',')) - and - (self.for_if_clauses()) + (self._tmp_205()) + and (a := self.star_named_expression()) + and (b := self.expect(",")) + and (self.for_if_clauses()) ): - return self . raise_syntax_error_known_range ( "did you forget parentheses around the comprehension target?" , a , b ); + return self.raise_syntax_error_known_range( + "did you forget parentheses around the comprehension target?", a, b + ) self._reset(mark) - return None; + return None @memoize def invalid_dict_comprehension(self) -> Optional[NoReturn]: # invalid_dict_comprehension: '{' '**' bitwise_or for_if_clauses '}' mark = self._mark() if ( - (self.expect('{')) - and - (a := self.expect('**')) - and - (self.bitwise_or()) - and - (self.for_if_clauses()) - and - (self.expect('}')) + (self.expect("{")) + and (a := self.expect("**")) + and (self.bitwise_or()) + and (self.for_if_clauses()) + and (self.expect("}")) ): - return self . raise_syntax_error_known_location ( "dict unpacking cannot be used in dict comprehension" , a ); + return self.raise_syntax_error_known_location( + "dict unpacking cannot be used in dict comprehension", a + ) self._reset(mark) - return None; + return None @memoize def invalid_parameters(self) -> Optional[NoReturn]: # invalid_parameters: "/" ',' | (slash_no_default | slash_with_default) param_maybe_default* '/' | slash_no_default? param_no_default* invalid_parameters_helper param_no_default | param_no_default* '(' param_no_default+ ','? ')' | [(slash_no_default | slash_with_default)] param_maybe_default* '*' (',' | param_no_default) param_maybe_default* '/' | param_maybe_default+ '/' '*' mark = self._mark() - if ( - (a := self.expect("/")) - and - (self.expect(',')) - ): - return self . raise_syntax_error_known_location ( "at least one argument must precede /" , a ); + if (a := self.expect("/")) and (self.expect(",")): + return self.raise_syntax_error_known_location( + "at least one argument must precede /", a + ) + self._reset(mark) + if (self._tmp_206()) and (self._loop0_207(),) and (a := self.expect("/")): + return self.raise_syntax_error_known_location("/ may appear only once", a) self._reset(mark) if ( - (self._tmp_201()) - and - (self._loop0_202(),) - and - (a := self.expect('/')) + self.call_invalid_rules + and (self.slash_no_default(),) + and (self._loop0_208(),) + and (self.invalid_parameters_helper()) + and (a := self.param_no_default()) ): - return self . raise_syntax_error_known_location ( "/ may appear only once" , a ); + return self.raise_syntax_error_known_location( + "parameter without a default follows parameter with a default", a + ) self._reset(mark) if ( - self.call_invalid_rules - and - (self.slash_no_default(),) - and - (self._loop0_203(),) - and - (self.invalid_parameters_helper()) - and - (a := self.param_no_default()) - ): - return self . raise_syntax_error_known_location ( "parameter without a default follows parameter with a default" , a ); - self._reset(mark) - if ( - (self._loop0_204(),) - and - (a := self.expect('(')) - and - (self._loop1_205()) - and - (self.expect(','),) - and - (b := self.expect(')')) - ): - return self . raise_syntax_error_known_range ( "Function parameters cannot be parenthesized" , a , b ); - self._reset(mark) - if ( - (self._tmp_206(),) - and - (self._loop0_207(),) - and - (self.expect('*')) - and - (self._tmp_208()) - and (self._loop0_209(),) - and - (a := self.expect('/')) + and (a := self.expect("(")) + and (self._loop1_210()) + and (self.expect(","),) + and (b := self.expect(")")) ): - return self . raise_syntax_error_known_location ( "/ must be ahead of *" , a ); + return self.raise_syntax_error_known_range( + "Function parameters cannot be parenthesized", a, b + ) self._reset(mark) if ( - (self._loop1_210()) - and - (self.expect('/')) - and - (a := self.expect('*')) + (self._tmp_211(),) + and (self._loop0_212(),) + and (self.expect("*")) + and (self._tmp_213()) + and (self._loop0_214(),) + and (a := self.expect("/")) ): - return self . raise_syntax_error_known_location ( "expected comma between / and *" , a ); + return self.raise_syntax_error_known_location("/ must be ahead of *", a) + self._reset(mark) + if (self._loop1_215()) and (self.expect("/")) and (a := self.expect("*")): + return self.raise_syntax_error_known_location( + "expected comma between / and *", a + ) self._reset(mark) - return None; + return None @memoize def invalid_default(self) -> Optional[Any]: # invalid_default: '=' &(')' | ',') mark = self._mark() - if ( - (a := self.expect('=')) - and - (self.positive_lookahead(self._tmp_211, )) + if (a := self.expect("=")) and ( + self.positive_lookahead( + self._tmp_216, + ) ): - return self . raise_syntax_error_known_location ( "expected default value expression" , a ); + return self.raise_syntax_error_known_location( + "expected default value expression", a + ) self._reset(mark) - return None; + return None @memoize def invalid_star_etc(self) -> Optional[Any]: # invalid_star_etc: '*' (')' | ',' (')' | '**')) | '*' ',' TYPE_COMMENT | '*' param '=' | '*' (param_no_default | ',') param_maybe_default* '*' (param_no_default | ',') mark = self._mark() - if ( - (a := self.expect('*')) - and - (self._tmp_212()) - ): - return self . raise_syntax_error_known_location ( "named arguments must follow bare *" , a ); + if (a := self.expect("*")) and (self._tmp_217()): + return self.raise_syntax_error_known_location( + "named arguments must follow bare *", a + ) self._reset(mark) - if ( - (self.expect('*')) - and - (self.expect(',')) - and - (self.type_comment()) - ): - return self . raise_syntax_error ( "bare * has associated type comment" ); + if (self.expect("*")) and (self.expect(",")) and (self.type_comment()): + return self.raise_syntax_error("bare * has associated type comment") self._reset(mark) - if ( - (self.expect('*')) - and - (self.param()) - and - (a := self.expect('=')) - ): - return self . raise_syntax_error_known_location ( "var-positional argument cannot have default value" , a ); + if (self.expect("*")) and (self.param()) and (a := self.expect("=")): + return self.raise_syntax_error_known_location( + "var-positional argument cannot have default value", a + ) self._reset(mark) if ( - (self.expect('*')) - and - (self._tmp_213()) - and - (self._loop0_214(),) - and - (a := self.expect('*')) - and - (self._tmp_215()) + (self.expect("*")) + and (self._tmp_218()) + and (self._loop0_219(),) + and (a := self.expect("*")) + and (self._tmp_220()) ): - return self . raise_syntax_error_known_location ( "* argument may appear only once" , a ); + return self.raise_syntax_error_known_location( + "* argument may appear only once", a + ) self._reset(mark) - return None; + return None @memoize def invalid_kwds(self) -> Optional[Any]: # invalid_kwds: '**' param '=' | '**' param ',' param | '**' param ',' ('*' | '**' | '/') mark = self._mark() - if ( - (self.expect('**')) - and - (self.param()) - and - (a := self.expect('=')) - ): - return self . raise_syntax_error_known_location ( "var-keyword argument cannot have default value" , a ); + if (self.expect("**")) and (self.param()) and (a := self.expect("=")): + return self.raise_syntax_error_known_location( + "var-keyword argument cannot have default value", a + ) self._reset(mark) if ( - (self.expect('**')) - and - (self.param()) - and - (self.expect(',')) - and - (a := self.param()) + (self.expect("**")) + and (self.param()) + and (self.expect(",")) + and (a := self.param()) ): - return self . raise_syntax_error_known_location ( "arguments cannot follow var-keyword argument" , a ); + return self.raise_syntax_error_known_location( + "arguments cannot follow var-keyword argument", a + ) self._reset(mark) if ( - (self.expect('**')) - and - (self.param()) - and - (self.expect(',')) - and - (a := self._tmp_216()) + (self.expect("**")) + and (self.param()) + and (self.expect(",")) + and (a := self._tmp_221()) ): - return self . raise_syntax_error_known_location ( "arguments cannot follow var-keyword argument" , a ); + return self.raise_syntax_error_known_location( + "arguments cannot follow var-keyword argument", a + ) self._reset(mark) - return None; + return None @memoize def invalid_parameters_helper(self) -> Optional[Any]: # invalid_parameters_helper: slash_with_default | param_with_default+ mark = self._mark() - if ( - (a := self.slash_with_default()) - ): - return [a]; + if a := self.slash_with_default(): + return [a] self._reset(mark) - if ( - (a := self._loop1_217()) - ): - return a; + if a := self._loop1_222(): + return a self._reset(mark) - return None; + return None @memoize def invalid_lambda_parameters(self) -> Optional[NoReturn]: # invalid_lambda_parameters: "/" ',' | (lambda_slash_no_default | lambda_slash_with_default) lambda_param_maybe_default* '/' | lambda_slash_no_default? lambda_param_no_default* invalid_lambda_parameters_helper lambda_param_no_default | lambda_param_no_default* '(' ','.lambda_param+ ','? ')' | [(lambda_slash_no_default | lambda_slash_with_default)] lambda_param_maybe_default* '*' (',' | lambda_param_no_default) lambda_param_maybe_default* '/' | lambda_param_maybe_default+ '/' '*' mark = self._mark() - if ( - (a := self.expect("/")) - and - (self.expect(',')) - ): - return self . raise_syntax_error_known_location ( "at least one argument must precede /" , a ); + if (a := self.expect("/")) and (self.expect(",")): + return self.raise_syntax_error_known_location( + "at least one argument must precede /", a + ) self._reset(mark) - if ( - (self._tmp_218()) - and - (self._loop0_219(),) - and - (a := self.expect('/')) - ): - return self . raise_syntax_error_known_location ( "/ may appear only once" , a ); + if (self._tmp_223()) and (self._loop0_224(),) and (a := self.expect("/")): + return self.raise_syntax_error_known_location("/ may appear only once", a) self._reset(mark) if ( self.call_invalid_rules - and - (self.lambda_slash_no_default(),) - and - (self._loop0_220(),) - and - (self.invalid_lambda_parameters_helper()) - and - (a := self.lambda_param_no_default()) + and (self.lambda_slash_no_default(),) + and (self._loop0_225(),) + and (self.invalid_lambda_parameters_helper()) + and (a := self.lambda_param_no_default()) ): - return self . raise_syntax_error_known_location ( "parameter without a default follows parameter with a default" , a ); + return self.raise_syntax_error_known_location( + "parameter without a default follows parameter with a default", a + ) self._reset(mark) if ( - (self._loop0_221(),) - and - (a := self.expect('(')) - and - (self._gather_222()) - and - (self.expect(','),) - and - (b := self.expect(')')) + (self._loop0_226(),) + and (a := self.expect("(")) + and (self._gather_227()) + and (self.expect(","),) + and (b := self.expect(")")) ): - return self . raise_syntax_error_known_range ( "Lambda expression parameters cannot be parenthesized" , a , b ); + return self.raise_syntax_error_known_range( + "Lambda expression parameters cannot be parenthesized", a, b + ) self._reset(mark) if ( - (self._tmp_224(),) - and - (self._loop0_225(),) - and - (self.expect('*')) - and - (self._tmp_226()) - and - (self._loop0_227(),) - and - (a := self.expect('/')) + (self._tmp_229(),) + and (self._loop0_230(),) + and (self.expect("*")) + and (self._tmp_231()) + and (self._loop0_232(),) + and (a := self.expect("/")) ): - return self . raise_syntax_error_known_location ( "/ must be ahead of *" , a ); + return self.raise_syntax_error_known_location("/ must be ahead of *", a) self._reset(mark) - if ( - (self._loop1_228()) - and - (self.expect('/')) - and - (a := self.expect('*')) - ): - return self . raise_syntax_error_known_location ( "expected comma between / and *" , a ); + if (self._loop1_233()) and (self.expect("/")) and (a := self.expect("*")): + return self.raise_syntax_error_known_location( + "expected comma between / and *", a + ) self._reset(mark) - return None; + return None @memoize def invalid_lambda_parameters_helper(self) -> Optional[NoReturn]: # invalid_lambda_parameters_helper: lambda_slash_with_default | lambda_param_with_default+ mark = self._mark() - if ( - (a := self.lambda_slash_with_default()) - ): - return [a]; + if a := self.lambda_slash_with_default(): + return [a] self._reset(mark) - if ( - (a := self._loop1_229()) - ): - return a; + if a := self._loop1_234(): + return a self._reset(mark) - return None; + return None @memoize def invalid_lambda_star_etc(self) -> Optional[NoReturn]: # invalid_lambda_star_etc: '*' (':' | ',' (':' | '**')) | '*' lambda_param '=' | '*' (lambda_param_no_default | ',') lambda_param_maybe_default* '*' (lambda_param_no_default | ',') mark = self._mark() - if ( - (self.expect('*')) - and - (self._tmp_230()) - ): - return self . raise_syntax_error ( "named arguments must follow bare *" ); + if (self.expect("*")) and (self._tmp_235()): + return self.raise_syntax_error("named arguments must follow bare *") self._reset(mark) - if ( - (self.expect('*')) - and - (self.lambda_param()) - and - (a := self.expect('=')) - ): - return self . raise_syntax_error_known_location ( "var-positional argument cannot have default value" , a ); + if (self.expect("*")) and (self.lambda_param()) and (a := self.expect("=")): + return self.raise_syntax_error_known_location( + "var-positional argument cannot have default value", a + ) self._reset(mark) if ( - (self.expect('*')) - and - (self._tmp_231()) - and - (self._loop0_232(),) - and - (a := self.expect('*')) - and - (self._tmp_233()) + (self.expect("*")) + and (self._tmp_236()) + and (self._loop0_237(),) + and (a := self.expect("*")) + and (self._tmp_238()) ): - return self . raise_syntax_error_known_location ( "* argument may appear only once" , a ); + return self.raise_syntax_error_known_location( + "* argument may appear only once", a + ) self._reset(mark) - return None; + return None @memoize def invalid_lambda_kwds(self) -> Optional[Any]: # invalid_lambda_kwds: '**' lambda_param '=' | '**' lambda_param ',' lambda_param | '**' lambda_param ',' ('*' | '**' | '/') mark = self._mark() - if ( - (self.expect('**')) - and - (self.lambda_param()) - and - (a := self.expect('=')) - ): - return self . raise_syntax_error_known_location ( "var-keyword argument cannot have default value" , a ); + if (self.expect("**")) and (self.lambda_param()) and (a := self.expect("=")): + return self.raise_syntax_error_known_location( + "var-keyword argument cannot have default value", a + ) self._reset(mark) if ( - (self.expect('**')) - and - (self.lambda_param()) - and - (self.expect(',')) - and - (a := self.lambda_param()) + (self.expect("**")) + and (self.lambda_param()) + and (self.expect(",")) + and (a := self.lambda_param()) ): - return self . raise_syntax_error_known_location ( "arguments cannot follow var-keyword argument" , a ); + return self.raise_syntax_error_known_location( + "arguments cannot follow var-keyword argument", a + ) self._reset(mark) if ( - (self.expect('**')) - and - (self.lambda_param()) - and - (self.expect(',')) - and - (a := self._tmp_234()) + (self.expect("**")) + and (self.lambda_param()) + and (self.expect(",")) + and (a := self._tmp_239()) ): - return self . raise_syntax_error_known_location ( "arguments cannot follow var-keyword argument" , a ); + return self.raise_syntax_error_known_location( + "arguments cannot follow var-keyword argument", a + ) self._reset(mark) - return None; + return None @memoize def invalid_double_type_comments(self) -> Optional[NoReturn]: @@ -7024,18 +7497,14 @@ def invalid_double_type_comments(self) -> Optional[NoReturn]: mark = self._mark() if ( (self.type_comment()) - and - (self.expect('NEWLINE')) - and - (self.type_comment()) - and - (self.expect('NEWLINE')) - and - (self.expect('INDENT')) + and (self.expect("NEWLINE")) + and (self.type_comment()) + and (self.expect("NEWLINE")) + and (self.expect("INDENT")) ): - return self . raise_syntax_error ( "Cannot have two type comments on def" ); + return self.raise_syntax_error("Cannot have two type comments on def") self._reset(mark) - return None; + return None @memoize def invalid_with_item(self) -> Optional[NoReturn]: @@ -7043,74 +7512,89 @@ def invalid_with_item(self) -> Optional[NoReturn]: mark = self._mark() if ( (self.expression()) - and - (self.expect('as')) - and - (a := self.expression()) - and - (self.positive_lookahead(self._tmp_235, )) + and (self.expect("as")) + and (a := self.expression()) + and ( + self.positive_lookahead( + self._tmp_240, + ) + ) ): - return self . raise_syntax_error_invalid_target ( Target . STAR_TARGETS , a ); + return self.raise_syntax_error_invalid_target(Target.STAR_TARGETS, a) self._reset(mark) - return None; + return None @memoize def invalid_for_target(self) -> Optional[NoReturn]: # invalid_for_target: 'async'? 'for' star_expressions mark = self._mark() if ( - (self.expect('async'),) - and - (self.expect('for')) - and - (a := self.star_expressions()) + (self.expect("async"),) + and (self.expect("for")) + and (a := self.star_expressions()) ): - return self . raise_syntax_error_invalid_target ( Target . FOR_TARGETS , a ); + return self.raise_syntax_error_invalid_target(Target.FOR_TARGETS, a) self._reset(mark) - return None; + return None @memoize def invalid_group(self) -> Optional[NoReturn]: # invalid_group: '(' starred_expression ')' | '(' '**' expression ')' mark = self._mark() if ( - (self.expect('(')) - and - (a := self.starred_expression()) - and - (self.expect(')')) + (self.expect("(")) + and (a := self.starred_expression()) + and (self.expect(")")) ): - return self . raise_syntax_error_known_location ( "cannot use starred expression here" , a ); + return self.raise_syntax_error_known_location( + "cannot use starred expression here", a + ) self._reset(mark) if ( - (self.expect('(')) - and - (a := self.expect('**')) - and - (self.expression()) - and - (self.expect(')')) + (self.expect("(")) + and (a := self.expect("**")) + and (self.expression()) + and (self.expect(")")) ): - return self . raise_syntax_error_known_location ( "cannot use double starred expression here" , a ); + return self.raise_syntax_error_known_location( + "cannot use double starred expression here", a + ) self._reset(mark) - return None; + return None @memoize def invalid_import(self) -> Optional[Any]: # invalid_import: 'import' ','.dotted_name+ 'from' dotted_name mark = self._mark() if ( - (a := self.expect('import')) - and - (self._gather_236()) - and - (self.expect('from')) - and - (self.dotted_name()) + (a := self.expect("import")) + and (self._gather_241()) + and (self.expect("from")) + and (self.dotted_name()) + ): + return self.raise_syntax_error_starting_from( + "Did you mean to use 'from ... import ...' instead?", a + ) + self._reset(mark) + return None + + @memoize + def invalid_import_from(self) -> Optional[Any]: + # invalid_import_from: 'from' (('.' | '...'))* dotted_name "lazy" 'import' import_from_targets + mark = self._mark() + if ( + (self.expect("from")) + and (self._loop0_243(),) + and (self.dotted_name()) + and (a := self.expect("lazy")) + and (self.expect("import")) + and (self.import_from_targets()) ): - return self . raise_syntax_error_starting_from ( "Did you mean to use 'from ... import ...' instead?" , a ); + return self.raise_syntax_error_known_location( + "use 'lazy from ... ' instead of 'from ... lazy import'", a + ) self._reset(mark) - return None; + return None @memoize def invalid_import_from_targets(self) -> Optional[NoReturn]: @@ -7118,282 +7602,259 @@ def invalid_import_from_targets(self) -> Optional[NoReturn]: mark = self._mark() if ( (self.import_from_as_names()) - and - (self.expect(',')) - and - (self.expect('NEWLINE')) + and (self.expect(",")) + and (self.expect("NEWLINE")) ): - return self . raise_syntax_error ( "trailing comma not allowed without surrounding parentheses" ); + return self.raise_syntax_error( + "trailing comma not allowed without surrounding parentheses" + ) self._reset(mark) - return None; + return None @memoize def invalid_with_stmt(self) -> Optional[None]: # invalid_with_stmt: 'async'? 'with' ','.(expression ['as' star_target])+ &&':' | 'async'? 'with' '(' ','.(expressions ['as' star_target])+ ','? ')' &&':' mark = self._mark() if ( - (self.expect('async'),) - and - (self.expect('with')) - and - (self._gather_238()) - and - (self.expect_forced(self.expect(':'), "':'")) + (self.expect("async"),) + and (self.expect("with")) + and (self._gather_244()) + and (self.expect_forced(self.expect(":"), "':'")) ): - return None # pragma: no cover; + return None # pragma: no cover self._reset(mark) if ( - (self.expect('async'),) - and - (self.expect('with')) - and - (self.expect('(')) - and - (self._gather_240()) - and - (self.expect(','),) - and - (self.expect(')')) - and - (self.expect_forced(self.expect(':'), "':'")) + (self.expect("async"),) + and (self.expect("with")) + and (self.expect("(")) + and (self._gather_246()) + and (self.expect(","),) + and (self.expect(")")) + and (self.expect_forced(self.expect(":"), "':'")) ): - return None # pragma: no cover; + return None # pragma: no cover self._reset(mark) - return None; + return None @memoize def invalid_with_stmt_indent(self) -> Optional[NoReturn]: # invalid_with_stmt_indent: 'async'? 'with' ','.(expression ['as' star_target])+ ':' NEWLINE !INDENT | 'async'? 'with' '(' ','.(expressions ['as' star_target])+ ','? ')' ':' NEWLINE !INDENT mark = self._mark() if ( - (self.expect('async'),) - and - (a := self.expect('with')) - and - (self._gather_242()) - and - (self.expect(':')) - and - (self.expect('NEWLINE')) - and - (self.negative_lookahead(self.expect, 'INDENT')) - ): - return self . raise_indentation_error ( f"expected an indented block after 'with' statement on line {a.start[0]}" ); - self._reset(mark) - if ( - (self.expect('async'),) - and - (a := self.expect('with')) - and - (self.expect('(')) - and - (self._gather_244()) - and - (self.expect(','),) - and - (self.expect(')')) - and - (self.expect(':')) - and - (self.expect('NEWLINE')) - and - (self.negative_lookahead(self.expect, 'INDENT')) - ): - return self . raise_indentation_error ( f"expected an indented block after 'with' statement on line {a.start[0]}" ); - self._reset(mark) - return None; + (self.expect("async"),) + and (a := self.expect("with")) + and (self._gather_248()) + and (self.expect(":")) + and (self.expect("NEWLINE")) + and (self.negative_lookahead(self.expect, "INDENT")) + ): + return self.raise_indentation_error( + f"expected an indented block after 'with' statement on line {a.start[0]}" + ) + self._reset(mark) + if ( + (self.expect("async"),) + and (a := self.expect("with")) + and (self.expect("(")) + and (self._gather_250()) + and (self.expect(","),) + and (self.expect(")")) + and (self.expect(":")) + and (self.expect("NEWLINE")) + and (self.negative_lookahead(self.expect, "INDENT")) + ): + return self.raise_indentation_error( + f"expected an indented block after 'with' statement on line {a.start[0]}" + ) + self._reset(mark) + return None @memoize def invalid_try_stmt(self) -> Optional[NoReturn]: # invalid_try_stmt: 'try' ':' NEWLINE !INDENT | 'try' ':' block !('except' | 'finally') | 'try' ':' block* except_block+ 'except' '*' expression ['as' NAME] ':' | 'try' ':' block* except_star_block+ 'except' [expression ['as' NAME]] ':' mark = self._mark() if ( - (a := self.expect('try')) - and - (self.expect(':')) - and - (self.expect('NEWLINE')) - and - (self.negative_lookahead(self.expect, 'INDENT')) - ): - return self . raise_indentation_error ( f"expected an indented block after 'try' statement on line {a.start[0]}" , ); - self._reset(mark) - if ( - (self.expect('try')) - and - (self.expect(':')) - and - (self.block()) - and - (self.negative_lookahead(self._tmp_246, )) - ): - return self . raise_syntax_error ( "expected 'except' or 'finally' block" ); - self._reset(mark) - if ( - (self.expect('try')) - and - (self.expect(':')) - and - (self._loop0_247(),) - and - (self._loop1_248()) - and - (a := self.expect('except')) - and - (b := self.expect('*')) - and - (self.expression()) - and - (self._tmp_249(),) - and - (self.expect(':')) + (a := self.expect("try")) + and (self.expect(":")) + and (self.expect("NEWLINE")) + and (self.negative_lookahead(self.expect, "INDENT")) + ): + return self.raise_indentation_error( + f"expected an indented block after 'try' statement on line {a.start[0]}", + ) + self._reset(mark) + if ( + (self.expect("try")) + and (self.expect(":")) + and (self.block()) + and ( + self.negative_lookahead( + self._tmp_252, + ) + ) + ): + return self.raise_syntax_error("expected 'except' or 'finally' block") + self._reset(mark) + if ( + (self.expect("try")) + and (self.expect(":")) + and (self._loop0_253(),) + and (self._loop1_254()) + and (a := self.expect("except")) + and (b := self.expect("*")) + and (self.expression()) + and (self._tmp_255(),) + and (self.expect(":")) ): - return self . raise_syntax_error_known_range ( "cannot have both 'except' and 'except*' on the same 'try'" , a , b ); + return self.raise_syntax_error_known_range( + "cannot have both 'except' and 'except*' on the same 'try'", a, b + ) self._reset(mark) if ( - (self.expect('try')) - and - (self.expect(':')) - and - (self._loop0_250(),) - and - (self._loop1_251()) - and - (a := self.expect('except')) - and - (self._tmp_252(),) - and - (self.expect(':')) + (self.expect("try")) + and (self.expect(":")) + and (self._loop0_256(),) + and (self._loop1_257()) + and (a := self.expect("except")) + and (self._tmp_258(),) + and (self.expect(":")) ): - return self . raise_syntax_error_known_location ( "cannot have both 'except' and 'except*' on the same 'try'" , a ); + return self.raise_syntax_error_known_location( + "cannot have both 'except' and 'except*' on the same 'try'", a + ) self._reset(mark) - return None; + return None @memoize def invalid_except_stmt(self) -> Optional[None]: - # invalid_except_stmt: 'except' '*'? expression ',' expressions ['as' NAME] ':' | 'except' '*'? expression ['as' NAME] NEWLINE | 'except' '*'? NEWLINE | 'except' '*' (NEWLINE | ':') + # invalid_except_stmt: 'except' '*'? expression ',' expressions ['as' NAME] ':' | 'except' '*'? expression ',' expressions ':' | 'except' '*'? expression ',' | 'except' '*'? expression ['as' NAME] NEWLINE | 'except' '*'? NEWLINE | 'except' '*' (NEWLINE | ':') mark = self._mark() if ( - (self.expect('except')) - and - (self.expect('*'),) - and - (a := self.expression()) - and - (self.expect(',')) - and - (self.expressions()) - and - (self._tmp_253(),) - and - (self.expect(':')) - ): - return self . raise_syntax_error_starting_from ( "multiple exception types must be parenthesized" , a ); - self._reset(mark) - if ( - (self.expect('except')) - and - (self.expect('*'),) - and - (self.expression()) - and - (self._tmp_254(),) - and - (self.expect('NEWLINE')) + (self.expect("except")) + and (self.expect("*"),) + and (a := self.expression()) + and (self.expect(",")) + and (self.expressions()) + and (self._tmp_259(),) + and (self.expect(":")) + ): + return self.raise_syntax_error_known_range( + "multiple exception types must be parenthesized when using 'as'" + if self.py_version >= (3, 14) + else "multiple exception types must be parenthesized", + a, + a, + ) + self._reset(mark) + if ( + (self.expect("except")) + and (self.expect("*"),) + and (a := self.expression()) + and (self.expect(",")) + and (b := self.expressions()) + and (self.expect(":")) ): - return self . raise_syntax_error ( "expected ':'" ); + return ( + self.raise_syntax_error_known_range( + "multiple exception types must be parenthesized", + a, + b, + ) + if self.py_version < (3, 14) + else None + ) self._reset(mark) if ( - (self.expect('except')) - and - (self.expect('*'),) - and - (self.expect('NEWLINE')) + (self.expect("except")) + and (self.expect("*"),) + and (self.expression()) + and (a := self.expect(",")) ): - return self . raise_syntax_error ( "expected ':'" ); + return ( + self.raise_syntax_error_known_location("invalid syntax", a) + if self.py_version < (3, 14) + else None + ) self._reset(mark) if ( - (self.expect('except')) - and - (self.expect('*')) - and - (self._tmp_255()) + (self.expect("except")) + and (self.expect("*"),) + and (self.expression()) + and (self._tmp_260(),) + and (self.expect("NEWLINE")) ): - return self . raise_syntax_error ( "expected one or more exception types" ); + return self.raise_syntax_error("expected ':'") + self._reset(mark) + if (self.expect("except")) and (self.expect("*"),) and (self.expect("NEWLINE")): + return self.raise_syntax_error("expected ':'") + self._reset(mark) + if (self.expect("except")) and (self.expect("*")) and (self._tmp_261()): + return self.raise_syntax_error("expected one or more exception types") self._reset(mark) - return None; + return None @memoize def invalid_finally_stmt(self) -> Optional[NoReturn]: # invalid_finally_stmt: 'finally' ':' NEWLINE !INDENT mark = self._mark() if ( - (a := self.expect('finally')) - and - (self.expect(':')) - and - (self.expect('NEWLINE')) - and - (self.negative_lookahead(self.expect, 'INDENT')) + (a := self.expect("finally")) + and (self.expect(":")) + and (self.expect("NEWLINE")) + and (self.negative_lookahead(self.expect, "INDENT")) ): - return self . raise_indentation_error ( f"expected an indented block after 'finally' statement on line {a.start[0]}" ); + return self.raise_indentation_error( + f"expected an indented block after 'finally' statement on line {a.start[0]}" + ) self._reset(mark) - return None; + return None @memoize def invalid_except_stmt_indent(self) -> Optional[NoReturn]: # invalid_except_stmt_indent: 'except' expression ['as' NAME] ':' NEWLINE !INDENT | 'except' ':' NEWLINE !INDENT mark = self._mark() if ( - (a := self.expect('except')) - and - (self.expression()) - and - (self._tmp_256(),) - and - (self.expect(':')) - and - (self.expect('NEWLINE')) - and - (self.negative_lookahead(self.expect, 'INDENT')) + (a := self.expect("except")) + and (self.expression()) + and (self._tmp_262(),) + and (self.expect(":")) + and (self.expect("NEWLINE")) + and (self.negative_lookahead(self.expect, "INDENT")) ): - return self . raise_indentation_error ( f"expected an indented block after 'except' statement on line {a.start[0]}" ); + return self.raise_indentation_error( + f"expected an indented block after 'except' statement on line {a.start[0]}" + ) self._reset(mark) if ( - (a := self.expect('except')) - and - (self.expect(':')) - and - (self.expect('NEWLINE')) - and - (self.negative_lookahead(self.expect, 'INDENT')) + (a := self.expect("except")) + and (self.expect(":")) + and (self.expect("NEWLINE")) + and (self.negative_lookahead(self.expect, "INDENT")) ): - return self . raise_indentation_error ( f"expected an indented block after 'except' statement on line {a.start[0]}" ); + return self.raise_indentation_error( + f"expected an indented block after 'except' statement on line {a.start[0]}" + ) self._reset(mark) - return None; + return None @memoize def invalid_except_star_stmt_indent(self) -> Optional[Any]: # invalid_except_star_stmt_indent: 'except' '*' expression ['as' NAME] ':' NEWLINE !INDENT mark = self._mark() if ( - (a := self.expect('except')) - and - (self.expect('*')) - and - (self.expression()) - and - (self._tmp_257(),) - and - (self.expect(':')) - and - (self.expect('NEWLINE')) - and - (self.negative_lookahead(self.expect, 'INDENT')) + (a := self.expect("except")) + and (self.expect("*")) + and (self.expression()) + and (self._tmp_263(),) + and (self.expect(":")) + and (self.expect("NEWLINE")) + and (self.negative_lookahead(self.expect, "INDENT")) ): - return self . raise_indentation_error ( f"expected an indented block after 'except*' statement on line {a.start[0]}" ); + return self.raise_indentation_error( + f"expected an indented block after 'except*' statement on line {a.start[0]}" + ) self._reset(mark) - return None; + return None @memoize def invalid_match_stmt(self) -> Optional[NoReturn]: @@ -7401,27 +7862,29 @@ def invalid_match_stmt(self) -> Optional[NoReturn]: mark = self._mark() if ( (self.expect("match")) - and - (self.subject_expr()) - and - (self.negative_lookahead(self.expect, ':')) + and (self.subject_expr()) + and (self.negative_lookahead(self.expect, ":")) ): - return self . check_version ( ( 3 , 10 ) , "Pattern matching is" , self . raise_syntax_error ( "expected ':'" ) ); + return self.check_version( + (3, 10), "Pattern matching is", self.raise_syntax_error("expected ':'") + ) self._reset(mark) if ( (a := self.expect("match")) - and - (self.subject_expr()) - and - (self.expect(':')) - and - (self.expect('NEWLINE')) - and - (self.negative_lookahead(self.expect, 'INDENT')) + and (self.subject_expr()) + and (self.expect(":")) + and (self.expect("NEWLINE")) + and (self.negative_lookahead(self.expect, "INDENT")) ): - return self . check_version ( ( 3 , 10 ) , "Pattern matching is" , self . raise_indentation_error ( f"expected an indented block after 'match' statement on line {a.start[0]}" ) ); + return self.check_version( + (3, 10), + "Pattern matching is", + self.raise_indentation_error( + f"expected an indented block after 'match' statement on line {a.start[0]}" + ), + ) self._reset(mark) - return None; + return None @memoize def invalid_case_block(self) -> Optional[NoReturn]: @@ -7429,57 +7892,45 @@ def invalid_case_block(self) -> Optional[NoReturn]: mark = self._mark() if ( (self.expect("case")) - and - (self.patterns()) - and - (self.guard(),) - and - (self.negative_lookahead(self.expect, ':')) + and (self.patterns()) + and (self.guard(),) + and (self.negative_lookahead(self.expect, ":")) ): - return self . raise_syntax_error ( "expected ':'" ); + return self.raise_syntax_error("expected ':'") self._reset(mark) if ( (a := self.expect("case")) - and - (self.patterns()) - and - (self.guard(),) - and - (self.expect(':')) - and - (self.expect('NEWLINE')) - and - (self.negative_lookahead(self.expect, 'INDENT')) + and (self.patterns()) + and (self.guard(),) + and (self.expect(":")) + and (self.expect("NEWLINE")) + and (self.negative_lookahead(self.expect, "INDENT")) ): - return self . raise_indentation_error ( f"expected an indented block after 'case' statement on line {a.start[0]}" ); + return self.raise_indentation_error( + f"expected an indented block after 'case' statement on line {a.start[0]}" + ) self._reset(mark) - return None; + return None @memoize def invalid_as_pattern(self) -> Optional[NoReturn]: - # invalid_as_pattern: or_pattern 'as' "_" | or_pattern 'as' !NAME expression + # invalid_as_pattern: or_pattern 'as' "_" | or_pattern 'as' expression mark = self._mark() - if ( - (self.or_pattern()) - and - (self.expect('as')) - and - (a := self.expect("_")) - ): - return self . raise_syntax_error_known_location ( "cannot use '_' as a target" , a ); + if (self.or_pattern()) and (self.expect("as")) and (a := self.expect("_")): + return self.raise_syntax_error_known_location( + "cannot use '_' as a target", a + ) self._reset(mark) - if ( - (self.or_pattern()) - and - (self.expect('as')) - and - (self.negative_lookahead(self.name, )) - and - (a := self.expression()) - ): - return self . raise_syntax_error_known_location ( "invalid pattern target" , a ); + if (self.or_pattern()) and (self.expect("as")) and (a := self.expression()): + return ( + self.raise_syntax_error_known_location( + f"cannot use {self.get_expr_name(a)} as pattern target", a + ) + if self.py_version >= (3, 14) + else self.raise_syntax_error_known_location("invalid pattern target", a) + ) self._reset(mark) - return None; + return None @memoize def invalid_class_pattern(self) -> Optional[NoReturn]: @@ -7487,241 +7938,198 @@ def invalid_class_pattern(self) -> Optional[NoReturn]: mark = self._mark() if ( self.call_invalid_rules - and - (self.name_or_attr()) - and - (self.expect('(')) - and - (a := self.invalid_class_argument_pattern()) + and (self.name_or_attr()) + and (self.expect("(")) + and (a := self.invalid_class_argument_pattern()) ): - return self . raise_syntax_error_known_range ( "positional patterns follow keyword patterns" , a [0] , a [- 1] ); + return self.raise_syntax_error_known_range( + "positional patterns follow keyword patterns", a[0], a[-1] + ) self._reset(mark) - return None; + return None @memoize def invalid_class_argument_pattern(self) -> Optional[list]: # invalid_class_argument_pattern: [positional_patterns ','] keyword_patterns ',' positional_patterns mark = self._mark() if ( - (self._tmp_258(),) - and - (self.keyword_patterns()) - and - (self.expect(',')) - and - (a := self.positional_patterns()) + (self._tmp_264(),) + and (self.keyword_patterns()) + and (self.expect(",")) + and (a := self.positional_patterns()) ): - return a; + return a self._reset(mark) - return None; + return None @memoize def invalid_if_stmt(self) -> Optional[NoReturn]: # invalid_if_stmt: 'if' named_expression NEWLINE | 'if' named_expression ':' NEWLINE !INDENT mark = self._mark() if ( - (self.expect('if')) - and - (self.named_expression()) - and - (self.expect('NEWLINE')) + (self.expect("if")) + and (self.named_expression()) + and (self.expect("NEWLINE")) ): - return self . raise_syntax_error ( "expected ':'" ); + return self.raise_syntax_error("expected ':'") self._reset(mark) if ( - (a := self.expect('if')) - and - (a_1 := self.named_expression()) - and - (self.expect(':')) - and - (self.expect('NEWLINE')) - and - (self.negative_lookahead(self.expect, 'INDENT')) + (a := self.expect("if")) + and (a_1 := self.named_expression()) + and (self.expect(":")) + and (self.expect("NEWLINE")) + and (self.negative_lookahead(self.expect, "INDENT")) ): - return self . raise_indentation_error ( f"expected an indented block after 'if' statement on line {a.start[0]}" ); + return self.raise_indentation_error( + f"expected an indented block after 'if' statement on line {a.start[0]}" + ) self._reset(mark) - return None; + return None @memoize def invalid_elif_stmt(self) -> Optional[NoReturn]: # invalid_elif_stmt: 'elif' named_expression NEWLINE | 'elif' named_expression ':' NEWLINE !INDENT mark = self._mark() if ( - (self.expect('elif')) - and - (self.named_expression()) - and - (self.expect('NEWLINE')) + (self.expect("elif")) + and (self.named_expression()) + and (self.expect("NEWLINE")) ): - return self . raise_syntax_error ( "expected ':'" ); + return self.raise_syntax_error("expected ':'") self._reset(mark) if ( - (a := self.expect('elif')) - and - (self.named_expression()) - and - (self.expect(':')) - and - (self.expect('NEWLINE')) - and - (self.negative_lookahead(self.expect, 'INDENT')) + (a := self.expect("elif")) + and (self.named_expression()) + and (self.expect(":")) + and (self.expect("NEWLINE")) + and (self.negative_lookahead(self.expect, "INDENT")) ): - return self . raise_indentation_error ( f"expected an indented block after 'elif' statement on line {a.start[0]}" ); + return self.raise_indentation_error( + f"expected an indented block after 'elif' statement on line {a.start[0]}" + ) self._reset(mark) - return None; + return None @memoize def invalid_else_stmt(self) -> Optional[NoReturn]: # invalid_else_stmt: 'else' ':' NEWLINE !INDENT mark = self._mark() if ( - (a := self.expect('else')) - and - (self.expect(':')) - and - (self.expect('NEWLINE')) - and - (self.negative_lookahead(self.expect, 'INDENT')) + (a := self.expect("else")) + and (self.expect(":")) + and (self.expect("NEWLINE")) + and (self.negative_lookahead(self.expect, "INDENT")) ): - return self . raise_indentation_error ( f"expected an indented block after 'else' statement on line {a.start[0]}" ); + return self.raise_indentation_error( + f"expected an indented block after 'else' statement on line {a.start[0]}" + ) self._reset(mark) - return None; + return None @memoize def invalid_while_stmt(self) -> Optional[NoReturn]: # invalid_while_stmt: 'while' named_expression NEWLINE | 'while' named_expression ':' NEWLINE !INDENT mark = self._mark() if ( - (self.expect('while')) - and - (self.named_expression()) - and - (self.expect('NEWLINE')) + (self.expect("while")) + and (self.named_expression()) + and (self.expect("NEWLINE")) ): - return self . raise_syntax_error ( "expected ':'" ); + return self.raise_syntax_error("expected ':'") self._reset(mark) if ( - (a := self.expect('while')) - and - (self.named_expression()) - and - (self.expect(':')) - and - (self.expect('NEWLINE')) - and - (self.negative_lookahead(self.expect, 'INDENT')) + (a := self.expect("while")) + and (self.named_expression()) + and (self.expect(":")) + and (self.expect("NEWLINE")) + and (self.negative_lookahead(self.expect, "INDENT")) ): - return self . raise_indentation_error ( f"expected an indented block after 'while' statement on line {a.start[0]}" ); + return self.raise_indentation_error( + f"expected an indented block after 'while' statement on line {a.start[0]}" + ) self._reset(mark) - return None; + return None @memoize def invalid_for_stmt(self) -> Optional[NoReturn]: # invalid_for_stmt: 'async'? 'for' star_targets 'in' star_expressions NEWLINE | 'async'? 'for' star_targets 'in' star_expressions ':' NEWLINE !INDENT mark = self._mark() if ( - (self.expect('async'),) - and - (self.expect('for')) - and - (self.star_targets()) - and - (self.expect('in')) - and - (self.star_expressions()) - and - (self.expect('NEWLINE')) + (self.expect("async"),) + and (self.expect("for")) + and (self.star_targets()) + and (self.expect("in")) + and (self.star_expressions()) + and (self.expect("NEWLINE")) ): - return self . raise_syntax_error ( "expected ':'" ); + return self.raise_syntax_error("expected ':'") self._reset(mark) if ( - (self.expect('async'),) - and - (a := self.expect('for')) - and - (self.star_targets()) - and - (self.expect('in')) - and - (self.star_expressions()) - and - (self.expect(':')) - and - (self.expect('NEWLINE')) - and - (self.negative_lookahead(self.expect, 'INDENT')) + (self.expect("async"),) + and (a := self.expect("for")) + and (self.star_targets()) + and (self.expect("in")) + and (self.star_expressions()) + and (self.expect(":")) + and (self.expect("NEWLINE")) + and (self.negative_lookahead(self.expect, "INDENT")) ): - return self . raise_indentation_error ( f"expected an indented block after 'for' statement on line {a.start[0]}" ); + return self.raise_indentation_error( + f"expected an indented block after 'for' statement on line {a.start[0]}" + ) self._reset(mark) - return None; + return None @memoize def invalid_def_raw(self) -> Optional[NoReturn]: # invalid_def_raw: 'async'? 'def' NAME type_params? '(' params? ')' ['->' expression] ':' NEWLINE !INDENT mark = self._mark() if ( - (self.expect('async'),) - and - (a := self.expect('def')) - and - (self.name()) - and - (self.type_params(),) - and - (self.expect('(')) - and - (self.params(),) - and - (self.expect(')')) - and - (self._tmp_259(),) - and - (self.expect(':')) - and - (self.expect('NEWLINE')) - and - (self.negative_lookahead(self.expect, 'INDENT')) - ): - return self . raise_indentation_error ( f"expected an indented block after function definition on line {a.start[0]}" ); - self._reset(mark) - return None; + (self.expect("async"),) + and (a := self.expect("def")) + and (self.name()) + and (self.type_params(),) + and (self.expect("(")) + and (self.params(),) + and (self.expect(")")) + and (self._tmp_265(),) + and (self.expect(":")) + and (self.expect("NEWLINE")) + and (self.negative_lookahead(self.expect, "INDENT")) + ): + return self.raise_indentation_error( + f"expected an indented block after function definition on line {a.start[0]}" + ) + self._reset(mark) + return None @memoize def invalid_class_def_raw(self) -> Optional[NoReturn]: # invalid_class_def_raw: 'class' NAME type_params? ['(' arguments? ')'] NEWLINE | 'class' NAME type_params? ['(' arguments? ')'] ':' NEWLINE !INDENT mark = self._mark() if ( - (self.expect('class')) - and - (self.name()) - and - (self.type_params(),) - and - (self._tmp_260(),) - and - (self.expect('NEWLINE')) + (self.expect("class")) + and (self.name()) + and (self.type_params(),) + and (self._tmp_266(),) + and (self.expect("NEWLINE")) ): - return self . raise_syntax_error ( "expected ':'" ); + return self.raise_syntax_error("expected ':'") self._reset(mark) if ( - (a := self.expect('class')) - and - (self.name()) - and - (self.type_params(),) - and - (self._tmp_261(),) - and - (self.expect(':')) - and - (self.expect('NEWLINE')) - and - (self.negative_lookahead(self.expect, 'INDENT')) + (a := self.expect("class")) + and (self.name()) + and (self.type_params(),) + and (self._tmp_267(),) + and (self.expect(":")) + and (self.expect("NEWLINE")) + and (self.negative_lookahead(self.expect, "INDENT")) ): - return self . raise_indentation_error ( f"expected an indented block after class definition on line {a.start[0]}" ); + return self.raise_indentation_error( + f"expected an indented block after class definition on line {a.start[0]}" + ) self._reset(mark) - return None; + return None @memoize def invalid_double_starred_kvpairs(self) -> Optional[None]: @@ -7729,4856 +8137,4292 @@ def invalid_double_starred_kvpairs(self) -> Optional[None]: mark = self._mark() if ( self.call_invalid_rules - and - (self._gather_262()) - and - (self.expect(',')) - and - (self.invalid_kvpair()) + and (self._gather_268()) + and (self.expect(",")) + and (self.invalid_kvpair()) ): - return None # pragma: no cover; + return None # pragma: no cover self._reset(mark) if ( (self.expression()) - and - (self.expect(':')) - and - (a := self.expect('*')) - and - (self.bitwise_or()) + and (self.expect(":")) + and (a := self.expect("*")) + and (self.bitwise_or()) ): - return self . raise_syntax_error_starting_from ( "cannot use a starred expression in a dictionary value" , a ); + return self.raise_syntax_error_starting_from( + "cannot use a starred expression in a dictionary value", a + ) self._reset(mark) if ( (self.expression()) - and - (a := self.expect(':')) - and - (self.positive_lookahead(self._tmp_264, )) + and (a := self.expect(":")) + and ( + self.positive_lookahead( + self._tmp_270, + ) + ) ): - return self . raise_syntax_error_known_location ( "expression expected after dictionary key and ':'" , a ); + return self.raise_syntax_error_known_location( + "expression expected after dictionary key and ':'", a + ) self._reset(mark) - return None; + return None @memoize def invalid_kvpair(self) -> Optional[None]: # invalid_kvpair: expression !(':') | expression ':' '*' bitwise_or | expression ':' &('}' | ',') | expression ':' mark = self._mark() - if ( - (a := self.expression()) - and - (self.negative_lookahead(self.expect, ':')) - ): - return self . raise_raw_syntax_error ( "':' expected after dictionary key" , ( a . lineno , a . col_offset ) , ( a . end_lineno , a . end_col_offset ) ); + if (a := self.expression()) and (self.negative_lookahead(self.expect, ":")): + return self.raise_raw_syntax_error( + "':' expected after dictionary key", + (a.lineno, a.col_offset), + (a.end_lineno, a.end_col_offset), + ) self._reset(mark) if ( (self.expression()) - and - (self.expect(':')) - and - (a := self.expect('*')) - and - (self.bitwise_or()) + and (self.expect(":")) + and (a := self.expect("*")) + and (self.bitwise_or()) ): - return self . raise_syntax_error_starting_from ( "cannot use a starred expression in a dictionary value" , a ); + return self.raise_syntax_error_starting_from( + "cannot use a starred expression in a dictionary value", a + ) self._reset(mark) if ( (self.expression()) - and - (a := self.expect(':')) - and - (self.positive_lookahead(self._tmp_265, )) + and (a := self.expect(":")) + and ( + self.positive_lookahead( + self._tmp_271, + ) + ) ): - return self . raise_syntax_error_known_location ( "expression expected after dictionary key and ':'" , a ); + return self.raise_syntax_error_known_location( + "expression expected after dictionary key and ':'", a + ) self._reset(mark) - if ( - (self.expression()) - and - (a := self.expect(':')) - ): - return self . raise_syntax_error_known_location ( "expression expected after dictionary key and ':'" , a ); + if (self.expression()) and (a := self.expect(":")): + return self.raise_syntax_error_known_location( + "expression expected after dictionary key and ':'", a + ) self._reset(mark) - return None; + return None @memoize def invalid_starred_expression(self) -> Optional[Any]: # invalid_starred_expression: '*' expression '=' expression mark = self._mark() if ( - (a := self.expect('*')) - and - (self.expression()) - and - (self.expect('=')) - and - (b := self.expression()) + (a := self.expect("*")) + and (self.expression()) + and (self.expect("=")) + and (b := self.expression()) ): - return self . raise_syntax_error_known_range ( "cannot assign to iterable argument unpacking" , a , b ); + return self.raise_syntax_error_known_range( + "cannot assign to iterable argument unpacking", a, b + ) self._reset(mark) - return None; + return None @memoize def invalid_replacement_field(self) -> Optional[Any]: # invalid_replacement_field: '{' '=' | '{' '!' | '{' ':' | '{' '}' | '{' !(yield_expr | star_expressions) | '{' (yield_expr | star_expressions) !('=' | '!' | ':' | '}') | '{' (yield_expr | star_expressions) '=' !('!' | ':' | '}') | '{' (yield_expr | star_expressions) '='? invalid_conversion_character | '{' (yield_expr | star_expressions) '='? ['!' NAME] !(':' | '}') | '{' (yield_expr | star_expressions) '='? ['!' NAME] ':' fstring_format_spec* !'}' | '{' (yield_expr | star_expressions) '='? ['!' NAME] !'}' mark = self._mark() - if ( - (self.expect('{')) - and - (a := self.expect('=')) + if (self.expect("{")) and (a := self.expect("=")): + return self.raise_syntax_error_known_location( + "f-string: valid expression required before '='", a + ) + self._reset(mark) + if (self.expect("{")) and (a := self.expect("!")): + return self.raise_syntax_error_known_location( + "f-string: valid expression required before '!'", a + ) + self._reset(mark) + if (self.expect("{")) and (a := self.expect(":")): + return self.raise_syntax_error_known_location( + "f-string: valid expression required before ':'", a + ) + self._reset(mark) + if (self.expect("{")) and (a := self.expect("}")): + return self.raise_syntax_error_known_location( + "f-string: valid expression required before '}'", a + ) + self._reset(mark) + if (self.expect("{")) and ( + self.negative_lookahead( + self._tmp_272, + ) ): - return self . raise_syntax_error_known_location ( "f-string: valid expression required before '='" , a ); + return self.raise_syntax_error_on_next_token( + "f-string: expecting a valid expression after '{'" + ) self._reset(mark) if ( - (self.expect('{')) - and - (a := self.expect('!')) + (self.expect("{")) + and (self._tmp_273()) + and ( + self.negative_lookahead( + self._tmp_274, + ) + ) ): - return self . raise_syntax_error_known_location ( "f-string: valid expression required before '!'" , a ); + return self.raise_syntax_error_on_next_token( + "f-string: expecting '=', or '!', or ':', or '}'" + ) self._reset(mark) if ( - (self.expect('{')) - and - (a := self.expect(':')) + (self.expect("{")) + and (self._tmp_275()) + and (self.expect("=")) + and ( + self.negative_lookahead( + self._tmp_276, + ) + ) ): - return self . raise_syntax_error_known_location ( "f-string: valid expression required before ':'" , a ); + return self.raise_syntax_error_on_next_token( + "f-string: expecting '!', or ':', or '}'" + ) self._reset(mark) if ( - (self.expect('{')) - and - (a := self.expect('}')) + self.call_invalid_rules + and (self.expect("{")) + and (self._tmp_277()) + and (self.expect("="),) + and (self.invalid_conversion_character()) ): - return self . raise_syntax_error_known_location ( "f-string: valid expression required before '}'" , a ); + return None # pragma: no cover self._reset(mark) if ( - (self.expect('{')) - and - (self.negative_lookahead(self._tmp_266, )) + (self.expect("{")) + and (self._tmp_278()) + and (self.expect("="),) + and (self._tmp_279(),) + and ( + self.negative_lookahead( + self._tmp_280, + ) + ) ): - return self . raise_syntax_error_on_next_token ( "f-string: expecting a valid expression after '{'" ); + return self.raise_syntax_error_on_next_token( + "f-string: expecting ':' or '}'" + ) self._reset(mark) if ( - (self.expect('{')) - and - (self._tmp_267()) - and - (self.negative_lookahead(self._tmp_268, )) + (self.expect("{")) + and (self._tmp_281()) + and (self.expect("="),) + and (self._tmp_282(),) + and (self.expect(":")) + and (self._loop0_283(),) + and (self.negative_lookahead(self.expect, "}")) ): - return self . raise_syntax_error_on_next_token ( "f-string: expecting '=', or '!', or ':', or '}'" ); + return self.raise_syntax_error_on_next_token( + "f-string: expecting '}', or format specs" + ) self._reset(mark) if ( - (self.expect('{')) - and - (self._tmp_269()) - and - (self.expect('=')) - and - (self.negative_lookahead(self._tmp_270, )) + (self.expect("{")) + and (self._tmp_284()) + and (self.expect("="),) + and (self._tmp_285(),) + and (self.negative_lookahead(self.expect, "}")) ): - return self . raise_syntax_error_on_next_token ( "f-string: expecting '!', or ':', or '}'" ); + return self.raise_syntax_error_on_next_token("f-string: expecting '}'") self._reset(mark) - if ( - self.call_invalid_rules - and - (self.expect('{')) - and - (self._tmp_271()) - and - (self.expect('='),) - and - (self.invalid_conversion_character()) - ): - return None # pragma: no cover; - self._reset(mark) - if ( - (self.expect('{')) - and - (self._tmp_272()) - and - (self.expect('='),) - and - (self._tmp_273(),) - and - (self.negative_lookahead(self._tmp_274, )) - ): - return self . raise_syntax_error_on_next_token ( "f-string: expecting ':' or '}'" ); - self._reset(mark) - if ( - (self.expect('{')) - and - (self._tmp_275()) - and - (self.expect('='),) - and - (self._tmp_276(),) - and - (self.expect(':')) - and - (self._loop0_277(),) - and - (self.negative_lookahead(self.expect, '}')) - ): - return self . raise_syntax_error_on_next_token ( "f-string: expecting '}', or format specs" ); - self._reset(mark) - if ( - (self.expect('{')) - and - (self._tmp_278()) - and - (self.expect('='),) - and - (self._tmp_279(),) - and - (self.negative_lookahead(self.expect, '}')) - ): - return self . raise_syntax_error_on_next_token ( "f-string: expecting '}'" ); - self._reset(mark) - return None; + return None @memoize def invalid_conversion_character(self) -> Optional[Any]: # invalid_conversion_character: '!' &(':' | '}') | '!' !NAME mark = self._mark() - if ( - (self.expect('!')) - and - (self.positive_lookahead(self._tmp_280, )) + if (self.expect("!")) and ( + self.positive_lookahead( + self._tmp_286, + ) ): - return self . raise_syntax_error_on_next_token ( "f-string: missing conversion character" ); + return self.raise_syntax_error_on_next_token( + "f-string: missing conversion character" + ) self._reset(mark) - if ( - (self.expect('!')) - and - (self.negative_lookahead(self.name, )) + if (self.expect("!")) and ( + self.negative_lookahead( + self.name, + ) ): - return self . raise_syntax_error_on_next_token ( "f-string: invalid conversion character" ); + return self.raise_syntax_error_on_next_token( + "f-string: invalid conversion character" + ) self._reset(mark) - return None; + return None @memoize - def _loop0_1(self) -> Optional[Any]: - # _loop0_1: enaml_item + def invalid_tstring_replacement_field(self) -> Optional[Any]: + # invalid_tstring_replacement_field: '{' '=' | '{' '!' | '{' ':' | '{' '}' | '{' !(yield_expr | star_expressions) | '{' (yield_expr | star_expressions) !('=' | '!' | ':' | '}') | '{' (yield_expr | star_expressions) '=' !('!' | ':' | '}') | '{' (yield_expr | star_expressions) '='? invalid_tstring_conversion_character | '{' (yield_expr | star_expressions) '='? ['!' NAME] !(':' | '}') | '{' (yield_expr | star_expressions) '='? ['!' NAME] ':' tstring_format_spec* !'}' | '{' (yield_expr | star_expressions) '='? ['!' NAME] !'}' mark = self._mark() - children = [] - while ( - (enaml_item := self.enaml_item()) - ): - children.append(enaml_item) - mark = self._mark() + if (self.expect("{")) and (a := self.expect("=")): + return self.raise_syntax_error_known_location( + "t-string: valid expression required before '='", a + ) self._reset(mark) - return children; - - @memoize - def _loop0_2(self) -> Optional[Any]: - # _loop0_2: pragma - mark = self._mark() - children = [] - while ( - (pragma := self.pragma()) + if (self.expect("{")) and (a := self.expect("!")): + return self.raise_syntax_error_known_location( + "t-string: valid expression required before '!'", a + ) + self._reset(mark) + if (self.expect("{")) and (a := self.expect(":")): + return self.raise_syntax_error_known_location( + "t-string: valid expression required before ':'", a + ) + self._reset(mark) + if (self.expect("{")) and (a := self.expect("}")): + return self.raise_syntax_error_known_location( + "t-string: valid expression required before '}'", a + ) + self._reset(mark) + if (self.expect("{")) and ( + self.negative_lookahead( + self._tmp_287, + ) ): - children.append(pragma) - mark = self._mark() + return self.raise_syntax_error_on_next_token( + "t-string: expecting a valid expression after '{'" + ) self._reset(mark) - return children; - - @memoize - def _tmp_3(self) -> Optional[Any]: - # _tmp_3: ':' NAME - mark = self._mark() if ( - (self.expect(':')) - and - (z := self.name()) + (self.expect("{")) + and (self._tmp_288()) + and ( + self.negative_lookahead( + self._tmp_289, + ) + ) ): - return z; + return self.raise_syntax_error_on_next_token( + "t-string: expecting '=', or '!', or ':', or '}'" + ) self._reset(mark) - return None; + if ( + (self.expect("{")) + and (self._tmp_290()) + and (self.expect("=")) + and ( + self.negative_lookahead( + self._tmp_291, + ) + ) + ): + return self.raise_syntax_error_on_next_token( + "t-string: expecting '!', or ':', or '}'" + ) + self._reset(mark) + if ( + self.call_invalid_rules + and (self.expect("{")) + and (self._tmp_292()) + and (self.expect("="),) + and (self.invalid_tstring_conversion_character()) + ): + return None # pragma: no cover + self._reset(mark) + if ( + (self.expect("{")) + and (self._tmp_293()) + and (self.expect("="),) + and (self._tmp_294(),) + and ( + self.negative_lookahead( + self._tmp_295, + ) + ) + ): + return self.raise_syntax_error_on_next_token( + "t-string: expecting ':' or '}'" + ) + self._reset(mark) + if ( + (self.expect("{")) + and (self._tmp_296()) + and (self.expect("="),) + and (self._tmp_297(),) + and (self.expect(":")) + and (self._loop0_298(),) + and (self.negative_lookahead(self.expect, "}")) + ): + return self.raise_syntax_error_on_next_token( + "t-string: expecting '}', or format specs" + ) + self._reset(mark) + if ( + (self.expect("{")) + and (self._tmp_299()) + and (self.expect("="),) + and (self._tmp_300(),) + and (self.negative_lookahead(self.expect, "}")) + ): + return self.raise_syntax_error_on_next_token("t-string: expecting '}'") + self._reset(mark) + return None + + @memoize + def invalid_tstring_conversion_character(self) -> Optional[Any]: + # invalid_tstring_conversion_character: '!' &(':' | '}') | '!' !NAME + mark = self._mark() + if (self.expect("!")) and ( + self.positive_lookahead( + self._tmp_301, + ) + ): + return self.raise_syntax_error_on_next_token( + "t-string: missing conversion character" + ) + self._reset(mark) + if (self.expect("!")) and ( + self.negative_lookahead( + self.name, + ) + ): + return self.raise_syntax_error_on_next_token( + "t-string: invalid conversion character" + ) + self._reset(mark) + return None + + @memoize + def invalid_string_tstring_concat(self) -> Optional[Any]: + # invalid_string_tstring_concat: ((fstring | STRING))+ tstring | tstring+ (fstring | STRING) + mark = self._mark() + if (a := self._loop1_302()) and (b := self.tstring()): + return self.raise_syntax_error_known_range( + "cannot mix t-string literals with string or bytes literals", a[-1], b + ) + self._reset(mark) + if (a := self._loop1_303()) and (b := self._tmp_304()): + return self.raise_syntax_error_known_range( + "cannot mix t-string literals with string or bytes literals", a[-1], b + ) + self._reset(mark) + return None + + @memoize + def _loop0_1(self) -> Optional[Any]: + # _loop0_1: enaml_item + mark = self._mark() + children = [] + while enaml_item := self.enaml_item(): + children.append(enaml_item) + mark = self._mark() + self._reset(mark) + return children + + @memoize + def _loop0_2(self) -> Optional[Any]: + # _loop0_2: pragma + mark = self._mark() + children = [] + while pragma := self.pragma(): + children.append(pragma) + mark = self._mark() + self._reset(mark) + return children + + @memoize + def _tmp_3(self) -> Optional[Any]: + # _tmp_3: ':' NAME + mark = self._mark() + if (self.expect(":")) and (z := self.name()): + return z + self._reset(mark) + return None @memoize def _loop1_4(self) -> Optional[Any]: # _loop1_4: enamldef_item mark = self._mark() children = [] - while ( - (enamldef_item := self.enamldef_item()) - ): + while enamldef_item := self.enamldef_item(): children.append(enamldef_item) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _loop1_5(self) -> Optional[Any]: # _loop1_5: enamldef_item mark = self._mark() children = [] - while ( - (enamldef_item := self.enamldef_item()) - ): + while enamldef_item := self.enamldef_item(): children.append(enamldef_item) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _loop1_6(self) -> Optional[Any]: # _loop1_6: pragma mark = self._mark() children = [] - while ( - (pragma := self.pragma()) - ): + while pragma := self.pragma(): children.append(pragma) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _tmp_7(self) -> Optional[Any]: # _tmp_7: '(' ','.pragma_arg+ ')' mark = self._mark() - if ( - (self.expect('(')) - and - (b := self._gather_281()) - and - (self.expect(')')) - ): - return b; + if (self.expect("(")) and (b := self._gather_305()) and (self.expect(")")): + return b self._reset(mark) - return None; + return None @memoize def _tmp_8(self) -> Optional[Any]: # _tmp_8: ':' '.'.NAME+ mark = self._mark() - if ( - (self.expect(':')) - and - (c := self._gather_283()) - ): - return c; + if (self.expect(":")) and (c := self._gather_307()): + return c self._reset(mark) - return None; + return None @memoize def _tmp_9(self) -> Optional[Any]: # _tmp_9: ':' dec_primary mark = self._mark() - if ( - (self.expect(':')) - and - (c := self.dec_primary()) - ): - return c; + if (self.expect(":")) and (c := self.dec_primary()): + return c self._reset(mark) - return None; + return None @memoize def _tmp_10(self) -> Optional[Any]: # _tmp_10: "attr" | "event" mark = self._mark() - if ( - (literal := self.expect("attr")) - ): - return literal; + if literal := self.expect("attr"): + return literal self._reset(mark) - if ( - (literal := self.expect("event")) - ): - return literal; + if literal := self.expect("event"): + return literal self._reset(mark) - return None; + return None @memoize def _tmp_11(self) -> Optional[Any]: # _tmp_11: ':' dec_primary mark = self._mark() - if ( - (self.expect(':')) - and - (d := self.dec_primary()) - ): - return d; + if (self.expect(":")) and (d := self.dec_primary()): + return d self._reset(mark) - return None; + return None @memoize def _tmp_12(self) -> Optional[Any]: # _tmp_12: "attr" | "event" mark = self._mark() - if ( - (literal := self.expect("attr")) - ): - return literal; + if literal := self.expect("attr"): + return literal self._reset(mark) - if ( - (literal := self.expect("event")) - ): - return literal; + if literal := self.expect("event"): + return literal self._reset(mark) - return None; + return None @memoize def _tmp_13(self) -> Optional[Any]: # _tmp_13: ':' dec_primary mark = self._mark() - if ( - (self.expect(':')) - and - (d := self.dec_primary()) - ): - return d; + if (self.expect(":")) and (d := self.dec_primary()): + return d self._reset(mark) - return None; + return None @memoize def _loop1_14(self) -> Optional[Any]: # _loop1_14: child_def_item mark = self._mark() children = [] - while ( - (child_def_item := self.child_def_item()) - ): + while child_def_item := self.child_def_item(): children.append(child_def_item) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _loop0_16(self) -> Optional[Any]: # _loop0_16: '.' NAME mark = self._mark() children = [] - while ( - (self.expect('.')) - and - (elem := self.name()) - ): + while (self.expect(".")) and (elem := self.name()): children.append(elem) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _gather_15(self) -> Optional[Any]: # _gather_15: NAME _loop0_16 mark = self._mark() - if ( - (elem := self.name()) - is not None - and - (seq := self._loop0_16()) - is not None - ): - return [elem] + seq; + if (elem := self.name()) is not None and (seq := self._loop0_16()) is not None: + return [elem] + seq self._reset(mark) - return None; + return None @memoize def _tmp_17(self) -> Optional[Any]: # _tmp_17: '=' | '<<' mark = self._mark() - if ( - (literal := self.expect('=')) - ): - return literal; + if literal := self.expect("="): + return literal self._reset(mark) - if ( - (literal := self.expect('<<')) - ): - return literal; + if literal := self.expect("<<"): + return literal self._reset(mark) - return None; + return None @memoize def _tmp_18(self) -> Optional[Any]: # _tmp_18: '>>' | ':=' mark = self._mark() - if ( - (literal := self.expect('>>')) - ): - return literal; + if literal := self.expect(">>"): + return literal self._reset(mark) - if ( - (literal := self.expect(':=')) - ): - return literal; + if literal := self.expect(":="): + return literal self._reset(mark) - return None; + return None @memoize def _tmp_19(self) -> Optional[Any]: # _tmp_19: '->' expression mark = self._mark() - if ( - (self.expect('->')) - and - (z := self.expression()) - ): - return z; + if (self.expect("->")) and (z := self.expression()): + return z self._reset(mark) - return None; + return None @memoize def _tmp_20(self) -> Optional[Any]: # _tmp_20: '->' expression mark = self._mark() - if ( - (self.expect('->')) - and - (z := self.expression()) - ): - return z; + if (self.expect("->")) and (z := self.expression()): + return z self._reset(mark) - return None; + return None @memoize def _loop1_21(self) -> Optional[Any]: # _loop1_21: template_item mark = self._mark() children = [] - while ( - (template_item := self.template_item()) - ): + while template_item := self.template_item(): children.append(template_item) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _loop1_22(self) -> Optional[Any]: # _loop1_22: template_item mark = self._mark() children = [] - while ( - (template_item := self.template_item()) - ): + while template_item := self.template_item(): children.append(template_item) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _loop0_24(self) -> Optional[Any]: # _loop0_24: ',' template_param mark = self._mark() children = [] - while ( - (self.expect(',')) - and - (elem := self.template_param()) - ): + while (self.expect(",")) and (elem := self.template_param()): children.append(elem) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _gather_23(self) -> Optional[Any]: # _gather_23: template_param _loop0_24 mark = self._mark() - if ( - (elem := self.template_param()) - is not None - and - (seq := self._loop0_24()) - is not None - ): - return [elem] + seq; + if (elem := self.template_param()) is not None and ( + seq := self._loop0_24() + ) is not None: + return [elem] + seq self._reset(mark) - return None; + return None @memoize def _tmp_25(self) -> Optional[Any]: # _tmp_25: ',' '*' NAME mark = self._mark() - if ( - (self.expect(',')) - and - (self.expect('*')) - and - (c := self.name()) - ): - return c; + if (self.expect(",")) and (self.expect("*")) and (c := self.name()): + return c self._reset(mark) - return None; + return None @memoize def _tmp_26(self) -> Optional[Any]: # _tmp_26: ':' template_ids mark = self._mark() - if ( - (self.expect(':')) - and - (z := self.template_ids()) - ): - return z; + if (self.expect(":")) and (z := self.template_ids()): + return z self._reset(mark) - return None; + return None @memoize def _loop0_28(self) -> Optional[Any]: # _loop0_28: ',' template_argument mark = self._mark() children = [] - while ( - (self.expect(',')) - and - (elem := self.template_argument()) - ): + while (self.expect(",")) and (elem := self.template_argument()): children.append(elem) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _gather_27(self) -> Optional[Any]: # _gather_27: template_argument _loop0_28 mark = self._mark() - if ( - (elem := self.template_argument()) - is not None - and - (seq := self._loop0_28()) - is not None - ): - return [elem] + seq; + if (elem := self.template_argument()) is not None and ( + seq := self._loop0_28() + ) is not None: + return [elem] + seq self._reset(mark) - return None; + return None @memoize def _tmp_29(self) -> Optional[Any]: # _tmp_29: ',' '*' expression mark = self._mark() - if ( - (self.expect(',')) - and - (self.expect('*')) - and - (z := self.expression()) - ): - return z; + if (self.expect(",")) and (self.expect("*")) and (z := self.expression()): + return z self._reset(mark) - return None; + return None @memoize def _loop0_31(self) -> Optional[Any]: # _loop0_31: ',' NAME mark = self._mark() children = [] - while ( - (self.expect(',')) - and - (elem := self.name()) - ): + while (self.expect(",")) and (elem := self.name()): children.append(elem) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _gather_30(self) -> Optional[Any]: # _gather_30: NAME _loop0_31 mark = self._mark() - if ( - (elem := self.name()) - is not None - and - (seq := self._loop0_31()) - is not None - ): - return [elem] + seq; + if (elem := self.name()) is not None and (seq := self._loop0_31()) is not None: + return [elem] + seq self._reset(mark) - return None; + return None @memoize def _tmp_32(self) -> Optional[Any]: # _tmp_32: ',' '*' NAME mark = self._mark() - if ( - (self.expect(',')) - and - (self.expect('*')) - and - (z := self.name()) - ): - return z; + if (self.expect(",")) and (self.expect("*")) and (z := self.name()): + return z self._reset(mark) - return None; + return None @memoize def _loop1_33(self) -> Optional[Any]: # _loop1_33: template_inst_item mark = self._mark() children = [] - while ( - (template_inst_item := self.template_inst_item()) - ): + while template_inst_item := self.template_inst_item(): children.append(template_inst_item) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _tmp_34(self) -> Optional[Any]: # _tmp_34: '.' '.'.NAME+ mark = self._mark() - if ( - (self.expect('.')) - and - (z := self._gather_285()) - ): - return z; + if (self.expect(".")) and (z := self._gather_309()): + return z self._reset(mark) - return None; + return None @memoize def _loop1_35(self) -> Optional[Any]: # _loop1_35: statement mark = self._mark() children = [] - while ( - (statement := self.statement()) - ): + while statement := self.statement(): children.append(statement) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _loop0_37(self) -> Optional[Any]: # _loop0_37: ';' simple_stmt mark = self._mark() children = [] - while ( - (self.expect(';')) - and - (elem := self.simple_stmt()) - ): + while (self.expect(";")) and (elem := self.simple_stmt()): children.append(elem) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _gather_36(self) -> Optional[Any]: # _gather_36: simple_stmt _loop0_37 mark = self._mark() - if ( - (elem := self.simple_stmt()) - is not None - and - (seq := self._loop0_37()) - is not None - ): - return [elem] + seq; + if (elem := self.simple_stmt()) is not None and ( + seq := self._loop0_37() + ) is not None: + return [elem] + seq self._reset(mark) - return None; + return None @memoize def _tmp_38(self) -> Optional[Any]: - # _tmp_38: 'import' | 'from' + # _tmp_38: 'import' | 'from' | "lazy" mark = self._mark() - if ( - (literal := self.expect('import')) - ): - return literal; + if literal := self.expect("import"): + return literal self._reset(mark) - if ( - (literal := self.expect('from')) - ): - return literal; + if literal := self.expect("from"): + return literal + self._reset(mark) + if literal := self.expect("lazy"): + return literal self._reset(mark) - return None; + return None @memoize def _tmp_39(self) -> Optional[Any]: # _tmp_39: 'def' | '@' | 'async' mark = self._mark() - if ( - (literal := self.expect('def')) - ): - return literal; + if literal := self.expect("def"): + return literal self._reset(mark) - if ( - (literal := self.expect('@')) - ): - return literal; + if literal := self.expect("@"): + return literal self._reset(mark) - if ( - (literal := self.expect('async')) - ): - return literal; + if literal := self.expect("async"): + return literal self._reset(mark) - return None; + return None @memoize def _tmp_40(self) -> Optional[Any]: # _tmp_40: 'class' | '@' mark = self._mark() - if ( - (literal := self.expect('class')) - ): - return literal; + if literal := self.expect("class"): + return literal self._reset(mark) - if ( - (literal := self.expect('@')) - ): - return literal; + if literal := self.expect("@"): + return literal self._reset(mark) - return None; + return None @memoize def _tmp_41(self) -> Optional[Any]: # _tmp_41: 'with' | 'async' mark = self._mark() - if ( - (literal := self.expect('with')) - ): - return literal; + if literal := self.expect("with"): + return literal self._reset(mark) - if ( - (literal := self.expect('async')) - ): - return literal; + if literal := self.expect("async"): + return literal self._reset(mark) - return None; + return None @memoize def _tmp_42(self) -> Optional[Any]: # _tmp_42: 'for' | 'async' mark = self._mark() - if ( - (literal := self.expect('for')) - ): - return literal; + if literal := self.expect("for"): + return literal self._reset(mark) - if ( - (literal := self.expect('async')) - ): - return literal; + if literal := self.expect("async"): + return literal self._reset(mark) - return None; + return None @memoize def _tmp_43(self) -> Optional[Any]: # _tmp_43: '=' annotated_rhs mark = self._mark() - if ( - (self.expect('=')) - and - (d := self.annotated_rhs()) - ): - return d; + if (self.expect("=")) and (d := self.annotated_rhs()): + return d self._reset(mark) - return None; + return None @memoize def _tmp_44(self) -> Optional[Any]: # _tmp_44: '(' single_target ')' | single_subscript_attribute_target mark = self._mark() - if ( - (self.expect('(')) - and - (b := self.single_target()) - and - (self.expect(')')) - ): - return b; + if (self.expect("(")) and (b := self.single_target()) and (self.expect(")")): + return b self._reset(mark) if ( - (single_subscript_attribute_target := self.single_subscript_attribute_target()) + single_subscript_attribute_target + := self.single_subscript_attribute_target() ): - return single_subscript_attribute_target; + return single_subscript_attribute_target self._reset(mark) - return None; + return None @memoize def _tmp_45(self) -> Optional[Any]: # _tmp_45: '=' annotated_rhs mark = self._mark() - if ( - (self.expect('=')) - and - (d := self.annotated_rhs()) - ): - return d; + if (self.expect("=")) and (d := self.annotated_rhs()): + return d self._reset(mark) - return None; + return None @memoize def _loop1_46(self) -> Optional[Any]: # _loop1_46: (star_targets '=') mark = self._mark() children = [] - while ( - (_tmp_287 := self._tmp_287()) - ): - children.append(_tmp_287) + while _tmp_311 := self._tmp_311(): + children.append(_tmp_311) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _tmp_47(self) -> Optional[Any]: # _tmp_47: yield_expr | star_expressions mark = self._mark() - if ( - (yield_expr := self.yield_expr()) - ): - return yield_expr; + if yield_expr := self.yield_expr(): + return yield_expr self._reset(mark) - if ( - (star_expressions := self.star_expressions()) - ): - return star_expressions; + if star_expressions := self.star_expressions(): + return star_expressions self._reset(mark) - return None; + return None @memoize def _tmp_48(self) -> Optional[Any]: # _tmp_48: yield_expr | star_expressions mark = self._mark() - if ( - (yield_expr := self.yield_expr()) - ): - return yield_expr; + if yield_expr := self.yield_expr(): + return yield_expr self._reset(mark) - if ( - (star_expressions := self.star_expressions()) - ): - return star_expressions; + if star_expressions := self.star_expressions(): + return star_expressions self._reset(mark) - return None; + return None @memoize def _tmp_49(self) -> Optional[Any]: # _tmp_49: 'from' expression mark = self._mark() - if ( - (self.expect('from')) - and - (z := self.expression()) - ): - return z; + if (self.expect("from")) and (z := self.expression()): + return z self._reset(mark) - return None; + return None @memoize def _loop0_51(self) -> Optional[Any]: # _loop0_51: ',' NAME mark = self._mark() children = [] - while ( - (self.expect(',')) - and - (elem := self.name()) - ): + while (self.expect(",")) and (elem := self.name()): children.append(elem) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _gather_50(self) -> Optional[Any]: # _gather_50: NAME _loop0_51 mark = self._mark() - if ( - (elem := self.name()) - is not None - and - (seq := self._loop0_51()) - is not None - ): - return [elem] + seq; + if (elem := self.name()) is not None and (seq := self._loop0_51()) is not None: + return [elem] + seq self._reset(mark) - return None; + return None @memoize def _loop0_53(self) -> Optional[Any]: # _loop0_53: ',' NAME mark = self._mark() children = [] - while ( - (self.expect(',')) - and - (elem := self.name()) - ): + while (self.expect(",")) and (elem := self.name()): children.append(elem) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _gather_52(self) -> Optional[Any]: # _gather_52: NAME _loop0_53 mark = self._mark() - if ( - (elem := self.name()) - is not None - and - (seq := self._loop0_53()) - is not None - ): - return [elem] + seq; + if (elem := self.name()) is not None and (seq := self._loop0_53()) is not None: + return [elem] + seq self._reset(mark) - return None; + return None @memoize def _tmp_54(self) -> Optional[Any]: # _tmp_54: ';' | NEWLINE mark = self._mark() - if ( - (literal := self.expect(';')) - ): - return literal; + if literal := self.expect(";"): + return literal self._reset(mark) - if ( - (_newline := self.expect('NEWLINE')) - ): - return _newline; + if _newline := self.expect("NEWLINE"): + return _newline self._reset(mark) - return None; + return None @memoize def _tmp_55(self) -> Optional[Any]: # _tmp_55: ',' expression mark = self._mark() - if ( - (self.expect(',')) - and - (z := self.expression()) - ): - return z; + if (self.expect(",")) and (z := self.expression()): + return z self._reset(mark) - return None; + return None @memoize def _loop0_56(self) -> Optional[Any]: # _loop0_56: ('.' | '...') mark = self._mark() children = [] - while ( - (_tmp_288 := self._tmp_288()) - ): - children.append(_tmp_288) + while _tmp_312 := self._tmp_312(): + children.append(_tmp_312) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _loop1_57(self) -> Optional[Any]: # _loop1_57: ('.' | '...') mark = self._mark() children = [] - while ( - (_tmp_289 := self._tmp_289()) - ): - children.append(_tmp_289) + while _tmp_313 := self._tmp_313(): + children.append(_tmp_313) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _loop0_59(self) -> Optional[Any]: # _loop0_59: ',' import_from_as_name mark = self._mark() children = [] - while ( - (self.expect(',')) - and - (elem := self.import_from_as_name()) - ): + while (self.expect(",")) and (elem := self.import_from_as_name()): children.append(elem) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _gather_58(self) -> Optional[Any]: # _gather_58: import_from_as_name _loop0_59 mark = self._mark() - if ( - (elem := self.import_from_as_name()) - is not None - and - (seq := self._loop0_59()) - is not None - ): - return [elem] + seq; + if (elem := self.import_from_as_name()) is not None and ( + seq := self._loop0_59() + ) is not None: + return [elem] + seq self._reset(mark) - return None; + return None @memoize def _tmp_60(self) -> Optional[Any]: # _tmp_60: 'as' NAME mark = self._mark() - if ( - (self.expect('as')) - and - (z := self.name()) - ): - return z . string; + if (self.expect("as")) and (z := self.name()): + return z.string self._reset(mark) - return None; + return None @memoize def _loop0_62(self) -> Optional[Any]: # _loop0_62: ',' dotted_as_name mark = self._mark() children = [] - while ( - (self.expect(',')) - and - (elem := self.dotted_as_name()) - ): + while (self.expect(",")) and (elem := self.dotted_as_name()): children.append(elem) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _gather_61(self) -> Optional[Any]: # _gather_61: dotted_as_name _loop0_62 mark = self._mark() - if ( - (elem := self.dotted_as_name()) - is not None - and - (seq := self._loop0_62()) - is not None - ): - return [elem] + seq; + if (elem := self.dotted_as_name()) is not None and ( + seq := self._loop0_62() + ) is not None: + return [elem] + seq self._reset(mark) - return None; + return None @memoize def _tmp_63(self) -> Optional[Any]: # _tmp_63: 'as' NAME mark = self._mark() - if ( - (self.expect('as')) - and - (z := self.name()) - ): - return z . string; + if (self.expect("as")) and (z := self.name()): + return z.string self._reset(mark) - return None; + return None @memoize def _loop1_64(self) -> Optional[Any]: # _loop1_64: decorator mark = self._mark() children = [] - while ( - (decorator := self.decorator()) - ): + while decorator := self.decorator(): children.append(decorator) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _tmp_65(self) -> Optional[Any]: # _tmp_65: '@' dec_maybe_call NEWLINE mark = self._mark() if ( - (self.expect('@')) - and - (f := self.dec_maybe_call()) - and - (self.expect('NEWLINE')) + (self.expect("@")) + and (f := self.dec_maybe_call()) + and (self.expect("NEWLINE")) ): - return f; + return f self._reset(mark) - return None; + return None @memoize def _tmp_66(self) -> Optional[Any]: # _tmp_66: '@' named_expression NEWLINE mark = self._mark() if ( - (self.expect('@')) - and - (f := self.named_expression()) - and - (self.expect('NEWLINE')) + (self.expect("@")) + and (f := self.named_expression()) + and (self.expect("NEWLINE")) ): - return f; + return f self._reset(mark) - return None; + return None @memoize def _tmp_67(self) -> Optional[Any]: # _tmp_67: '(' arguments? ')' mark = self._mark() - if ( - (self.expect('(')) - and - (z := self.arguments(),) - and - (self.expect(')')) - ): - return z; + if (self.expect("(")) and (z := self.arguments(),) and (self.expect(")")): + return z self._reset(mark) - return None; + return None @memoize def _tmp_68(self) -> Optional[Any]: # _tmp_68: '->' expression mark = self._mark() - if ( - (self.expect('->')) - and - (z := self.expression()) - ): - return z; + if (self.expect("->")) and (z := self.expression()): + return z self._reset(mark) - return None; + return None @memoize def _tmp_69(self) -> Optional[Any]: # _tmp_69: '->' expression mark = self._mark() - if ( - (self.expect('->')) - and - (z := self.expression()) - ): - return z; + if (self.expect("->")) and (z := self.expression()): + return z self._reset(mark) - return None; + return None @memoize def _loop0_70(self) -> Optional[Any]: # _loop0_70: param_no_default mark = self._mark() children = [] - while ( - (param_no_default := self.param_no_default()) - ): + while param_no_default := self.param_no_default(): children.append(param_no_default) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _loop0_71(self) -> Optional[Any]: # _loop0_71: param_with_default mark = self._mark() children = [] - while ( - (param_with_default := self.param_with_default()) - ): + while param_with_default := self.param_with_default(): children.append(param_with_default) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _loop0_72(self) -> Optional[Any]: # _loop0_72: param_with_default mark = self._mark() children = [] - while ( - (param_with_default := self.param_with_default()) - ): + while param_with_default := self.param_with_default(): children.append(param_with_default) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _loop1_73(self) -> Optional[Any]: # _loop1_73: param_no_default mark = self._mark() children = [] - while ( - (param_no_default := self.param_no_default()) - ): + while param_no_default := self.param_no_default(): children.append(param_no_default) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _loop0_74(self) -> Optional[Any]: # _loop0_74: param_with_default mark = self._mark() children = [] - while ( - (param_with_default := self.param_with_default()) - ): + while param_with_default := self.param_with_default(): children.append(param_with_default) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _loop1_75(self) -> Optional[Any]: # _loop1_75: param_with_default mark = self._mark() children = [] - while ( - (param_with_default := self.param_with_default()) - ): + while param_with_default := self.param_with_default(): children.append(param_with_default) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _loop1_76(self) -> Optional[Any]: # _loop1_76: param_no_default mark = self._mark() children = [] - while ( - (param_no_default := self.param_no_default()) - ): + while param_no_default := self.param_no_default(): children.append(param_no_default) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _loop1_77(self) -> Optional[Any]: # _loop1_77: param_no_default mark = self._mark() children = [] - while ( - (param_no_default := self.param_no_default()) - ): + while param_no_default := self.param_no_default(): children.append(param_no_default) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _loop0_78(self) -> Optional[Any]: # _loop0_78: param_no_default mark = self._mark() children = [] - while ( - (param_no_default := self.param_no_default()) - ): + while param_no_default := self.param_no_default(): children.append(param_no_default) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _loop1_79(self) -> Optional[Any]: # _loop1_79: param_with_default mark = self._mark() children = [] - while ( - (param_with_default := self.param_with_default()) - ): + while param_with_default := self.param_with_default(): children.append(param_with_default) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _loop0_80(self) -> Optional[Any]: # _loop0_80: param_no_default mark = self._mark() children = [] - while ( - (param_no_default := self.param_no_default()) - ): + while param_no_default := self.param_no_default(): children.append(param_no_default) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _loop1_81(self) -> Optional[Any]: # _loop1_81: param_with_default mark = self._mark() children = [] - while ( - (param_with_default := self.param_with_default()) - ): + while param_with_default := self.param_with_default(): children.append(param_with_default) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _loop0_82(self) -> Optional[Any]: # _loop0_82: param_maybe_default mark = self._mark() children = [] - while ( - (param_maybe_default := self.param_maybe_default()) - ): + while param_maybe_default := self.param_maybe_default(): children.append(param_maybe_default) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _loop0_83(self) -> Optional[Any]: # _loop0_83: param_maybe_default mark = self._mark() children = [] - while ( - (param_maybe_default := self.param_maybe_default()) - ): + while param_maybe_default := self.param_maybe_default(): children.append(param_maybe_default) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _loop1_84(self) -> Optional[Any]: # _loop1_84: param_maybe_default mark = self._mark() children = [] - while ( - (param_maybe_default := self.param_maybe_default()) - ): + while param_maybe_default := self.param_maybe_default(): children.append(param_maybe_default) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _loop0_86(self) -> Optional[Any]: # _loop0_86: ',' with_item mark = self._mark() children = [] - while ( - (self.expect(',')) - and - (elem := self.with_item()) - ): + while (self.expect(",")) and (elem := self.with_item()): children.append(elem) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _gather_85(self) -> Optional[Any]: # _gather_85: with_item _loop0_86 mark = self._mark() - if ( - (elem := self.with_item()) - is not None - and - (seq := self._loop0_86()) - is not None - ): - return [elem] + seq; + if (elem := self.with_item()) is not None and ( + seq := self._loop0_86() + ) is not None: + return [elem] + seq self._reset(mark) - return None; + return None @memoize def _loop0_88(self) -> Optional[Any]: # _loop0_88: ',' with_item mark = self._mark() children = [] - while ( - (self.expect(',')) - and - (elem := self.with_item()) - ): + while (self.expect(",")) and (elem := self.with_item()): children.append(elem) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _gather_87(self) -> Optional[Any]: # _gather_87: with_item _loop0_88 mark = self._mark() - if ( - (elem := self.with_item()) - is not None - and - (seq := self._loop0_88()) - is not None - ): - return [elem] + seq; + if (elem := self.with_item()) is not None and ( + seq := self._loop0_88() + ) is not None: + return [elem] + seq self._reset(mark) - return None; + return None @memoize def _loop0_90(self) -> Optional[Any]: # _loop0_90: ',' with_item mark = self._mark() children = [] - while ( - (self.expect(',')) - and - (elem := self.with_item()) - ): + while (self.expect(",")) and (elem := self.with_item()): children.append(elem) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _gather_89(self) -> Optional[Any]: # _gather_89: with_item _loop0_90 mark = self._mark() - if ( - (elem := self.with_item()) - is not None - and - (seq := self._loop0_90()) - is not None - ): - return [elem] + seq; + if (elem := self.with_item()) is not None and ( + seq := self._loop0_90() + ) is not None: + return [elem] + seq self._reset(mark) - return None; + return None @memoize def _loop0_92(self) -> Optional[Any]: # _loop0_92: ',' with_item mark = self._mark() children = [] - while ( - (self.expect(',')) - and - (elem := self.with_item()) - ): + while (self.expect(",")) and (elem := self.with_item()): children.append(elem) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _gather_91(self) -> Optional[Any]: # _gather_91: with_item _loop0_92 mark = self._mark() - if ( - (elem := self.with_item()) - is not None - and - (seq := self._loop0_92()) - is not None - ): - return [elem] + seq; + if (elem := self.with_item()) is not None and ( + seq := self._loop0_92() + ) is not None: + return [elem] + seq self._reset(mark) - return None; + return None @memoize def _tmp_93(self) -> Optional[Any]: # _tmp_93: ',' | ')' | ':' mark = self._mark() - if ( - (literal := self.expect(',')) - ): - return literal; + if literal := self.expect(","): + return literal self._reset(mark) - if ( - (literal := self.expect(')')) - ): - return literal; + if literal := self.expect(")"): + return literal self._reset(mark) - if ( - (literal := self.expect(':')) - ): - return literal; + if literal := self.expect(":"): + return literal self._reset(mark) - return None; + return None @memoize def _loop1_94(self) -> Optional[Any]: # _loop1_94: except_block mark = self._mark() children = [] - while ( - (except_block := self.except_block()) - ): + while except_block := self.except_block(): children.append(except_block) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _loop1_95(self) -> Optional[Any]: # _loop1_95: except_star_block mark = self._mark() children = [] - while ( - (except_star_block := self.except_star_block()) - ): + while except_star_block := self.except_star_block(): children.append(except_star_block) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _tmp_96(self) -> Optional[Any]: # _tmp_96: 'as' NAME mark = self._mark() - if ( - (self.expect('as')) - and - (z := self.name()) - ): - return z . string; + if (self.expect("as")) and (z := self.name()): + return z.string self._reset(mark) - return None; + return None @memoize def _tmp_97(self) -> Optional[Any]: # _tmp_97: 'as' NAME mark = self._mark() - if ( - (self.expect('as')) - and - (z := self.name()) - ): - return z . string; + if (self.expect("as")) and (z := self.name()): + return z.string self._reset(mark) - return None; + return None @memoize def _loop1_98(self) -> Optional[Any]: # _loop1_98: case_block mark = self._mark() children = [] - while ( - (case_block := self.case_block()) - ): + while case_block := self.case_block(): children.append(case_block) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _loop0_100(self) -> Optional[Any]: # _loop0_100: '|' closed_pattern mark = self._mark() children = [] - while ( - (self.expect('|')) - and - (elem := self.closed_pattern()) - ): + while (self.expect("|")) and (elem := self.closed_pattern()): children.append(elem) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _gather_99(self) -> Optional[Any]: # _gather_99: closed_pattern _loop0_100 mark = self._mark() - if ( - (elem := self.closed_pattern()) - is not None - and - (seq := self._loop0_100()) - is not None - ): - return [elem] + seq; + if (elem := self.closed_pattern()) is not None and ( + seq := self._loop0_100() + ) is not None: + return [elem] + seq self._reset(mark) - return None; + return None @memoize def _tmp_101(self) -> Optional[Any]: # _tmp_101: '+' | '-' mark = self._mark() - if ( - (literal := self.expect('+')) - ): - return literal; + if literal := self.expect("+"): + return literal self._reset(mark) - if ( - (literal := self.expect('-')) - ): - return literal; + if literal := self.expect("-"): + return literal self._reset(mark) - return None; + return None @memoize def _tmp_102(self) -> Optional[Any]: # _tmp_102: '+' | '-' mark = self._mark() - if ( - (literal := self.expect('+')) - ): - return literal; + if literal := self.expect("+"): + return literal self._reset(mark) - if ( - (literal := self.expect('-')) - ): - return literal; + if literal := self.expect("-"): + return literal self._reset(mark) - return None; + return None @memoize def _tmp_103(self) -> Optional[Any]: # _tmp_103: '.' | '(' | '=' mark = self._mark() - if ( - (literal := self.expect('.')) - ): - return literal; + if literal := self.expect("."): + return literal self._reset(mark) - if ( - (literal := self.expect('(')) - ): - return literal; + if literal := self.expect("("): + return literal self._reset(mark) - if ( - (literal := self.expect('=')) - ): - return literal; + if literal := self.expect("="): + return literal self._reset(mark) - return None; + return None @memoize def _tmp_104(self) -> Optional[Any]: # _tmp_104: '.' | '(' | '=' mark = self._mark() - if ( - (literal := self.expect('.')) - ): - return literal; + if literal := self.expect("."): + return literal self._reset(mark) - if ( - (literal := self.expect('(')) - ): - return literal; + if literal := self.expect("("): + return literal self._reset(mark) - if ( - (literal := self.expect('=')) - ): - return literal; + if literal := self.expect("="): + return literal self._reset(mark) - return None; + return None @memoize def _loop0_106(self) -> Optional[Any]: # _loop0_106: ',' maybe_star_pattern mark = self._mark() children = [] - while ( - (self.expect(',')) - and - (elem := self.maybe_star_pattern()) - ): + while (self.expect(",")) and (elem := self.maybe_star_pattern()): children.append(elem) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _gather_105(self) -> Optional[Any]: # _gather_105: maybe_star_pattern _loop0_106 mark = self._mark() - if ( - (elem := self.maybe_star_pattern()) - is not None - and - (seq := self._loop0_106()) - is not None - ): - return [elem] + seq; + if (elem := self.maybe_star_pattern()) is not None and ( + seq := self._loop0_106() + ) is not None: + return [elem] + seq self._reset(mark) - return None; + return None @memoize def _loop0_108(self) -> Optional[Any]: # _loop0_108: ',' key_value_pattern mark = self._mark() children = [] - while ( - (self.expect(',')) - and - (elem := self.key_value_pattern()) - ): + while (self.expect(",")) and (elem := self.key_value_pattern()): children.append(elem) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _gather_107(self) -> Optional[Any]: # _gather_107: key_value_pattern _loop0_108 mark = self._mark() - if ( - (elem := self.key_value_pattern()) - is not None - and - (seq := self._loop0_108()) - is not None - ): - return [elem] + seq; + if (elem := self.key_value_pattern()) is not None and ( + seq := self._loop0_108() + ) is not None: + return [elem] + seq self._reset(mark) - return None; + return None @memoize def _tmp_109(self) -> Optional[Any]: # _tmp_109: literal_expr | attr mark = self._mark() - if ( - (literal_expr := self.literal_expr()) - ): - return literal_expr; + if literal_expr := self.literal_expr(): + return literal_expr self._reset(mark) - if ( - (attr := self.attr()) - ): - return attr; + if attr := self.attr(): + return attr self._reset(mark) - return None; + return None @memoize def _loop0_111(self) -> Optional[Any]: # _loop0_111: ',' pattern mark = self._mark() children = [] - while ( - (self.expect(',')) - and - (elem := self.pattern()) - ): + while (self.expect(",")) and (elem := self.pattern()): children.append(elem) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _gather_110(self) -> Optional[Any]: # _gather_110: pattern _loop0_111 mark = self._mark() - if ( - (elem := self.pattern()) - is not None - and - (seq := self._loop0_111()) - is not None - ): - return [elem] + seq; + if (elem := self.pattern()) is not None and ( + seq := self._loop0_111() + ) is not None: + return [elem] + seq self._reset(mark) - return None; + return None @memoize def _loop0_113(self) -> Optional[Any]: # _loop0_113: ',' keyword_pattern mark = self._mark() children = [] - while ( - (self.expect(',')) - and - (elem := self.keyword_pattern()) - ): + while (self.expect(",")) and (elem := self.keyword_pattern()): children.append(elem) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _gather_112(self) -> Optional[Any]: # _gather_112: keyword_pattern _loop0_113 mark = self._mark() - if ( - (elem := self.keyword_pattern()) - is not None - and - (seq := self._loop0_113()) - is not None - ): - return [elem] + seq; + if (elem := self.keyword_pattern()) is not None and ( + seq := self._loop0_113() + ) is not None: + return [elem] + seq self._reset(mark) - return None; + return None @memoize def _loop0_115(self) -> Optional[Any]: # _loop0_115: ',' type_param mark = self._mark() children = [] - while ( - (self.expect(',')) - and - (elem := self.type_param()) - ): + while (self.expect(",")) and (elem := self.type_param()): children.append(elem) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _gather_114(self) -> Optional[Any]: # _gather_114: type_param _loop0_115 mark = self._mark() - if ( - (elem := self.type_param()) - is not None - and - (seq := self._loop0_115()) - is not None - ): - return [elem] + seq; + if (elem := self.type_param()) is not None and ( + seq := self._loop0_115() + ) is not None: + return [elem] + seq self._reset(mark) - return None; + return None @memoize def _loop1_116(self) -> Optional[Any]: # _loop1_116: (',' expression) mark = self._mark() children = [] - while ( - (_tmp_290 := self._tmp_290()) - ): - children.append(_tmp_290) + while _tmp_314 := self._tmp_314(): + children.append(_tmp_314) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _loop1_117(self) -> Optional[Any]: # _loop1_117: (',' star_expression) mark = self._mark() children = [] - while ( - (_tmp_291 := self._tmp_291()) - ): - children.append(_tmp_291) + while _tmp_315 := self._tmp_315(): + children.append(_tmp_315) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _loop0_119(self) -> Optional[Any]: # _loop0_119: ',' star_named_expression mark = self._mark() children = [] - while ( - (self.expect(',')) - and - (elem := self.star_named_expression()) - ): + while (self.expect(",")) and (elem := self.star_named_expression()): children.append(elem) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _gather_118(self) -> Optional[Any]: # _gather_118: star_named_expression _loop0_119 mark = self._mark() - if ( - (elem := self.star_named_expression()) - is not None - and - (seq := self._loop0_119()) - is not None - ): - return [elem] + seq; + if (elem := self.star_named_expression()) is not None and ( + seq := self._loop0_119() + ) is not None: + return [elem] + seq self._reset(mark) - return None; + return None @memoize def _loop1_120(self) -> Optional[Any]: # _loop1_120: ('or' conjunction) mark = self._mark() children = [] - while ( - (_tmp_292 := self._tmp_292()) - ): - children.append(_tmp_292) + while _tmp_316 := self._tmp_316(): + children.append(_tmp_316) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _loop1_121(self) -> Optional[Any]: # _loop1_121: ('and' inversion) mark = self._mark() children = [] - while ( - (_tmp_293 := self._tmp_293()) - ): - children.append(_tmp_293) + while _tmp_317 := self._tmp_317(): + children.append(_tmp_317) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _loop1_122(self) -> Optional[Any]: # _loop1_122: compare_op_bitwise_or_pair mark = self._mark() children = [] - while ( - (compare_op_bitwise_or_pair := self.compare_op_bitwise_or_pair()) - ): + while compare_op_bitwise_or_pair := self.compare_op_bitwise_or_pair(): children.append(compare_op_bitwise_or_pair) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _loop0_124(self) -> Optional[Any]: # _loop0_124: ',' (slice | starred_expression) mark = self._mark() children = [] - while ( - (self.expect(',')) - and - (elem := self._tmp_294()) - ): + while (self.expect(",")) and (elem := self._tmp_318()): children.append(elem) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _gather_123(self) -> Optional[Any]: # _gather_123: (slice | starred_expression) _loop0_124 mark = self._mark() - if ( - (elem := self._tmp_294()) - is not None - and - (seq := self._loop0_124()) - is not None - ): - return [elem] + seq; + if (elem := self._tmp_318()) is not None and ( + seq := self._loop0_124() + ) is not None: + return [elem] + seq self._reset(mark) - return None; + return None @memoize def _tmp_125(self) -> Optional[Any]: # _tmp_125: ':' expression? mark = self._mark() - if ( - (self.expect(':')) - and - (d := self.expression(),) - ): - return d; + if (self.expect(":")) and (d := self.expression(),): + return d self._reset(mark) - return None; + return None @memoize def _tmp_126(self) -> Optional[Any]: - # _tmp_126: STRING | FSTRING_START + # _tmp_126: STRING | FSTRING_START | TSTRING_START mark = self._mark() - if ( - (string := self.string()) - ): - return string; + if string := self.string(): + return string self._reset(mark) - if ( - (fstring_start := self.fstring_start()) - ): - return fstring_start; + if fstring_start := self.fstring_start(): + return fstring_start + self._reset(mark) + if TSTRING_START := self.TSTRING_START(): + return TSTRING_START self._reset(mark) - return None; + return None @memoize def _tmp_127(self) -> Optional[Any]: # _tmp_127: tuple | group | genexp mark = self._mark() - if ( - (tuple := self.tuple()) - ): - return tuple; + if tuple := self.tuple(): + return tuple self._reset(mark) - if ( - (group := self.group()) - ): - return group; + if group := self.group(): + return group self._reset(mark) - if ( - (genexp := self.genexp()) - ): - return genexp; + if genexp := self.genexp(): + return genexp self._reset(mark) - return None; + return None @memoize def _tmp_128(self) -> Optional[Any]: # _tmp_128: list | listcomp mark = self._mark() - if ( - (list := self.list()) - ): - return list; + if list := self.list(): + return list self._reset(mark) - if ( - (listcomp := self.listcomp()) - ): - return listcomp; + if listcomp := self.listcomp(): + return listcomp self._reset(mark) - return None; + return None @memoize def _tmp_129(self) -> Optional[Any]: # _tmp_129: dict | set | dictcomp | setcomp mark = self._mark() - if ( - (dict := self.dict()) - ): - return dict; + if dict := self.dict(): + return dict self._reset(mark) - if ( - (set := self.set()) - ): - return set; + if set := self.set(): + return set self._reset(mark) - if ( - (dictcomp := self.dictcomp()) - ): - return dictcomp; + if dictcomp := self.dictcomp(): + return dictcomp self._reset(mark) - if ( - (setcomp := self.setcomp()) - ): - return setcomp; + if setcomp := self.setcomp(): + return setcomp self._reset(mark) - return None; + return None @memoize def _tmp_130(self) -> Optional[Any]: # _tmp_130: yield_expr | named_expression mark = self._mark() - if ( - (yield_expr := self.yield_expr()) - ): - return yield_expr; + if yield_expr := self.yield_expr(): + return yield_expr self._reset(mark) - if ( - (named_expression := self.named_expression()) - ): - return named_expression; + if named_expression := self.named_expression(): + return named_expression self._reset(mark) - return None; + return None @memoize def _loop0_131(self) -> Optional[Any]: # _loop0_131: lambda_param_no_default mark = self._mark() children = [] - while ( - (lambda_param_no_default := self.lambda_param_no_default()) - ): + while lambda_param_no_default := self.lambda_param_no_default(): children.append(lambda_param_no_default) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _loop0_132(self) -> Optional[Any]: # _loop0_132: lambda_param_with_default mark = self._mark() children = [] - while ( - (lambda_param_with_default := self.lambda_param_with_default()) - ): + while lambda_param_with_default := self.lambda_param_with_default(): children.append(lambda_param_with_default) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _loop0_133(self) -> Optional[Any]: # _loop0_133: lambda_param_with_default mark = self._mark() children = [] - while ( - (lambda_param_with_default := self.lambda_param_with_default()) - ): + while lambda_param_with_default := self.lambda_param_with_default(): children.append(lambda_param_with_default) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _loop1_134(self) -> Optional[Any]: # _loop1_134: lambda_param_no_default mark = self._mark() children = [] - while ( - (lambda_param_no_default := self.lambda_param_no_default()) - ): + while lambda_param_no_default := self.lambda_param_no_default(): children.append(lambda_param_no_default) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _loop0_135(self) -> Optional[Any]: # _loop0_135: lambda_param_with_default mark = self._mark() children = [] - while ( - (lambda_param_with_default := self.lambda_param_with_default()) - ): + while lambda_param_with_default := self.lambda_param_with_default(): children.append(lambda_param_with_default) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _loop1_136(self) -> Optional[Any]: # _loop1_136: lambda_param_with_default mark = self._mark() children = [] - while ( - (lambda_param_with_default := self.lambda_param_with_default()) - ): + while lambda_param_with_default := self.lambda_param_with_default(): children.append(lambda_param_with_default) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _loop1_137(self) -> Optional[Any]: # _loop1_137: lambda_param_no_default mark = self._mark() children = [] - while ( - (lambda_param_no_default := self.lambda_param_no_default()) - ): + while lambda_param_no_default := self.lambda_param_no_default(): children.append(lambda_param_no_default) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _loop1_138(self) -> Optional[Any]: # _loop1_138: lambda_param_no_default mark = self._mark() children = [] - while ( - (lambda_param_no_default := self.lambda_param_no_default()) - ): + while lambda_param_no_default := self.lambda_param_no_default(): children.append(lambda_param_no_default) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _loop0_139(self) -> Optional[Any]: # _loop0_139: lambda_param_no_default mark = self._mark() children = [] - while ( - (lambda_param_no_default := self.lambda_param_no_default()) - ): + while lambda_param_no_default := self.lambda_param_no_default(): children.append(lambda_param_no_default) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _loop1_140(self) -> Optional[Any]: # _loop1_140: lambda_param_with_default mark = self._mark() children = [] - while ( - (lambda_param_with_default := self.lambda_param_with_default()) - ): + while lambda_param_with_default := self.lambda_param_with_default(): children.append(lambda_param_with_default) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _loop0_141(self) -> Optional[Any]: # _loop0_141: lambda_param_no_default mark = self._mark() children = [] - while ( - (lambda_param_no_default := self.lambda_param_no_default()) - ): + while lambda_param_no_default := self.lambda_param_no_default(): children.append(lambda_param_no_default) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _loop1_142(self) -> Optional[Any]: # _loop1_142: lambda_param_with_default mark = self._mark() children = [] - while ( - (lambda_param_with_default := self.lambda_param_with_default()) - ): + while lambda_param_with_default := self.lambda_param_with_default(): children.append(lambda_param_with_default) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _loop0_143(self) -> Optional[Any]: # _loop0_143: lambda_param_maybe_default mark = self._mark() children = [] - while ( - (lambda_param_maybe_default := self.lambda_param_maybe_default()) - ): + while lambda_param_maybe_default := self.lambda_param_maybe_default(): children.append(lambda_param_maybe_default) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _loop1_144(self) -> Optional[Any]: # _loop1_144: lambda_param_maybe_default mark = self._mark() children = [] - while ( - (lambda_param_maybe_default := self.lambda_param_maybe_default()) - ): + while lambda_param_maybe_default := self.lambda_param_maybe_default(): children.append(lambda_param_maybe_default) mark = self._mark() self._reset(mark) - return children; + return children @memoize - def _tmp_145(self) -> Optional[Any]: - # _tmp_145: yield_expr | star_expressions + def _loop0_145(self) -> Optional[Any]: + # _loop0_145: fstring_format_spec mark = self._mark() - if ( - (yield_expr := self.yield_expr()) - ): - return yield_expr; - self._reset(mark) - if ( - (star_expressions := self.star_expressions()) - ): - return star_expressions; + children = [] + while fstring_format_spec := self.fstring_format_spec(): + children.append(fstring_format_spec) + mark = self._mark() self._reset(mark) - return None; + return children @memoize def _loop0_146(self) -> Optional[Any]: - # _loop0_146: fstring_format_spec + # _loop0_146: fstring_mid mark = self._mark() children = [] - while ( - (fstring_format_spec := self.fstring_format_spec()) - ): - children.append(fstring_format_spec) + while fstring_mid := self.fstring_mid(): + children.append(fstring_mid) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _loop0_147(self) -> Optional[Any]: - # _loop0_147: fstring_mid + # _loop0_147: tstring_format_spec mark = self._mark() children = [] - while ( - (fstring_mid := self.fstring_mid()) - ): - children.append(fstring_mid) + while tstring_format_spec := self.tstring_format_spec(): + children.append(tstring_format_spec) mark = self._mark() self._reset(mark) - return children; + return children @memoize - def _loop1_148(self) -> Optional[Any]: - # _loop1_148: (fstring | STRING) + def _loop0_148(self) -> Optional[Any]: + # _loop0_148: tstring_mid mark = self._mark() children = [] - while ( - (_tmp_295 := self._tmp_295()) - ): - children.append(_tmp_295) + while tstring_mid := self.tstring_mid(): + children.append(tstring_mid) mark = self._mark() self._reset(mark) - return children; + return children @memoize - def _tmp_149(self) -> Optional[Any]: - # _tmp_149: star_named_expression ',' star_named_expressions? + def _loop1_149(self) -> Optional[Any]: + # _loop1_149: (fstring | STRING) mark = self._mark() - if ( - (y := self.star_named_expression()) - and - (self.expect(',')) - and - (z := self.star_named_expressions(),) - ): - return [y] + ( z or [] ); + children = [] + while _tmp_319 := self._tmp_319(): + children.append(_tmp_319) + mark = self._mark() self._reset(mark) - return None; + return children @memoize - def _loop0_151(self) -> Optional[Any]: - # _loop0_151: ',' double_starred_kvpair + def _loop1_150(self) -> Optional[Any]: + # _loop1_150: tstring mark = self._mark() children = [] - while ( - (self.expect(',')) - and - (elem := self.double_starred_kvpair()) - ): - children.append(elem) + while tstring := self.tstring(): + children.append(tstring) mark = self._mark() self._reset(mark) - return children; + return children @memoize - def _gather_150(self) -> Optional[Any]: - # _gather_150: double_starred_kvpair _loop0_151 + def _tmp_151(self) -> Optional[Any]: + # _tmp_151: star_named_expression ',' star_named_expressions? mark = self._mark() if ( - (elem := self.double_starred_kvpair()) - is not None - and - (seq := self._loop0_151()) - is not None + (y := self.star_named_expression()) + and (self.expect(",")) + and (z := self.star_named_expressions(),) ): - return [elem] + seq; + return [y] + (z or []) self._reset(mark) - return None; + return None @memoize - def _loop1_152(self) -> Optional[Any]: - # _loop1_152: for_if_clause + def _loop0_153(self) -> Optional[Any]: + # _loop0_153: ',' double_starred_kvpair mark = self._mark() children = [] - while ( - (for_if_clause := self.for_if_clause()) - ): - children.append(for_if_clause) + while (self.expect(",")) and (elem := self.double_starred_kvpair()): + children.append(elem) mark = self._mark() self._reset(mark) - return children; + return children @memoize - def _loop0_153(self) -> Optional[Any]: - # _loop0_153: ('if' disjunction) + def _gather_152(self) -> Optional[Any]: + # _gather_152: double_starred_kvpair _loop0_153 mark = self._mark() - children = [] - while ( - (_tmp_296 := self._tmp_296()) - ): - children.append(_tmp_296) - mark = self._mark() + if (elem := self.double_starred_kvpair()) is not None and ( + seq := self._loop0_153() + ) is not None: + return [elem] + seq self._reset(mark) - return children; + return None @memoize - def _loop0_154(self) -> Optional[Any]: - # _loop0_154: ('if' disjunction) + def _loop1_154(self) -> Optional[Any]: + # _loop1_154: for_if_clause mark = self._mark() children = [] - while ( - (_tmp_297 := self._tmp_297()) - ): - children.append(_tmp_297) + while for_if_clause := self.for_if_clause(): + children.append(for_if_clause) mark = self._mark() self._reset(mark) - return children; + return children @memoize - def _tmp_155(self) -> Optional[Any]: - # _tmp_155: assignment_expression | expression !':=' + def _loop0_155(self) -> Optional[Any]: + # _loop0_155: ('if' disjunction) mark = self._mark() - if ( - (assignment_expression := self.assignment_expression()) - ): - return assignment_expression; - self._reset(mark) - if ( - (expression := self.expression()) - and - (self.negative_lookahead(self.expect, ':=')) - ): - return expression; + children = [] + while _tmp_320 := self._tmp_320(): + children.append(_tmp_320) + mark = self._mark() self._reset(mark) - return None; + return children @memoize - def _loop0_157(self) -> Optional[Any]: - # _loop0_157: ',' (starred_expression | (assignment_expression | expression !':=') !'=') + def _loop0_156(self) -> Optional[Any]: + # _loop0_156: ('if' disjunction) mark = self._mark() children = [] - while ( - (self.expect(',')) - and - (elem := self._tmp_298()) - ): - children.append(elem) + while _tmp_321 := self._tmp_321(): + children.append(_tmp_321) mark = self._mark() self._reset(mark) - return children; + return children @memoize - def _gather_156(self) -> Optional[Any]: - # _gather_156: (starred_expression | (assignment_expression | expression !':=') !'=') _loop0_157 + def _tmp_157(self) -> Optional[Any]: + # _tmp_157: assignment_expression | expression !':=' mark = self._mark() - if ( - (elem := self._tmp_298()) - is not None - and - (seq := self._loop0_157()) - is not None - ): - return [elem] + seq; + if assignment_expression := self.assignment_expression(): + return assignment_expression self._reset(mark) - return None; - - @memoize - def _tmp_158(self) -> Optional[Any]: - # _tmp_158: ',' kwargs - mark = self._mark() - if ( - (self.expect(',')) - and - (k := self.kwargs()) + if (expression := self.expression()) and ( + self.negative_lookahead(self.expect, ":=") ): - return k; + return expression self._reset(mark) - return None; + return None @memoize - def _loop0_160(self) -> Optional[Any]: - # _loop0_160: ',' kwarg_or_starred + def _loop0_159(self) -> Optional[Any]: + # _loop0_159: ',' (starred_expression | (assignment_expression | expression !':=') !'=') mark = self._mark() children = [] - while ( - (self.expect(',')) - and - (elem := self.kwarg_or_starred()) - ): + while (self.expect(",")) and (elem := self._tmp_322()): children.append(elem) mark = self._mark() self._reset(mark) - return children; + return children @memoize - def _gather_159(self) -> Optional[Any]: - # _gather_159: kwarg_or_starred _loop0_160 + def _gather_158(self) -> Optional[Any]: + # _gather_158: (starred_expression | (assignment_expression | expression !':=') !'=') _loop0_159 mark = self._mark() - if ( - (elem := self.kwarg_or_starred()) - is not None - and - (seq := self._loop0_160()) - is not None - ): - return [elem] + seq; + if (elem := self._tmp_322()) is not None and ( + seq := self._loop0_159() + ) is not None: + return [elem] + seq + self._reset(mark) + return None + + @memoize + def _tmp_160(self) -> Optional[Any]: + # _tmp_160: ',' kwargs + mark = self._mark() + if (self.expect(",")) and (k := self.kwargs()): + return k self._reset(mark) - return None; + return None @memoize def _loop0_162(self) -> Optional[Any]: - # _loop0_162: ',' kwarg_or_double_starred + # _loop0_162: ',' kwarg_or_starred mark = self._mark() children = [] - while ( - (self.expect(',')) - and - (elem := self.kwarg_or_double_starred()) - ): + while (self.expect(",")) and (elem := self.kwarg_or_starred()): children.append(elem) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _gather_161(self) -> Optional[Any]: - # _gather_161: kwarg_or_double_starred _loop0_162 + # _gather_161: kwarg_or_starred _loop0_162 mark = self._mark() - if ( - (elem := self.kwarg_or_double_starred()) - is not None - and - (seq := self._loop0_162()) - is not None - ): - return [elem] + seq; + if (elem := self.kwarg_or_starred()) is not None and ( + seq := self._loop0_162() + ) is not None: + return [elem] + seq self._reset(mark) - return None; + return None @memoize def _loop0_164(self) -> Optional[Any]: - # _loop0_164: ',' kwarg_or_starred + # _loop0_164: ',' kwarg_or_double_starred mark = self._mark() children = [] - while ( - (self.expect(',')) - and - (elem := self.kwarg_or_starred()) - ): + while (self.expect(",")) and (elem := self.kwarg_or_double_starred()): children.append(elem) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _gather_163(self) -> Optional[Any]: - # _gather_163: kwarg_or_starred _loop0_164 + # _gather_163: kwarg_or_double_starred _loop0_164 mark = self._mark() - if ( - (elem := self.kwarg_or_starred()) - is not None - and - (seq := self._loop0_164()) - is not None - ): - return [elem] + seq; + if (elem := self.kwarg_or_double_starred()) is not None and ( + seq := self._loop0_164() + ) is not None: + return [elem] + seq self._reset(mark) - return None; + return None @memoize def _loop0_166(self) -> Optional[Any]: - # _loop0_166: ',' kwarg_or_double_starred + # _loop0_166: ',' kwarg_or_starred mark = self._mark() children = [] - while ( - (self.expect(',')) - and - (elem := self.kwarg_or_double_starred()) - ): + while (self.expect(",")) and (elem := self.kwarg_or_starred()): children.append(elem) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _gather_165(self) -> Optional[Any]: - # _gather_165: kwarg_or_double_starred _loop0_166 + # _gather_165: kwarg_or_starred _loop0_166 mark = self._mark() - if ( - (elem := self.kwarg_or_double_starred()) - is not None - and - (seq := self._loop0_166()) - is not None - ): - return [elem] + seq; + if (elem := self.kwarg_or_starred()) is not None and ( + seq := self._loop0_166() + ) is not None: + return [elem] + seq self._reset(mark) - return None; + return None @memoize - def _loop0_167(self) -> Optional[Any]: - # _loop0_167: (',' star_target) + def _loop0_168(self) -> Optional[Any]: + # _loop0_168: ',' kwarg_or_double_starred mark = self._mark() children = [] - while ( - (_tmp_299 := self._tmp_299()) - ): - children.append(_tmp_299) + while (self.expect(",")) and (elem := self.kwarg_or_double_starred()): + children.append(elem) mark = self._mark() self._reset(mark) - return children; + return children @memoize - def _loop0_169(self) -> Optional[Any]: - # _loop0_169: ',' star_target + def _gather_167(self) -> Optional[Any]: + # _gather_167: kwarg_or_double_starred _loop0_168 mark = self._mark() - children = [] - while ( - (self.expect(',')) - and - (elem := self.star_target()) - ): - children.append(elem) - mark = self._mark() + if (elem := self.kwarg_or_double_starred()) is not None and ( + seq := self._loop0_168() + ) is not None: + return [elem] + seq self._reset(mark) - return children; + return None @memoize - def _gather_168(self) -> Optional[Any]: - # _gather_168: star_target _loop0_169 + def _loop0_169(self) -> Optional[Any]: + # _loop0_169: (',' star_target) mark = self._mark() - if ( - (elem := self.star_target()) - is not None - and - (seq := self._loop0_169()) - is not None - ): - return [elem] + seq; + children = [] + while _tmp_323 := self._tmp_323(): + children.append(_tmp_323) + mark = self._mark() self._reset(mark) - return None; + return children @memoize - def _loop1_170(self) -> Optional[Any]: - # _loop1_170: (',' star_target) + def _loop0_171(self) -> Optional[Any]: + # _loop0_171: ',' star_target mark = self._mark() children = [] - while ( - (_tmp_300 := self._tmp_300()) - ): - children.append(_tmp_300) + while (self.expect(",")) and (elem := self.star_target()): + children.append(elem) mark = self._mark() self._reset(mark) - return children; + return children @memoize - def _tmp_171(self) -> Optional[Any]: - # _tmp_171: !'*' star_target + def _gather_170(self) -> Optional[Any]: + # _gather_170: star_target _loop0_171 mark = self._mark() - if ( - (self.negative_lookahead(self.expect, '*')) - and - (star_target := self.star_target()) - ): - return star_target; + if (elem := self.star_target()) is not None and ( + seq := self._loop0_171() + ) is not None: + return [elem] + seq self._reset(mark) - return None; + return None @memoize - def _loop0_173(self) -> Optional[Any]: - # _loop0_173: ',' del_target + def _loop1_172(self) -> Optional[Any]: + # _loop1_172: (',' star_target) mark = self._mark() children = [] - while ( - (self.expect(',')) - and - (elem := self.del_target()) - ): - children.append(elem) + while _tmp_324 := self._tmp_324(): + children.append(_tmp_324) mark = self._mark() self._reset(mark) - return children; + return children @memoize - def _gather_172(self) -> Optional[Any]: - # _gather_172: del_target _loop0_173 + def _tmp_173(self) -> Optional[Any]: + # _tmp_173: !'*' star_target mark = self._mark() - if ( - (elem := self.del_target()) - is not None - and - (seq := self._loop0_173()) - is not None + if (self.negative_lookahead(self.expect, "*")) and ( + star_target := self.star_target() ): - return [elem] + seq; + return star_target self._reset(mark) - return None; + return None @memoize def _loop0_175(self) -> Optional[Any]: - # _loop0_175: ',' expression + # _loop0_175: ',' del_target mark = self._mark() children = [] - while ( - (self.expect(',')) - and - (elem := self.expression()) - ): + while (self.expect(",")) and (elem := self.del_target()): children.append(elem) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _gather_174(self) -> Optional[Any]: - # _gather_174: expression _loop0_175 + # _gather_174: del_target _loop0_175 mark = self._mark() - if ( - (elem := self.expression()) - is not None - and - (seq := self._loop0_175()) - is not None - ): - return [elem] + seq; + if (elem := self.del_target()) is not None and ( + seq := self._loop0_175() + ) is not None: + return [elem] + seq self._reset(mark) - return None; + return None @memoize def _loop0_177(self) -> Optional[Any]: # _loop0_177: ',' expression mark = self._mark() children = [] - while ( - (self.expect(',')) - and - (elem := self.expression()) - ): + while (self.expect(",")) and (elem := self.expression()): children.append(elem) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _gather_176(self) -> Optional[Any]: # _gather_176: expression _loop0_177 mark = self._mark() - if ( - (elem := self.expression()) - is not None - and - (seq := self._loop0_177()) - is not None - ): - return [elem] + seq; + if (elem := self.expression()) is not None and ( + seq := self._loop0_177() + ) is not None: + return [elem] + seq self._reset(mark) - return None; + return None @memoize def _loop0_179(self) -> Optional[Any]: # _loop0_179: ',' expression mark = self._mark() children = [] - while ( - (self.expect(',')) - and - (elem := self.expression()) - ): + while (self.expect(",")) and (elem := self.expression()): children.append(elem) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _gather_178(self) -> Optional[Any]: # _gather_178: expression _loop0_179 mark = self._mark() - if ( - (elem := self.expression()) - is not None - and - (seq := self._loop0_179()) - is not None - ): - return [elem] + seq; + if (elem := self.expression()) is not None and ( + seq := self._loop0_179() + ) is not None: + return [elem] + seq self._reset(mark) - return None; + return None @memoize def _loop0_181(self) -> Optional[Any]: # _loop0_181: ',' expression mark = self._mark() children = [] - while ( - (self.expect(',')) - and - (elem := self.expression()) - ): + while (self.expect(",")) and (elem := self.expression()): children.append(elem) mark = self._mark() self._reset(mark) - return children; + return children @memoize def _gather_180(self) -> Optional[Any]: # _gather_180: expression _loop0_181 mark = self._mark() - if ( - (elem := self.expression()) - is not None - and - (seq := self._loop0_181()) - is not None - ): - return [elem] + seq; + if (elem := self.expression()) is not None and ( + seq := self._loop0_181() + ) is not None: + return [elem] + seq self._reset(mark) - return None; + return None @memoize - def _tmp_182(self) -> Optional[Any]: - # _tmp_182: NEWLINE INDENT + def _loop0_183(self) -> Optional[Any]: + # _loop0_183: ',' expression mark = self._mark() - if ( - (_newline := self.expect('NEWLINE')) - and - (_indent := self.expect('INDENT')) - ): - return [_newline, _indent]; + children = [] + while (self.expect(",")) and (elem := self.expression()): + children.append(elem) + mark = self._mark() self._reset(mark) - return None; + return children @memoize - def _tmp_183(self) -> Optional[Any]: - # _tmp_183: args | expression for_if_clauses + def _gather_182(self) -> Optional[Any]: + # _gather_182: expression _loop0_183 mark = self._mark() - if ( - (args := self.args()) - ): - return args; - self._reset(mark) - if ( - (expression := self.expression()) - and - (for_if_clauses := self.for_if_clauses()) - ): - return [expression, for_if_clauses]; + if (elem := self.expression()) is not None and ( + seq := self._loop0_183() + ) is not None: + return [elem] + seq self._reset(mark) - return None; + return None @memoize def _tmp_184(self) -> Optional[Any]: - # _tmp_184: args ',' + # _tmp_184: NEWLINE INDENT mark = self._mark() - if ( - (args := self.args()) - and - (literal := self.expect(',')) - ): - return [args, literal]; + if (_newline := self.expect("NEWLINE")) and (_indent := self.expect("INDENT")): + return [_newline, _indent] self._reset(mark) - return None; + return None @memoize def _tmp_185(self) -> Optional[Any]: - # _tmp_185: ',' | ')' + # _tmp_185: (','.(starred_expression | (assignment_expression | expression !':=') !'=')+ ',' kwargs) | kwargs mark = self._mark() - if ( - (literal := self.expect(',')) - ): - return literal; + if _tmp_325 := self._tmp_325(): + return _tmp_325 self._reset(mark) - if ( - (literal := self.expect(')')) - ): - return literal; + if kwargs := self.kwargs(): + return kwargs self._reset(mark) - return None; + return None @memoize - def _tmp_186(self) -> Optional[Any]: - # _tmp_186: 'True' | 'False' | 'None' + def _loop0_187(self) -> Optional[Any]: + # _loop0_187: ',' (starred_expression !'=') mark = self._mark() - if ( - (literal := self.expect('True')) - ): - return literal; - self._reset(mark) - if ( - (literal := self.expect('False')) - ): - return literal; - self._reset(mark) - if ( - (literal := self.expect('None')) - ): - return literal; + children = [] + while (self.expect(",")) and (elem := self._tmp_326()): + children.append(elem) + mark = self._mark() self._reset(mark) - return None; + return children @memoize - def _tmp_187(self) -> Optional[Any]: - # _tmp_187: NAME '=' + def _gather_186(self) -> Optional[Any]: + # _gather_186: (starred_expression !'=') _loop0_187 mark = self._mark() - if ( - (name := self.name()) - and - (literal := self.expect('=')) - ): - return [name, literal]; + if (elem := self._tmp_326()) is not None and ( + seq := self._loop0_187() + ) is not None: + return [elem] + seq self._reset(mark) - return None; + return None @memoize def _tmp_188(self) -> Optional[Any]: - # _tmp_188: NAME STRING | SOFT_KEYWORD + # _tmp_188: args | expression for_if_clauses mark = self._mark() - if ( - (name := self.name()) - and - (string := self.string()) - ): - return [name, string]; + if args := self.args(): + return args self._reset(mark) - if ( - (soft_keyword := self.soft_keyword()) + if (expression := self.expression()) and ( + for_if_clauses := self.for_if_clauses() ): - return soft_keyword; + return [expression, for_if_clauses] self._reset(mark) - return None; + return None @memoize def _tmp_189(self) -> Optional[Any]: - # _tmp_189: 'else' | ':' + # _tmp_189: args ',' mark = self._mark() - if ( - (literal := self.expect('else')) - ): - return literal; - self._reset(mark) - if ( - (literal := self.expect(':')) - ): - return literal; + if (args := self.args()) and (literal := self.expect(",")): + return [args, literal] self._reset(mark) - return None; + return None @memoize def _tmp_190(self) -> Optional[Any]: - # _tmp_190: FSTRING_MIDDLE | fstring_replacement_field + # _tmp_190: ',' | ')' mark = self._mark() - if ( - (fstring_middle := self.fstring_middle()) - ): - return fstring_middle; + if literal := self.expect(","): + return literal self._reset(mark) - if ( - (fstring_replacement_field := self.fstring_replacement_field()) - ): - return fstring_replacement_field; + if literal := self.expect(")"): + return literal self._reset(mark) - return None; + return None @memoize def _tmp_191(self) -> Optional[Any]: - # _tmp_191: '=' | ':=' + # _tmp_191: 'True' | 'False' | 'None' mark = self._mark() - if ( - (literal := self.expect('=')) - ): - return literal; + if literal := self.expect("True"): + return literal self._reset(mark) - if ( - (literal := self.expect(':=')) - ): - return literal; + if literal := self.expect("False"): + return literal + self._reset(mark) + if literal := self.expect("None"): + return literal self._reset(mark) - return None; + return None @memoize def _tmp_192(self) -> Optional[Any]: - # _tmp_192: list | tuple | genexp | 'True' | 'None' | 'False' + # _tmp_192: NAME '=' mark = self._mark() - if ( - (list := self.list()) - ): - return list; + if (name := self.name()) and (literal := self.expect("=")): + return [name, literal] self._reset(mark) - if ( - (tuple := self.tuple()) - ): - return tuple; - self._reset(mark) - if ( - (genexp := self.genexp()) - ): - return genexp; - self._reset(mark) - if ( - (literal := self.expect('True')) - ): - return literal; - self._reset(mark) - if ( - (literal := self.expect('None')) - ): - return literal; - self._reset(mark) - if ( - (literal := self.expect('False')) - ): - return literal; - self._reset(mark) - return None; + return None @memoize def _tmp_193(self) -> Optional[Any]: - # _tmp_193: '=' | ':=' + # _tmp_193: NAME STRING | SOFT_KEYWORD mark = self._mark() - if ( - (literal := self.expect('=')) - ): - return literal; + if (name := self.name()) and (string := self.string()): + return [name, string] self._reset(mark) - if ( - (literal := self.expect(':=')) - ): - return literal; + if soft_keyword := self.soft_keyword(): + return soft_keyword self._reset(mark) - return None; + return None @memoize - def _loop0_194(self) -> Optional[Any]: - # _loop0_194: star_named_expressions + def _tmp_194(self) -> Optional[Any]: + # _tmp_194: 'else' | ':' mark = self._mark() - children = [] - while ( - (star_named_expressions := self.star_named_expressions()) - ): - children.append(star_named_expressions) - mark = self._mark() + if literal := self.expect("else"): + return literal + self._reset(mark) + if literal := self.expect(":"): + return literal self._reset(mark) - return children; + return None @memoize - def _loop0_195(self) -> Optional[Any]: - # _loop0_195: (star_targets '=') + def _tmp_195(self) -> Optional[Any]: + # _tmp_195: FSTRING_MIDDLE | fstring_replacement_field mark = self._mark() - children = [] - while ( - (_tmp_301 := self._tmp_301()) - ): - children.append(_tmp_301) - mark = self._mark() + if fstring_middle := self.fstring_middle(): + return fstring_middle + self._reset(mark) + if fstring_replacement_field := self.fstring_replacement_field(): + return fstring_replacement_field self._reset(mark) - return children; + return None @memoize - def _loop0_196(self) -> Optional[Any]: - # _loop0_196: (star_targets '=') + def _tmp_196(self) -> Optional[Any]: + # _tmp_196: '=' | ':=' mark = self._mark() - children = [] - while ( - (_tmp_302 := self._tmp_302()) - ): - children.append(_tmp_302) - mark = self._mark() + if literal := self.expect("="): + return literal + self._reset(mark) + if literal := self.expect(":="): + return literal self._reset(mark) - return children; + return None @memoize def _tmp_197(self) -> Optional[Any]: - # _tmp_197: yield_expr | star_expressions + # _tmp_197: list | tuple | genexp | 'True' | 'None' | 'False' mark = self._mark() - if ( - (yield_expr := self.yield_expr()) - ): - return yield_expr; + if list := self.list(): + return list self._reset(mark) - if ( - (star_expressions := self.star_expressions()) - ): - return star_expressions; + if tuple := self.tuple(): + return tuple + self._reset(mark) + if genexp := self.genexp(): + return genexp + self._reset(mark) + if literal := self.expect("True"): + return literal + self._reset(mark) + if literal := self.expect("None"): + return literal + self._reset(mark) + if literal := self.expect("False"): + return literal self._reset(mark) - return None; + return None @memoize def _tmp_198(self) -> Optional[Any]: - # _tmp_198: '[' | '(' | '{' + # _tmp_198: '=' | ':=' mark = self._mark() - if ( - (literal := self.expect('[')) - ): - return literal; - self._reset(mark) - if ( - (literal := self.expect('(')) - ): - return literal; + if literal := self.expect("="): + return literal self._reset(mark) - if ( - (literal := self.expect('{')) - ): - return literal; + if literal := self.expect(":="): + return literal self._reset(mark) - return None; + return None @memoize - def _tmp_199(self) -> Optional[Any]: - # _tmp_199: '[' | '{' + def _loop0_199(self) -> Optional[Any]: + # _loop0_199: star_named_expressions mark = self._mark() - if ( - (literal := self.expect('[')) - ): - return literal; + children = [] + while star_named_expressions := self.star_named_expressions(): + children.append(star_named_expressions) + mark = self._mark() self._reset(mark) - if ( - (literal := self.expect('{')) - ): - return literal; + return children + + @memoize + def _loop0_200(self) -> Optional[Any]: + # _loop0_200: (star_targets '=') + mark = self._mark() + children = [] + while _tmp_327 := self._tmp_327(): + children.append(_tmp_327) + mark = self._mark() self._reset(mark) - return None; + return children @memoize - def _tmp_200(self) -> Optional[Any]: - # _tmp_200: '[' | '{' + def _loop0_201(self) -> Optional[Any]: + # _loop0_201: (star_targets '=') mark = self._mark() - if ( - (literal := self.expect('[')) - ): - return literal; + children = [] + while _tmp_328 := self._tmp_328(): + children.append(_tmp_328) + mark = self._mark() self._reset(mark) - if ( - (literal := self.expect('{')) - ): - return literal; + return children + + @memoize + def _tmp_202(self) -> Optional[Any]: + # _tmp_202: yield_expr | star_expressions + mark = self._mark() + if yield_expr := self.yield_expr(): + return yield_expr self._reset(mark) - return None; + if star_expressions := self.star_expressions(): + return star_expressions + self._reset(mark) + return None @memoize - def _tmp_201(self) -> Optional[Any]: - # _tmp_201: slash_no_default | slash_with_default + def _tmp_203(self) -> Optional[Any]: + # _tmp_203: '[' | '(' | '{' mark = self._mark() - if ( - (slash_no_default := self.slash_no_default()) - ): - return slash_no_default; + if literal := self.expect("["): + return literal self._reset(mark) - if ( - (slash_with_default := self.slash_with_default()) - ): - return slash_with_default; + if literal := self.expect("("): + return literal + self._reset(mark) + if literal := self.expect("{"): + return literal + self._reset(mark) + return None + + @memoize + def _tmp_204(self) -> Optional[Any]: + # _tmp_204: '[' | '{' + mark = self._mark() + if literal := self.expect("["): + return literal + self._reset(mark) + if literal := self.expect("{"): + return literal + self._reset(mark) + return None + + @memoize + def _tmp_205(self) -> Optional[Any]: + # _tmp_205: '[' | '{' + mark = self._mark() + if literal := self.expect("["): + return literal + self._reset(mark) + if literal := self.expect("{"): + return literal + self._reset(mark) + return None + + @memoize + def _tmp_206(self) -> Optional[Any]: + # _tmp_206: slash_no_default | slash_with_default + mark = self._mark() + if slash_no_default := self.slash_no_default(): + return slash_no_default self._reset(mark) - return None; + if slash_with_default := self.slash_with_default(): + return slash_with_default + self._reset(mark) + return None @memoize - def _loop0_202(self) -> Optional[Any]: - # _loop0_202: param_maybe_default + def _loop0_207(self) -> Optional[Any]: + # _loop0_207: param_maybe_default mark = self._mark() children = [] - while ( - (param_maybe_default := self.param_maybe_default()) - ): + while param_maybe_default := self.param_maybe_default(): children.append(param_maybe_default) mark = self._mark() self._reset(mark) - return children; + return children @memoize - def _loop0_203(self) -> Optional[Any]: - # _loop0_203: param_no_default + def _loop0_208(self) -> Optional[Any]: + # _loop0_208: param_no_default mark = self._mark() children = [] - while ( - (param_no_default := self.param_no_default()) - ): + while param_no_default := self.param_no_default(): children.append(param_no_default) mark = self._mark() self._reset(mark) - return children; + return children @memoize - def _loop0_204(self) -> Optional[Any]: - # _loop0_204: param_no_default + def _loop0_209(self) -> Optional[Any]: + # _loop0_209: param_no_default mark = self._mark() children = [] - while ( - (param_no_default := self.param_no_default()) - ): + while param_no_default := self.param_no_default(): children.append(param_no_default) mark = self._mark() self._reset(mark) - return children; + return children @memoize - def _loop1_205(self) -> Optional[Any]: - # _loop1_205: param_no_default + def _loop1_210(self) -> Optional[Any]: + # _loop1_210: param_no_default mark = self._mark() children = [] - while ( - (param_no_default := self.param_no_default()) - ): + while param_no_default := self.param_no_default(): children.append(param_no_default) mark = self._mark() self._reset(mark) - return children; + return children @memoize - def _tmp_206(self) -> Optional[Any]: - # _tmp_206: slash_no_default | slash_with_default + def _tmp_211(self) -> Optional[Any]: + # _tmp_211: slash_no_default | slash_with_default mark = self._mark() - if ( - (slash_no_default := self.slash_no_default()) - ): - return slash_no_default; + if slash_no_default := self.slash_no_default(): + return slash_no_default self._reset(mark) - if ( - (slash_with_default := self.slash_with_default()) - ): - return slash_with_default; + if slash_with_default := self.slash_with_default(): + return slash_with_default self._reset(mark) - return None; + return None @memoize - def _loop0_207(self) -> Optional[Any]: - # _loop0_207: param_maybe_default + def _loop0_212(self) -> Optional[Any]: + # _loop0_212: param_maybe_default mark = self._mark() children = [] - while ( - (param_maybe_default := self.param_maybe_default()) - ): + while param_maybe_default := self.param_maybe_default(): children.append(param_maybe_default) mark = self._mark() self._reset(mark) - return children; + return children @memoize - def _tmp_208(self) -> Optional[Any]: - # _tmp_208: ',' | param_no_default + def _tmp_213(self) -> Optional[Any]: + # _tmp_213: ',' | param_no_default mark = self._mark() - if ( - (literal := self.expect(',')) - ): - return literal; + if literal := self.expect(","): + return literal self._reset(mark) - if ( - (param_no_default := self.param_no_default()) - ): - return param_no_default; + if param_no_default := self.param_no_default(): + return param_no_default self._reset(mark) - return None; + return None @memoize - def _loop0_209(self) -> Optional[Any]: - # _loop0_209: param_maybe_default + def _loop0_214(self) -> Optional[Any]: + # _loop0_214: param_maybe_default mark = self._mark() children = [] - while ( - (param_maybe_default := self.param_maybe_default()) - ): + while param_maybe_default := self.param_maybe_default(): children.append(param_maybe_default) mark = self._mark() self._reset(mark) - return children; + return children @memoize - def _loop1_210(self) -> Optional[Any]: - # _loop1_210: param_maybe_default + def _loop1_215(self) -> Optional[Any]: + # _loop1_215: param_maybe_default mark = self._mark() children = [] - while ( - (param_maybe_default := self.param_maybe_default()) - ): + while param_maybe_default := self.param_maybe_default(): children.append(param_maybe_default) mark = self._mark() self._reset(mark) - return children; + return children @memoize - def _tmp_211(self) -> Optional[Any]: - # _tmp_211: ')' | ',' + def _tmp_216(self) -> Optional[Any]: + # _tmp_216: ')' | ',' mark = self._mark() - if ( - (literal := self.expect(')')) - ): - return literal; + if literal := self.expect(")"): + return literal self._reset(mark) - if ( - (literal := self.expect(',')) - ): - return literal; + if literal := self.expect(","): + return literal self._reset(mark) - return None; + return None @memoize - def _tmp_212(self) -> Optional[Any]: - # _tmp_212: ')' | ',' (')' | '**') + def _tmp_217(self) -> Optional[Any]: + # _tmp_217: ')' | ',' (')' | '**') mark = self._mark() - if ( - (literal := self.expect(')')) - ): - return literal; + if literal := self.expect(")"): + return literal self._reset(mark) - if ( - (literal := self.expect(',')) - and - (_tmp_303 := self._tmp_303()) - ): - return [literal, _tmp_303]; + if (literal := self.expect(",")) and (_tmp_329 := self._tmp_329()): + return [literal, _tmp_329] self._reset(mark) - return None; + return None @memoize - def _tmp_213(self) -> Optional[Any]: - # _tmp_213: param_no_default | ',' + def _tmp_218(self) -> Optional[Any]: + # _tmp_218: param_no_default | ',' mark = self._mark() - if ( - (param_no_default := self.param_no_default()) - ): - return param_no_default; + if param_no_default := self.param_no_default(): + return param_no_default self._reset(mark) - if ( - (literal := self.expect(',')) - ): - return literal; + if literal := self.expect(","): + return literal self._reset(mark) - return None; + return None @memoize - def _loop0_214(self) -> Optional[Any]: - # _loop0_214: param_maybe_default + def _loop0_219(self) -> Optional[Any]: + # _loop0_219: param_maybe_default mark = self._mark() children = [] - while ( - (param_maybe_default := self.param_maybe_default()) - ): + while param_maybe_default := self.param_maybe_default(): children.append(param_maybe_default) mark = self._mark() self._reset(mark) - return children; + return children @memoize - def _tmp_215(self) -> Optional[Any]: - # _tmp_215: param_no_default | ',' + def _tmp_220(self) -> Optional[Any]: + # _tmp_220: param_no_default | ',' mark = self._mark() - if ( - (param_no_default := self.param_no_default()) - ): - return param_no_default; + if param_no_default := self.param_no_default(): + return param_no_default self._reset(mark) - if ( - (literal := self.expect(',')) - ): - return literal; + if literal := self.expect(","): + return literal self._reset(mark) - return None; + return None @memoize - def _tmp_216(self) -> Optional[Any]: - # _tmp_216: '*' | '**' | '/' + def _tmp_221(self) -> Optional[Any]: + # _tmp_221: '*' | '**' | '/' mark = self._mark() - if ( - (literal := self.expect('*')) - ): - return literal; + if literal := self.expect("*"): + return literal self._reset(mark) - if ( - (literal := self.expect('**')) - ): - return literal; + if literal := self.expect("**"): + return literal self._reset(mark) - if ( - (literal := self.expect('/')) - ): - return literal; + if literal := self.expect("/"): + return literal self._reset(mark) - return None; + return None @memoize - def _loop1_217(self) -> Optional[Any]: - # _loop1_217: param_with_default + def _loop1_222(self) -> Optional[Any]: + # _loop1_222: param_with_default mark = self._mark() children = [] - while ( - (param_with_default := self.param_with_default()) - ): + while param_with_default := self.param_with_default(): children.append(param_with_default) mark = self._mark() self._reset(mark) - return children; + return children @memoize - def _tmp_218(self) -> Optional[Any]: - # _tmp_218: lambda_slash_no_default | lambda_slash_with_default + def _tmp_223(self) -> Optional[Any]: + # _tmp_223: lambda_slash_no_default | lambda_slash_with_default mark = self._mark() - if ( - (lambda_slash_no_default := self.lambda_slash_no_default()) - ): - return lambda_slash_no_default; + if lambda_slash_no_default := self.lambda_slash_no_default(): + return lambda_slash_no_default self._reset(mark) - if ( - (lambda_slash_with_default := self.lambda_slash_with_default()) - ): - return lambda_slash_with_default; + if lambda_slash_with_default := self.lambda_slash_with_default(): + return lambda_slash_with_default self._reset(mark) - return None; + return None @memoize - def _loop0_219(self) -> Optional[Any]: - # _loop0_219: lambda_param_maybe_default + def _loop0_224(self) -> Optional[Any]: + # _loop0_224: lambda_param_maybe_default mark = self._mark() children = [] - while ( - (lambda_param_maybe_default := self.lambda_param_maybe_default()) - ): + while lambda_param_maybe_default := self.lambda_param_maybe_default(): children.append(lambda_param_maybe_default) mark = self._mark() self._reset(mark) - return children; + return children @memoize - def _loop0_220(self) -> Optional[Any]: - # _loop0_220: lambda_param_no_default + def _loop0_225(self) -> Optional[Any]: + # _loop0_225: lambda_param_no_default mark = self._mark() children = [] - while ( - (lambda_param_no_default := self.lambda_param_no_default()) - ): + while lambda_param_no_default := self.lambda_param_no_default(): children.append(lambda_param_no_default) mark = self._mark() self._reset(mark) - return children; + return children @memoize - def _loop0_221(self) -> Optional[Any]: - # _loop0_221: lambda_param_no_default + def _loop0_226(self) -> Optional[Any]: + # _loop0_226: lambda_param_no_default mark = self._mark() children = [] - while ( - (lambda_param_no_default := self.lambda_param_no_default()) - ): + while lambda_param_no_default := self.lambda_param_no_default(): children.append(lambda_param_no_default) mark = self._mark() self._reset(mark) - return children; + return children @memoize - def _loop0_223(self) -> Optional[Any]: - # _loop0_223: ',' lambda_param + def _loop0_228(self) -> Optional[Any]: + # _loop0_228: ',' lambda_param mark = self._mark() children = [] - while ( - (self.expect(',')) - and - (elem := self.lambda_param()) - ): + while (self.expect(",")) and (elem := self.lambda_param()): children.append(elem) mark = self._mark() self._reset(mark) - return children; + return children @memoize - def _gather_222(self) -> Optional[Any]: - # _gather_222: lambda_param _loop0_223 + def _gather_227(self) -> Optional[Any]: + # _gather_227: lambda_param _loop0_228 mark = self._mark() - if ( - (elem := self.lambda_param()) - is not None - and - (seq := self._loop0_223()) - is not None - ): - return [elem] + seq; + if (elem := self.lambda_param()) is not None and ( + seq := self._loop0_228() + ) is not None: + return [elem] + seq self._reset(mark) - return None; + return None @memoize - def _tmp_224(self) -> Optional[Any]: - # _tmp_224: lambda_slash_no_default | lambda_slash_with_default + def _tmp_229(self) -> Optional[Any]: + # _tmp_229: lambda_slash_no_default | lambda_slash_with_default mark = self._mark() - if ( - (lambda_slash_no_default := self.lambda_slash_no_default()) - ): - return lambda_slash_no_default; + if lambda_slash_no_default := self.lambda_slash_no_default(): + return lambda_slash_no_default self._reset(mark) - if ( - (lambda_slash_with_default := self.lambda_slash_with_default()) - ): - return lambda_slash_with_default; + if lambda_slash_with_default := self.lambda_slash_with_default(): + return lambda_slash_with_default self._reset(mark) - return None; + return None @memoize - def _loop0_225(self) -> Optional[Any]: - # _loop0_225: lambda_param_maybe_default + def _loop0_230(self) -> Optional[Any]: + # _loop0_230: lambda_param_maybe_default mark = self._mark() children = [] - while ( - (lambda_param_maybe_default := self.lambda_param_maybe_default()) - ): + while lambda_param_maybe_default := self.lambda_param_maybe_default(): children.append(lambda_param_maybe_default) mark = self._mark() self._reset(mark) - return children; + return children @memoize - def _tmp_226(self) -> Optional[Any]: - # _tmp_226: ',' | lambda_param_no_default + def _tmp_231(self) -> Optional[Any]: + # _tmp_231: ',' | lambda_param_no_default mark = self._mark() - if ( - (literal := self.expect(',')) - ): - return literal; + if literal := self.expect(","): + return literal self._reset(mark) - if ( - (lambda_param_no_default := self.lambda_param_no_default()) - ): - return lambda_param_no_default; + if lambda_param_no_default := self.lambda_param_no_default(): + return lambda_param_no_default self._reset(mark) - return None; + return None @memoize - def _loop0_227(self) -> Optional[Any]: - # _loop0_227: lambda_param_maybe_default + def _loop0_232(self) -> Optional[Any]: + # _loop0_232: lambda_param_maybe_default mark = self._mark() children = [] - while ( - (lambda_param_maybe_default := self.lambda_param_maybe_default()) - ): + while lambda_param_maybe_default := self.lambda_param_maybe_default(): children.append(lambda_param_maybe_default) mark = self._mark() self._reset(mark) - return children; + return children @memoize - def _loop1_228(self) -> Optional[Any]: - # _loop1_228: lambda_param_maybe_default + def _loop1_233(self) -> Optional[Any]: + # _loop1_233: lambda_param_maybe_default mark = self._mark() children = [] - while ( - (lambda_param_maybe_default := self.lambda_param_maybe_default()) - ): + while lambda_param_maybe_default := self.lambda_param_maybe_default(): children.append(lambda_param_maybe_default) mark = self._mark() self._reset(mark) - return children; + return children @memoize - def _loop1_229(self) -> Optional[Any]: - # _loop1_229: lambda_param_with_default + def _loop1_234(self) -> Optional[Any]: + # _loop1_234: lambda_param_with_default mark = self._mark() children = [] - while ( - (lambda_param_with_default := self.lambda_param_with_default()) - ): + while lambda_param_with_default := self.lambda_param_with_default(): children.append(lambda_param_with_default) mark = self._mark() self._reset(mark) - return children; + return children @memoize - def _tmp_230(self) -> Optional[Any]: - # _tmp_230: ':' | ',' (':' | '**') + def _tmp_235(self) -> Optional[Any]: + # _tmp_235: ':' | ',' (':' | '**') mark = self._mark() - if ( - (literal := self.expect(':')) - ): - return literal; + if literal := self.expect(":"): + return literal self._reset(mark) - if ( - (literal := self.expect(',')) - and - (_tmp_304 := self._tmp_304()) - ): - return [literal, _tmp_304]; + if (literal := self.expect(",")) and (_tmp_330 := self._tmp_330()): + return [literal, _tmp_330] self._reset(mark) - return None; + return None @memoize - def _tmp_231(self) -> Optional[Any]: - # _tmp_231: lambda_param_no_default | ',' + def _tmp_236(self) -> Optional[Any]: + # _tmp_236: lambda_param_no_default | ',' mark = self._mark() - if ( - (lambda_param_no_default := self.lambda_param_no_default()) - ): - return lambda_param_no_default; + if lambda_param_no_default := self.lambda_param_no_default(): + return lambda_param_no_default self._reset(mark) - if ( - (literal := self.expect(',')) - ): - return literal; + if literal := self.expect(","): + return literal self._reset(mark) - return None; + return None @memoize - def _loop0_232(self) -> Optional[Any]: - # _loop0_232: lambda_param_maybe_default + def _loop0_237(self) -> Optional[Any]: + # _loop0_237: lambda_param_maybe_default mark = self._mark() children = [] - while ( - (lambda_param_maybe_default := self.lambda_param_maybe_default()) - ): + while lambda_param_maybe_default := self.lambda_param_maybe_default(): children.append(lambda_param_maybe_default) mark = self._mark() self._reset(mark) - return children; + return children @memoize - def _tmp_233(self) -> Optional[Any]: - # _tmp_233: lambda_param_no_default | ',' + def _tmp_238(self) -> Optional[Any]: + # _tmp_238: lambda_param_no_default | ',' mark = self._mark() - if ( - (lambda_param_no_default := self.lambda_param_no_default()) - ): - return lambda_param_no_default; + if lambda_param_no_default := self.lambda_param_no_default(): + return lambda_param_no_default self._reset(mark) - if ( - (literal := self.expect(',')) - ): - return literal; + if literal := self.expect(","): + return literal self._reset(mark) - return None; + return None @memoize - def _tmp_234(self) -> Optional[Any]: - # _tmp_234: '*' | '**' | '/' + def _tmp_239(self) -> Optional[Any]: + # _tmp_239: '*' | '**' | '/' mark = self._mark() - if ( - (literal := self.expect('*')) - ): - return literal; + if literal := self.expect("*"): + return literal self._reset(mark) - if ( - (literal := self.expect('**')) - ): - return literal; + if literal := self.expect("**"): + return literal self._reset(mark) - if ( - (literal := self.expect('/')) - ): - return literal; + if literal := self.expect("/"): + return literal self._reset(mark) - return None; + return None @memoize - def _tmp_235(self) -> Optional[Any]: - # _tmp_235: ',' | ')' | ':' + def _tmp_240(self) -> Optional[Any]: + # _tmp_240: ',' | ')' | ':' mark = self._mark() - if ( - (literal := self.expect(',')) - ): - return literal; + if literal := self.expect(","): + return literal self._reset(mark) - if ( - (literal := self.expect(')')) - ): - return literal; + if literal := self.expect(")"): + return literal self._reset(mark) - if ( - (literal := self.expect(':')) - ): - return literal; + if literal := self.expect(":"): + return literal self._reset(mark) - return None; + return None @memoize - def _loop0_237(self) -> Optional[Any]: - # _loop0_237: ',' dotted_name + def _loop0_242(self) -> Optional[Any]: + # _loop0_242: ',' dotted_name mark = self._mark() children = [] - while ( - (self.expect(',')) - and - (elem := self.dotted_name()) - ): + while (self.expect(",")) and (elem := self.dotted_name()): children.append(elem) mark = self._mark() self._reset(mark) - return children; + return children @memoize - def _gather_236(self) -> Optional[Any]: - # _gather_236: dotted_name _loop0_237 + def _gather_241(self) -> Optional[Any]: + # _gather_241: dotted_name _loop0_242 mark = self._mark() - if ( - (elem := self.dotted_name()) - is not None - and - (seq := self._loop0_237()) - is not None - ): - return [elem] + seq; + if (elem := self.dotted_name()) is not None and ( + seq := self._loop0_242() + ) is not None: + return [elem] + seq self._reset(mark) - return None; + return None @memoize - def _loop0_239(self) -> Optional[Any]: - # _loop0_239: ',' (expression ['as' star_target]) + def _loop0_243(self) -> Optional[Any]: + # _loop0_243: ('.' | '...') mark = self._mark() children = [] - while ( - (self.expect(',')) - and - (elem := self._tmp_305()) - ): + while _tmp_331 := self._tmp_331(): + children.append(_tmp_331) + mark = self._mark() + self._reset(mark) + return children + + @memoize + def _loop0_245(self) -> Optional[Any]: + # _loop0_245: ',' (expression ['as' star_target]) + mark = self._mark() + children = [] + while (self.expect(",")) and (elem := self._tmp_332()): children.append(elem) mark = self._mark() self._reset(mark) - return children; + return children @memoize - def _gather_238(self) -> Optional[Any]: - # _gather_238: (expression ['as' star_target]) _loop0_239 + def _gather_244(self) -> Optional[Any]: + # _gather_244: (expression ['as' star_target]) _loop0_245 mark = self._mark() - if ( - (elem := self._tmp_305()) - is not None - and - (seq := self._loop0_239()) - is not None - ): - return [elem] + seq; + if (elem := self._tmp_332()) is not None and ( + seq := self._loop0_245() + ) is not None: + return [elem] + seq self._reset(mark) - return None; + return None @memoize - def _loop0_241(self) -> Optional[Any]: - # _loop0_241: ',' (expressions ['as' star_target]) + def _loop0_247(self) -> Optional[Any]: + # _loop0_247: ',' (expressions ['as' star_target]) mark = self._mark() children = [] - while ( - (self.expect(',')) - and - (elem := self._tmp_306()) - ): + while (self.expect(",")) and (elem := self._tmp_333()): children.append(elem) mark = self._mark() self._reset(mark) - return children; + return children @memoize - def _gather_240(self) -> Optional[Any]: - # _gather_240: (expressions ['as' star_target]) _loop0_241 + def _gather_246(self) -> Optional[Any]: + # _gather_246: (expressions ['as' star_target]) _loop0_247 mark = self._mark() - if ( - (elem := self._tmp_306()) - is not None - and - (seq := self._loop0_241()) - is not None - ): - return [elem] + seq; + if (elem := self._tmp_333()) is not None and ( + seq := self._loop0_247() + ) is not None: + return [elem] + seq self._reset(mark) - return None; + return None @memoize - def _loop0_243(self) -> Optional[Any]: - # _loop0_243: ',' (expression ['as' star_target]) + def _loop0_249(self) -> Optional[Any]: + # _loop0_249: ',' (expression ['as' star_target]) mark = self._mark() children = [] - while ( - (self.expect(',')) - and - (elem := self._tmp_307()) - ): + while (self.expect(",")) and (elem := self._tmp_334()): children.append(elem) mark = self._mark() self._reset(mark) - return children; + return children @memoize - def _gather_242(self) -> Optional[Any]: - # _gather_242: (expression ['as' star_target]) _loop0_243 + def _gather_248(self) -> Optional[Any]: + # _gather_248: (expression ['as' star_target]) _loop0_249 mark = self._mark() - if ( - (elem := self._tmp_307()) - is not None - and - (seq := self._loop0_243()) - is not None - ): - return [elem] + seq; + if (elem := self._tmp_334()) is not None and ( + seq := self._loop0_249() + ) is not None: + return [elem] + seq self._reset(mark) - return None; + return None @memoize - def _loop0_245(self) -> Optional[Any]: - # _loop0_245: ',' (expressions ['as' star_target]) + def _loop0_251(self) -> Optional[Any]: + # _loop0_251: ',' (expressions ['as' star_target]) mark = self._mark() children = [] - while ( - (self.expect(',')) - and - (elem := self._tmp_308()) - ): + while (self.expect(",")) and (elem := self._tmp_335()): children.append(elem) mark = self._mark() self._reset(mark) - return children; + return children @memoize - def _gather_244(self) -> Optional[Any]: - # _gather_244: (expressions ['as' star_target]) _loop0_245 + def _gather_250(self) -> Optional[Any]: + # _gather_250: (expressions ['as' star_target]) _loop0_251 mark = self._mark() - if ( - (elem := self._tmp_308()) - is not None - and - (seq := self._loop0_245()) - is not None - ): - return [elem] + seq; + if (elem := self._tmp_335()) is not None and ( + seq := self._loop0_251() + ) is not None: + return [elem] + seq self._reset(mark) - return None; + return None @memoize - def _tmp_246(self) -> Optional[Any]: - # _tmp_246: 'except' | 'finally' + def _tmp_252(self) -> Optional[Any]: + # _tmp_252: 'except' | 'finally' mark = self._mark() - if ( - (literal := self.expect('except')) - ): - return literal; + if literal := self.expect("except"): + return literal self._reset(mark) - if ( - (literal := self.expect('finally')) - ): - return literal; + if literal := self.expect("finally"): + return literal self._reset(mark) - return None; + return None @memoize - def _loop0_247(self) -> Optional[Any]: - # _loop0_247: block + def _loop0_253(self) -> Optional[Any]: + # _loop0_253: block mark = self._mark() children = [] - while ( - (block := self.block()) - ): + while block := self.block(): children.append(block) mark = self._mark() self._reset(mark) - return children; + return children @memoize - def _loop1_248(self) -> Optional[Any]: - # _loop1_248: except_block + def _loop1_254(self) -> Optional[Any]: + # _loop1_254: except_block mark = self._mark() children = [] - while ( - (except_block := self.except_block()) - ): + while except_block := self.except_block(): children.append(except_block) mark = self._mark() self._reset(mark) - return children; + return children @memoize - def _tmp_249(self) -> Optional[Any]: - # _tmp_249: 'as' NAME + def _tmp_255(self) -> Optional[Any]: + # _tmp_255: 'as' NAME mark = self._mark() - if ( - (literal := self.expect('as')) - and - (name := self.name()) - ): - return [literal, name]; + if (literal := self.expect("as")) and (name := self.name()): + return [literal, name] self._reset(mark) - return None; + return None @memoize - def _loop0_250(self) -> Optional[Any]: - # _loop0_250: block + def _loop0_256(self) -> Optional[Any]: + # _loop0_256: block mark = self._mark() children = [] - while ( - (block := self.block()) - ): + while block := self.block(): children.append(block) mark = self._mark() self._reset(mark) - return children; + return children @memoize - def _loop1_251(self) -> Optional[Any]: - # _loop1_251: except_star_block + def _loop1_257(self) -> Optional[Any]: + # _loop1_257: except_star_block mark = self._mark() children = [] - while ( - (except_star_block := self.except_star_block()) - ): + while except_star_block := self.except_star_block(): children.append(except_star_block) mark = self._mark() self._reset(mark) - return children; + return children @memoize - def _tmp_252(self) -> Optional[Any]: - # _tmp_252: expression ['as' NAME] + def _tmp_258(self) -> Optional[Any]: + # _tmp_258: expression ['as' NAME] mark = self._mark() - if ( - (expression := self.expression()) - and - (opt := self._tmp_309(),) - ): - return [expression, opt]; + if (expression := self.expression()) and (opt := self._tmp_336(),): + return [expression, opt] self._reset(mark) - return None; + return None @memoize - def _tmp_253(self) -> Optional[Any]: - # _tmp_253: 'as' NAME + def _tmp_259(self) -> Optional[Any]: + # _tmp_259: 'as' NAME mark = self._mark() - if ( - (literal := self.expect('as')) - and - (name := self.name()) - ): - return [literal, name]; + if (literal := self.expect("as")) and (name := self.name()): + return [literal, name] self._reset(mark) - return None; + return None @memoize - def _tmp_254(self) -> Optional[Any]: - # _tmp_254: 'as' NAME + def _tmp_260(self) -> Optional[Any]: + # _tmp_260: 'as' NAME mark = self._mark() - if ( - (literal := self.expect('as')) - and - (name := self.name()) - ): - return [literal, name]; + if (literal := self.expect("as")) and (name := self.name()): + return [literal, name] self._reset(mark) - return None; + return None @memoize - def _tmp_255(self) -> Optional[Any]: - # _tmp_255: NEWLINE | ':' + def _tmp_261(self) -> Optional[Any]: + # _tmp_261: NEWLINE | ':' mark = self._mark() - if ( - (_newline := self.expect('NEWLINE')) - ): - return _newline; + if _newline := self.expect("NEWLINE"): + return _newline self._reset(mark) - if ( - (literal := self.expect(':')) - ): - return literal; + if literal := self.expect(":"): + return literal self._reset(mark) - return None; + return None @memoize - def _tmp_256(self) -> Optional[Any]: - # _tmp_256: 'as' NAME + def _tmp_262(self) -> Optional[Any]: + # _tmp_262: 'as' NAME mark = self._mark() - if ( - (literal := self.expect('as')) - and - (name := self.name()) - ): - return [literal, name]; + if (literal := self.expect("as")) and (name := self.name()): + return [literal, name] self._reset(mark) - return None; + return None @memoize - def _tmp_257(self) -> Optional[Any]: - # _tmp_257: 'as' NAME + def _tmp_263(self) -> Optional[Any]: + # _tmp_263: 'as' NAME mark = self._mark() - if ( - (literal := self.expect('as')) - and - (name := self.name()) - ): - return [literal, name]; + if (literal := self.expect("as")) and (name := self.name()): + return [literal, name] self._reset(mark) - return None; + return None @memoize - def _tmp_258(self) -> Optional[Any]: - # _tmp_258: positional_patterns ',' + def _tmp_264(self) -> Optional[Any]: + # _tmp_264: positional_patterns ',' mark = self._mark() - if ( - (positional_patterns := self.positional_patterns()) - and - (literal := self.expect(',')) + if (positional_patterns := self.positional_patterns()) and ( + literal := self.expect(",") ): - return [positional_patterns, literal]; + return [positional_patterns, literal] self._reset(mark) - return None; + return None @memoize - def _tmp_259(self) -> Optional[Any]: - # _tmp_259: '->' expression + def _tmp_265(self) -> Optional[Any]: + # _tmp_265: '->' expression mark = self._mark() - if ( - (literal := self.expect('->')) - and - (expression := self.expression()) - ): - return [literal, expression]; + if (literal := self.expect("->")) and (expression := self.expression()): + return [literal, expression] self._reset(mark) - return None; + return None @memoize - def _tmp_260(self) -> Optional[Any]: - # _tmp_260: '(' arguments? ')' + def _tmp_266(self) -> Optional[Any]: + # _tmp_266: '(' arguments? ')' mark = self._mark() if ( - (literal := self.expect('(')) - and - (opt := self.arguments(),) - and - (literal_1 := self.expect(')')) + (literal := self.expect("(")) + and (opt := self.arguments(),) + and (literal_1 := self.expect(")")) ): - return [literal, opt, literal_1]; + return [literal, opt, literal_1] self._reset(mark) - return None; + return None @memoize - def _tmp_261(self) -> Optional[Any]: - # _tmp_261: '(' arguments? ')' + def _tmp_267(self) -> Optional[Any]: + # _tmp_267: '(' arguments? ')' mark = self._mark() if ( - (literal := self.expect('(')) - and - (opt := self.arguments(),) - and - (literal_1 := self.expect(')')) + (literal := self.expect("(")) + and (opt := self.arguments(),) + and (literal_1 := self.expect(")")) ): - return [literal, opt, literal_1]; + return [literal, opt, literal_1] self._reset(mark) - return None; + return None @memoize - def _loop0_263(self) -> Optional[Any]: - # _loop0_263: ',' double_starred_kvpair + def _loop0_269(self) -> Optional[Any]: + # _loop0_269: ',' double_starred_kvpair mark = self._mark() children = [] - while ( - (self.expect(',')) - and - (elem := self.double_starred_kvpair()) - ): + while (self.expect(",")) and (elem := self.double_starred_kvpair()): children.append(elem) mark = self._mark() self._reset(mark) - return children; + return children @memoize - def _gather_262(self) -> Optional[Any]: - # _gather_262: double_starred_kvpair _loop0_263 + def _gather_268(self) -> Optional[Any]: + # _gather_268: double_starred_kvpair _loop0_269 mark = self._mark() - if ( - (elem := self.double_starred_kvpair()) - is not None - and - (seq := self._loop0_263()) - is not None - ): - return [elem] + seq; + if (elem := self.double_starred_kvpair()) is not None and ( + seq := self._loop0_269() + ) is not None: + return [elem] + seq self._reset(mark) - return None; + return None @memoize - def _tmp_264(self) -> Optional[Any]: - # _tmp_264: '}' | ',' + def _tmp_270(self) -> Optional[Any]: + # _tmp_270: '}' | ',' mark = self._mark() - if ( - (literal := self.expect('}')) - ): - return literal; + if literal := self.expect("}"): + return literal self._reset(mark) - if ( - (literal := self.expect(',')) - ): - return literal; + if literal := self.expect(","): + return literal self._reset(mark) - return None; + return None @memoize - def _tmp_265(self) -> Optional[Any]: - # _tmp_265: '}' | ',' + def _tmp_271(self) -> Optional[Any]: + # _tmp_271: '}' | ',' mark = self._mark() - if ( - (literal := self.expect('}')) - ): - return literal; + if literal := self.expect("}"): + return literal self._reset(mark) - if ( - (literal := self.expect(',')) - ): - return literal; + if literal := self.expect(","): + return literal self._reset(mark) - return None; + return None @memoize - def _tmp_266(self) -> Optional[Any]: - # _tmp_266: yield_expr | star_expressions + def _tmp_272(self) -> Optional[Any]: + # _tmp_272: yield_expr | star_expressions mark = self._mark() - if ( - (yield_expr := self.yield_expr()) - ): - return yield_expr; + if yield_expr := self.yield_expr(): + return yield_expr self._reset(mark) - if ( - (star_expressions := self.star_expressions()) - ): - return star_expressions; + if star_expressions := self.star_expressions(): + return star_expressions self._reset(mark) - return None; + return None @memoize - def _tmp_267(self) -> Optional[Any]: - # _tmp_267: yield_expr | star_expressions + def _tmp_273(self) -> Optional[Any]: + # _tmp_273: yield_expr | star_expressions mark = self._mark() - if ( - (yield_expr := self.yield_expr()) - ): - return yield_expr; + if yield_expr := self.yield_expr(): + return yield_expr self._reset(mark) - if ( - (star_expressions := self.star_expressions()) - ): - return star_expressions; + if star_expressions := self.star_expressions(): + return star_expressions self._reset(mark) - return None; + return None @memoize - def _tmp_268(self) -> Optional[Any]: - # _tmp_268: '=' | '!' | ':' | '}' + def _tmp_274(self) -> Optional[Any]: + # _tmp_274: '=' | '!' | ':' | '}' mark = self._mark() - if ( - (literal := self.expect('=')) - ): - return literal; + if literal := self.expect("="): + return literal self._reset(mark) - if ( - (literal := self.expect('!')) - ): - return literal; + if literal := self.expect("!"): + return literal self._reset(mark) - if ( - (literal := self.expect(':')) - ): - return literal; + if literal := self.expect(":"): + return literal self._reset(mark) - if ( - (literal := self.expect('}')) - ): - return literal; + if literal := self.expect("}"): + return literal self._reset(mark) - return None; + return None @memoize - def _tmp_269(self) -> Optional[Any]: - # _tmp_269: yield_expr | star_expressions + def _tmp_275(self) -> Optional[Any]: + # _tmp_275: yield_expr | star_expressions mark = self._mark() - if ( - (yield_expr := self.yield_expr()) - ): - return yield_expr; + if yield_expr := self.yield_expr(): + return yield_expr self._reset(mark) - if ( - (star_expressions := self.star_expressions()) - ): - return star_expressions; + if star_expressions := self.star_expressions(): + return star_expressions self._reset(mark) - return None; + return None @memoize - def _tmp_270(self) -> Optional[Any]: - # _tmp_270: '!' | ':' | '}' + def _tmp_276(self) -> Optional[Any]: + # _tmp_276: '!' | ':' | '}' mark = self._mark() - if ( - (literal := self.expect('!')) - ): - return literal; + if literal := self.expect("!"): + return literal self._reset(mark) - if ( - (literal := self.expect(':')) - ): - return literal; + if literal := self.expect(":"): + return literal self._reset(mark) - if ( - (literal := self.expect('}')) - ): - return literal; + if literal := self.expect("}"): + return literal self._reset(mark) - return None; + return None @memoize - def _tmp_271(self) -> Optional[Any]: - # _tmp_271: yield_expr | star_expressions + def _tmp_277(self) -> Optional[Any]: + # _tmp_277: yield_expr | star_expressions mark = self._mark() - if ( - (yield_expr := self.yield_expr()) - ): - return yield_expr; + if yield_expr := self.yield_expr(): + return yield_expr self._reset(mark) - if ( - (star_expressions := self.star_expressions()) - ): - return star_expressions; + if star_expressions := self.star_expressions(): + return star_expressions self._reset(mark) - return None; + return None @memoize - def _tmp_272(self) -> Optional[Any]: - # _tmp_272: yield_expr | star_expressions + def _tmp_278(self) -> Optional[Any]: + # _tmp_278: yield_expr | star_expressions mark = self._mark() - if ( - (yield_expr := self.yield_expr()) - ): - return yield_expr; + if yield_expr := self.yield_expr(): + return yield_expr self._reset(mark) - if ( - (star_expressions := self.star_expressions()) - ): - return star_expressions; + if star_expressions := self.star_expressions(): + return star_expressions self._reset(mark) - return None; + return None @memoize - def _tmp_273(self) -> Optional[Any]: - # _tmp_273: '!' NAME + def _tmp_279(self) -> Optional[Any]: + # _tmp_279: '!' NAME mark = self._mark() - if ( - (literal := self.expect('!')) - and - (name := self.name()) - ): - return [literal, name]; + if (literal := self.expect("!")) and (name := self.name()): + return [literal, name] self._reset(mark) - return None; + return None @memoize - def _tmp_274(self) -> Optional[Any]: - # _tmp_274: ':' | '}' + def _tmp_280(self) -> Optional[Any]: + # _tmp_280: ':' | '}' mark = self._mark() - if ( - (literal := self.expect(':')) - ): - return literal; + if literal := self.expect(":"): + return literal self._reset(mark) - if ( - (literal := self.expect('}')) - ): - return literal; + if literal := self.expect("}"): + return literal self._reset(mark) - return None; + return None @memoize - def _tmp_275(self) -> Optional[Any]: - # _tmp_275: yield_expr | star_expressions + def _tmp_281(self) -> Optional[Any]: + # _tmp_281: yield_expr | star_expressions mark = self._mark() - if ( - (yield_expr := self.yield_expr()) - ): - return yield_expr; + if yield_expr := self.yield_expr(): + return yield_expr self._reset(mark) - if ( - (star_expressions := self.star_expressions()) - ): - return star_expressions; + if star_expressions := self.star_expressions(): + return star_expressions self._reset(mark) - return None; + return None @memoize - def _tmp_276(self) -> Optional[Any]: - # _tmp_276: '!' NAME + def _tmp_282(self) -> Optional[Any]: + # _tmp_282: '!' NAME mark = self._mark() - if ( - (literal := self.expect('!')) - and - (name := self.name()) - ): - return [literal, name]; + if (literal := self.expect("!")) and (name := self.name()): + return [literal, name] self._reset(mark) - return None; + return None @memoize - def _loop0_277(self) -> Optional[Any]: - # _loop0_277: fstring_format_spec + def _loop0_283(self) -> Optional[Any]: + # _loop0_283: fstring_format_spec mark = self._mark() children = [] - while ( - (fstring_format_spec := self.fstring_format_spec()) - ): + while fstring_format_spec := self.fstring_format_spec(): children.append(fstring_format_spec) mark = self._mark() self._reset(mark) - return children; + return children @memoize - def _tmp_278(self) -> Optional[Any]: - # _tmp_278: yield_expr | star_expressions + def _tmp_284(self) -> Optional[Any]: + # _tmp_284: yield_expr | star_expressions mark = self._mark() - if ( - (yield_expr := self.yield_expr()) - ): - return yield_expr; + if yield_expr := self.yield_expr(): + return yield_expr self._reset(mark) - if ( - (star_expressions := self.star_expressions()) - ): - return star_expressions; + if star_expressions := self.star_expressions(): + return star_expressions self._reset(mark) - return None; + return None @memoize - def _tmp_279(self) -> Optional[Any]: - # _tmp_279: '!' NAME + def _tmp_285(self) -> Optional[Any]: + # _tmp_285: '!' NAME mark = self._mark() - if ( - (literal := self.expect('!')) - and - (name := self.name()) - ): - return [literal, name]; + if (literal := self.expect("!")) and (name := self.name()): + return [literal, name] self._reset(mark) - return None; + return None @memoize - def _tmp_280(self) -> Optional[Any]: - # _tmp_280: ':' | '}' + def _tmp_286(self) -> Optional[Any]: + # _tmp_286: ':' | '}' mark = self._mark() - if ( - (literal := self.expect(':')) - ): - return literal; + if literal := self.expect(":"): + return literal self._reset(mark) - if ( - (literal := self.expect('}')) - ): - return literal; + if literal := self.expect("}"): + return literal self._reset(mark) - return None; + return None @memoize - def _loop0_282(self) -> Optional[Any]: - # _loop0_282: ',' pragma_arg + def _tmp_287(self) -> Optional[Any]: + # _tmp_287: yield_expr | star_expressions + mark = self._mark() + if yield_expr := self.yield_expr(): + return yield_expr + self._reset(mark) + if star_expressions := self.star_expressions(): + return star_expressions + self._reset(mark) + return None + + @memoize + def _tmp_288(self) -> Optional[Any]: + # _tmp_288: yield_expr | star_expressions + mark = self._mark() + if yield_expr := self.yield_expr(): + return yield_expr + self._reset(mark) + if star_expressions := self.star_expressions(): + return star_expressions + self._reset(mark) + return None + + @memoize + def _tmp_289(self) -> Optional[Any]: + # _tmp_289: '=' | '!' | ':' | '}' + mark = self._mark() + if literal := self.expect("="): + return literal + self._reset(mark) + if literal := self.expect("!"): + return literal + self._reset(mark) + if literal := self.expect(":"): + return literal + self._reset(mark) + if literal := self.expect("}"): + return literal + self._reset(mark) + return None + + @memoize + def _tmp_290(self) -> Optional[Any]: + # _tmp_290: yield_expr | star_expressions + mark = self._mark() + if yield_expr := self.yield_expr(): + return yield_expr + self._reset(mark) + if star_expressions := self.star_expressions(): + return star_expressions + self._reset(mark) + return None + + @memoize + def _tmp_291(self) -> Optional[Any]: + # _tmp_291: '!' | ':' | '}' + mark = self._mark() + if literal := self.expect("!"): + return literal + self._reset(mark) + if literal := self.expect(":"): + return literal + self._reset(mark) + if literal := self.expect("}"): + return literal + self._reset(mark) + return None + + @memoize + def _tmp_292(self) -> Optional[Any]: + # _tmp_292: yield_expr | star_expressions + mark = self._mark() + if yield_expr := self.yield_expr(): + return yield_expr + self._reset(mark) + if star_expressions := self.star_expressions(): + return star_expressions + self._reset(mark) + return None + + @memoize + def _tmp_293(self) -> Optional[Any]: + # _tmp_293: yield_expr | star_expressions + mark = self._mark() + if yield_expr := self.yield_expr(): + return yield_expr + self._reset(mark) + if star_expressions := self.star_expressions(): + return star_expressions + self._reset(mark) + return None + + @memoize + def _tmp_294(self) -> Optional[Any]: + # _tmp_294: '!' NAME + mark = self._mark() + if (literal := self.expect("!")) and (name := self.name()): + return [literal, name] + self._reset(mark) + return None + + @memoize + def _tmp_295(self) -> Optional[Any]: + # _tmp_295: ':' | '}' + mark = self._mark() + if literal := self.expect(":"): + return literal + self._reset(mark) + if literal := self.expect("}"): + return literal + self._reset(mark) + return None + + @memoize + def _tmp_296(self) -> Optional[Any]: + # _tmp_296: yield_expr | star_expressions + mark = self._mark() + if yield_expr := self.yield_expr(): + return yield_expr + self._reset(mark) + if star_expressions := self.star_expressions(): + return star_expressions + self._reset(mark) + return None + + @memoize + def _tmp_297(self) -> Optional[Any]: + # _tmp_297: '!' NAME + mark = self._mark() + if (literal := self.expect("!")) and (name := self.name()): + return [literal, name] + self._reset(mark) + return None + + @memoize + def _loop0_298(self) -> Optional[Any]: + # _loop0_298: tstring_format_spec mark = self._mark() children = [] - while ( - (self.expect(',')) - and - (elem := self.pragma_arg()) - ): + while tstring_format_spec := self.tstring_format_spec(): + children.append(tstring_format_spec) + mark = self._mark() + self._reset(mark) + return children + + @memoize + def _tmp_299(self) -> Optional[Any]: + # _tmp_299: yield_expr | star_expressions + mark = self._mark() + if yield_expr := self.yield_expr(): + return yield_expr + self._reset(mark) + if star_expressions := self.star_expressions(): + return star_expressions + self._reset(mark) + return None + + @memoize + def _tmp_300(self) -> Optional[Any]: + # _tmp_300: '!' NAME + mark = self._mark() + if (literal := self.expect("!")) and (name := self.name()): + return [literal, name] + self._reset(mark) + return None + + @memoize + def _tmp_301(self) -> Optional[Any]: + # _tmp_301: ':' | '}' + mark = self._mark() + if literal := self.expect(":"): + return literal + self._reset(mark) + if literal := self.expect("}"): + return literal + self._reset(mark) + return None + + @memoize + def _loop1_302(self) -> Optional[Any]: + # _loop1_302: (fstring | STRING) + mark = self._mark() + children = [] + while _tmp_337 := self._tmp_337(): + children.append(_tmp_337) + mark = self._mark() + self._reset(mark) + return children + + @memoize + def _loop1_303(self) -> Optional[Any]: + # _loop1_303: tstring + mark = self._mark() + children = [] + while tstring := self.tstring(): + children.append(tstring) + mark = self._mark() + self._reset(mark) + return children + + @memoize + def _tmp_304(self) -> Optional[Any]: + # _tmp_304: fstring | STRING + mark = self._mark() + if fstring := self.fstring(): + return fstring + self._reset(mark) + if string := self.string(): + return string + self._reset(mark) + return None + + @memoize + def _loop0_306(self) -> Optional[Any]: + # _loop0_306: ',' pragma_arg + mark = self._mark() + children = [] + while (self.expect(",")) and (elem := self.pragma_arg()): children.append(elem) mark = self._mark() self._reset(mark) - return children; + return children @memoize - def _gather_281(self) -> Optional[Any]: - # _gather_281: pragma_arg _loop0_282 + def _gather_305(self) -> Optional[Any]: + # _gather_305: pragma_arg _loop0_306 mark = self._mark() - if ( - (elem := self.pragma_arg()) - is not None - and - (seq := self._loop0_282()) - is not None - ): - return [elem] + seq; + if (elem := self.pragma_arg()) is not None and ( + seq := self._loop0_306() + ) is not None: + return [elem] + seq self._reset(mark) - return None; + return None @memoize - def _loop0_284(self) -> Optional[Any]: - # _loop0_284: '.' NAME + def _loop0_308(self) -> Optional[Any]: + # _loop0_308: '.' NAME mark = self._mark() children = [] - while ( - (self.expect('.')) - and - (elem := self.name()) - ): + while (self.expect(".")) and (elem := self.name()): children.append(elem) mark = self._mark() self._reset(mark) - return children; + return children @memoize - def _gather_283(self) -> Optional[Any]: - # _gather_283: NAME _loop0_284 + def _gather_307(self) -> Optional[Any]: + # _gather_307: NAME _loop0_308 mark = self._mark() - if ( - (elem := self.name()) - is not None - and - (seq := self._loop0_284()) - is not None - ): - return [elem] + seq; + if (elem := self.name()) is not None and (seq := self._loop0_308()) is not None: + return [elem] + seq self._reset(mark) - return None; + return None @memoize - def _loop0_286(self) -> Optional[Any]: - # _loop0_286: '.' NAME + def _loop0_310(self) -> Optional[Any]: + # _loop0_310: '.' NAME mark = self._mark() children = [] - while ( - (self.expect('.')) - and - (elem := self.name()) - ): + while (self.expect(".")) and (elem := self.name()): children.append(elem) mark = self._mark() self._reset(mark) - return children; + return children @memoize - def _gather_285(self) -> Optional[Any]: - # _gather_285: NAME _loop0_286 + def _gather_309(self) -> Optional[Any]: + # _gather_309: NAME _loop0_310 mark = self._mark() - if ( - (elem := self.name()) - is not None - and - (seq := self._loop0_286()) - is not None - ): - return [elem] + seq; + if (elem := self.name()) is not None and (seq := self._loop0_310()) is not None: + return [elem] + seq self._reset(mark) - return None; + return None @memoize - def _tmp_287(self) -> Optional[Any]: - # _tmp_287: star_targets '=' + def _tmp_311(self) -> Optional[Any]: + # _tmp_311: star_targets '=' mark = self._mark() - if ( - (z := self.star_targets()) - and - (self.expect('=')) - ): - return z; + if (z := self.star_targets()) and (self.expect("=")): + return z self._reset(mark) - return None; + return None @memoize - def _tmp_288(self) -> Optional[Any]: - # _tmp_288: '.' | '...' + def _tmp_312(self) -> Optional[Any]: + # _tmp_312: '.' | '...' mark = self._mark() - if ( - (literal := self.expect('.')) - ): - return literal; + if literal := self.expect("."): + return literal self._reset(mark) - if ( - (literal := self.expect('...')) - ): - return literal; + if literal := self.expect("..."): + return literal self._reset(mark) - return None; + return None @memoize - def _tmp_289(self) -> Optional[Any]: - # _tmp_289: '.' | '...' + def _tmp_313(self) -> Optional[Any]: + # _tmp_313: '.' | '...' mark = self._mark() - if ( - (literal := self.expect('.')) - ): - return literal; + if literal := self.expect("."): + return literal self._reset(mark) - if ( - (literal := self.expect('...')) - ): - return literal; + if literal := self.expect("..."): + return literal self._reset(mark) - return None; + return None @memoize - def _tmp_290(self) -> Optional[Any]: - # _tmp_290: ',' expression + def _tmp_314(self) -> Optional[Any]: + # _tmp_314: ',' expression mark = self._mark() - if ( - (self.expect(',')) - and - (c := self.expression()) - ): - return c; + if (self.expect(",")) and (c := self.expression()): + return c self._reset(mark) - return None; + return None @memoize - def _tmp_291(self) -> Optional[Any]: - # _tmp_291: ',' star_expression + def _tmp_315(self) -> Optional[Any]: + # _tmp_315: ',' star_expression mark = self._mark() - if ( - (self.expect(',')) - and - (c := self.star_expression()) - ): - return c; + if (self.expect(",")) and (c := self.star_expression()): + return c self._reset(mark) - return None; + return None @memoize - def _tmp_292(self) -> Optional[Any]: - # _tmp_292: 'or' conjunction + def _tmp_316(self) -> Optional[Any]: + # _tmp_316: 'or' conjunction mark = self._mark() - if ( - (self.expect('or')) - and - (c := self.conjunction()) - ): - return c; + if (self.expect("or")) and (c := self.conjunction()): + return c self._reset(mark) - return None; + return None @memoize - def _tmp_293(self) -> Optional[Any]: - # _tmp_293: 'and' inversion + def _tmp_317(self) -> Optional[Any]: + # _tmp_317: 'and' inversion mark = self._mark() - if ( - (self.expect('and')) - and - (c := self.inversion()) - ): - return c; + if (self.expect("and")) and (c := self.inversion()): + return c self._reset(mark) - return None; + return None @memoize - def _tmp_294(self) -> Optional[Any]: - # _tmp_294: slice | starred_expression + def _tmp_318(self) -> Optional[Any]: + # _tmp_318: slice | starred_expression mark = self._mark() - if ( - (slice := self.slice()) - ): - return slice; + if slice := self.slice(): + return slice self._reset(mark) - if ( - (starred_expression := self.starred_expression()) - ): - return starred_expression; + if starred_expression := self.starred_expression(): + return starred_expression self._reset(mark) - return None; + return None @memoize - def _tmp_295(self) -> Optional[Any]: - # _tmp_295: fstring | STRING + def _tmp_319(self) -> Optional[Any]: + # _tmp_319: fstring | STRING mark = self._mark() - if ( - (fstring := self.fstring()) - ): - return fstring; + if fstring := self.fstring(): + return fstring self._reset(mark) - if ( - (string := self.string()) - ): - return string; + if string := self.string(): + return string self._reset(mark) - return None; + return None @memoize - def _tmp_296(self) -> Optional[Any]: - # _tmp_296: 'if' disjunction + def _tmp_320(self) -> Optional[Any]: + # _tmp_320: 'if' disjunction mark = self._mark() - if ( - (self.expect('if')) - and - (z := self.disjunction()) - ): - return z; + if (self.expect("if")) and (z := self.disjunction()): + return z self._reset(mark) - return None; + return None @memoize - def _tmp_297(self) -> Optional[Any]: - # _tmp_297: 'if' disjunction + def _tmp_321(self) -> Optional[Any]: + # _tmp_321: 'if' disjunction mark = self._mark() - if ( - (self.expect('if')) - and - (z := self.disjunction()) - ): - return z; + if (self.expect("if")) and (z := self.disjunction()): + return z self._reset(mark) - return None; + return None @memoize - def _tmp_298(self) -> Optional[Any]: - # _tmp_298: starred_expression | (assignment_expression | expression !':=') !'=' + def _tmp_322(self) -> Optional[Any]: + # _tmp_322: starred_expression | (assignment_expression | expression !':=') !'=' mark = self._mark() - if ( - (starred_expression := self.starred_expression()) - ): - return starred_expression; + if starred_expression := self.starred_expression(): + return starred_expression self._reset(mark) - if ( - (_tmp_310 := self._tmp_310()) - and - (self.negative_lookahead(self.expect, '=')) + if (_tmp_338 := self._tmp_338()) and ( + self.negative_lookahead(self.expect, "=") ): - return _tmp_310; + return _tmp_338 self._reset(mark) - return None; + return None @memoize - def _tmp_299(self) -> Optional[Any]: - # _tmp_299: ',' star_target + def _tmp_323(self) -> Optional[Any]: + # _tmp_323: ',' star_target mark = self._mark() - if ( - (self.expect(',')) - and - (c := self.star_target()) - ): - return c; + if (self.expect(",")) and (c := self.star_target()): + return c self._reset(mark) - return None; + return None @memoize - def _tmp_300(self) -> Optional[Any]: - # _tmp_300: ',' star_target + def _tmp_324(self) -> Optional[Any]: + # _tmp_324: ',' star_target mark = self._mark() - if ( - (self.expect(',')) - and - (c := self.star_target()) - ): - return c; + if (self.expect(",")) and (c := self.star_target()): + return c self._reset(mark) - return None; + return None @memoize - def _tmp_301(self) -> Optional[Any]: - # _tmp_301: star_targets '=' + def _tmp_325(self) -> Optional[Any]: + # _tmp_325: ','.(starred_expression | (assignment_expression | expression !':=') !'=')+ ',' kwargs mark = self._mark() if ( - (star_targets := self.star_targets()) - and - (literal := self.expect('=')) + (_gather_339 := self._gather_339()) + and (literal := self.expect(",")) + and (kwargs := self.kwargs()) ): - return [star_targets, literal]; + return [_gather_339, literal, kwargs] self._reset(mark) - return None; + return None @memoize - def _tmp_302(self) -> Optional[Any]: - # _tmp_302: star_targets '=' + def _tmp_326(self) -> Optional[Any]: + # _tmp_326: starred_expression !'=' mark = self._mark() - if ( - (star_targets := self.star_targets()) - and - (literal := self.expect('=')) + if (starred_expression := self.starred_expression()) and ( + self.negative_lookahead(self.expect, "=") ): - return [star_targets, literal]; + return starred_expression self._reset(mark) - return None; + return None @memoize - def _tmp_303(self) -> Optional[Any]: - # _tmp_303: ')' | '**' + def _tmp_327(self) -> Optional[Any]: + # _tmp_327: star_targets '=' mark = self._mark() - if ( - (literal := self.expect(')')) - ): - return literal; + if (star_targets := self.star_targets()) and (literal := self.expect("=")): + return [star_targets, literal] self._reset(mark) - if ( - (literal := self.expect('**')) - ): - return literal; + return None + + @memoize + def _tmp_328(self) -> Optional[Any]: + # _tmp_328: star_targets '=' + mark = self._mark() + if (star_targets := self.star_targets()) and (literal := self.expect("=")): + return [star_targets, literal] self._reset(mark) - return None; + return None @memoize - def _tmp_304(self) -> Optional[Any]: - # _tmp_304: ':' | '**' + def _tmp_329(self) -> Optional[Any]: + # _tmp_329: ')' | '**' mark = self._mark() - if ( - (literal := self.expect(':')) - ): - return literal; + if literal := self.expect(")"): + return literal self._reset(mark) - if ( - (literal := self.expect('**')) - ): - return literal; + if literal := self.expect("**"): + return literal self._reset(mark) - return None; + return None @memoize - def _tmp_305(self) -> Optional[Any]: - # _tmp_305: expression ['as' star_target] + def _tmp_330(self) -> Optional[Any]: + # _tmp_330: ':' | '**' mark = self._mark() - if ( - (expression := self.expression()) - and - (opt := self._tmp_311(),) - ): - return [expression, opt]; + if literal := self.expect(":"): + return literal + self._reset(mark) + if literal := self.expect("**"): + return literal self._reset(mark) - return None; + return None @memoize - def _tmp_306(self) -> Optional[Any]: - # _tmp_306: expressions ['as' star_target] + def _tmp_331(self) -> Optional[Any]: + # _tmp_331: '.' | '...' mark = self._mark() - if ( - (expressions := self.expressions()) - and - (opt := self._tmp_312(),) - ): - return [expressions, opt]; + if literal := self.expect("."): + return literal + self._reset(mark) + if literal := self.expect("..."): + return literal self._reset(mark) - return None; + return None @memoize - def _tmp_307(self) -> Optional[Any]: - # _tmp_307: expression ['as' star_target] + def _tmp_332(self) -> Optional[Any]: + # _tmp_332: expression ['as' star_target] mark = self._mark() - if ( - (expression := self.expression()) - and - (opt := self._tmp_313(),) - ): - return [expression, opt]; + if (expression := self.expression()) and (opt := self._tmp_341(),): + return [expression, opt] self._reset(mark) - return None; + return None @memoize - def _tmp_308(self) -> Optional[Any]: - # _tmp_308: expressions ['as' star_target] + def _tmp_333(self) -> Optional[Any]: + # _tmp_333: expressions ['as' star_target] mark = self._mark() - if ( - (expressions := self.expressions()) - and - (opt := self._tmp_314(),) - ): - return [expressions, opt]; + if (expressions := self.expressions()) and (opt := self._tmp_342(),): + return [expressions, opt] self._reset(mark) - return None; + return None @memoize - def _tmp_309(self) -> Optional[Any]: - # _tmp_309: 'as' NAME + def _tmp_334(self) -> Optional[Any]: + # _tmp_334: expression ['as' star_target] mark = self._mark() - if ( - (literal := self.expect('as')) - and - (name := self.name()) - ): - return [literal, name]; + if (expression := self.expression()) and (opt := self._tmp_343(),): + return [expression, opt] self._reset(mark) - return None; + return None @memoize - def _tmp_310(self) -> Optional[Any]: - # _tmp_310: assignment_expression | expression !':=' + def _tmp_335(self) -> Optional[Any]: + # _tmp_335: expressions ['as' star_target] mark = self._mark() - if ( - (assignment_expression := self.assignment_expression()) - ): - return assignment_expression; + if (expressions := self.expressions()) and (opt := self._tmp_344(),): + return [expressions, opt] self._reset(mark) - if ( - (expression := self.expression()) - and - (self.negative_lookahead(self.expect, ':=')) - ): - return expression; + return None + + @memoize + def _tmp_336(self) -> Optional[Any]: + # _tmp_336: 'as' NAME + mark = self._mark() + if (literal := self.expect("as")) and (name := self.name()): + return [literal, name] self._reset(mark) - return None; + return None @memoize - def _tmp_311(self) -> Optional[Any]: - # _tmp_311: 'as' star_target + def _tmp_337(self) -> Optional[Any]: + # _tmp_337: fstring | STRING mark = self._mark() - if ( - (literal := self.expect('as')) - and - (star_target := self.star_target()) - ): - return [literal, star_target]; + if fstring := self.fstring(): + return fstring + self._reset(mark) + if string := self.string(): + return string self._reset(mark) - return None; + return None @memoize - def _tmp_312(self) -> Optional[Any]: - # _tmp_312: 'as' star_target + def _tmp_338(self) -> Optional[Any]: + # _tmp_338: assignment_expression | expression !':=' mark = self._mark() - if ( - (literal := self.expect('as')) - and - (star_target := self.star_target()) + if assignment_expression := self.assignment_expression(): + return assignment_expression + self._reset(mark) + if (expression := self.expression()) and ( + self.negative_lookahead(self.expect, ":=") ): - return [literal, star_target]; + return expression self._reset(mark) - return None; + return None @memoize - def _tmp_313(self) -> Optional[Any]: - # _tmp_313: 'as' star_target + def _loop0_340(self) -> Optional[Any]: + # _loop0_340: ',' (starred_expression | (assignment_expression | expression !':=') !'=') mark = self._mark() - if ( - (literal := self.expect('as')) - and - (star_target := self.star_target()) - ): - return [literal, star_target]; + children = [] + while (self.expect(",")) and (elem := self._tmp_345()): + children.append(elem) + mark = self._mark() self._reset(mark) - return None; + return children @memoize - def _tmp_314(self) -> Optional[Any]: - # _tmp_314: 'as' star_target + def _gather_339(self) -> Optional[Any]: + # _gather_339: (starred_expression | (assignment_expression | expression !':=') !'=') _loop0_340 mark = self._mark() - if ( - (literal := self.expect('as')) - and - (star_target := self.star_target()) - ): - return [literal, star_target]; + if (elem := self._tmp_345()) is not None and ( + seq := self._loop0_340() + ) is not None: + return [elem] + seq self._reset(mark) - return None; + return None - KEYWORDS = ('False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield') - SOFT_KEYWORDS = ('_', 'alias', 'attr', 'case', 'const', 'enamldef', 'event', 'func', 'match', 'pragma', 'template', 'type') + @memoize + def _tmp_341(self) -> Optional[Any]: + # _tmp_341: 'as' star_target + mark = self._mark() + if (literal := self.expect("as")) and (star_target := self.star_target()): + return [literal, star_target] + self._reset(mark) + return None + @memoize + def _tmp_342(self) -> Optional[Any]: + # _tmp_342: 'as' star_target + mark = self._mark() + if (literal := self.expect("as")) and (star_target := self.star_target()): + return [literal, star_target] + self._reset(mark) + return None -if __name__ == '__main__': + @memoize + def _tmp_343(self) -> Optional[Any]: + # _tmp_343: 'as' star_target + mark = self._mark() + if (literal := self.expect("as")) and (star_target := self.star_target()): + return [literal, star_target] + self._reset(mark) + return None + + @memoize + def _tmp_344(self) -> Optional[Any]: + # _tmp_344: 'as' star_target + mark = self._mark() + if (literal := self.expect("as")) and (star_target := self.star_target()): + return [literal, star_target] + self._reset(mark) + return None + + @memoize + def _tmp_345(self) -> Optional[Any]: + # _tmp_345: starred_expression | (assignment_expression | expression !':=') !'=' + mark = self._mark() + if starred_expression := self.starred_expression(): + return starred_expression + self._reset(mark) + if (_tmp_346 := self._tmp_346()) and ( + self.negative_lookahead(self.expect, "=") + ): + return _tmp_346 + self._reset(mark) + return None + + @memoize + def _tmp_346(self) -> Optional[Any]: + # _tmp_346: assignment_expression | expression !':=' + mark = self._mark() + if assignment_expression := self.assignment_expression(): + return assignment_expression + self._reset(mark) + if (expression := self.expression()) and ( + self.negative_lookahead(self.expect, ":=") + ): + return expression + self._reset(mark) + return None + + KEYWORDS = ( + "False", + "None", + "True", + "and", + "as", + "assert", + "async", + "await", + "break", + "class", + "continue", + "def", + "del", + "elif", + "else", + "except", + "finally", + "for", + "from", + "global", + "if", + "import", + "in", + "is", + "lambda", + "nonlocal", + "not", + "or", + "pass", + "raise", + "return", + "try", + "while", + "with", + "yield", + ) + SOFT_KEYWORDS = ( + "_", + "alias", + "attr", + "case", + "const", + "enamldef", + "event", + "func", + "lazy", + "match", + "pragma", + "template", + "type", + ) + + +if __name__ == "__main__": from pegen.parser import simple_parser_main + simple_parser_main(EnamlParser) diff --git a/enaml/core/parser/generate_enaml_parser.py b/enaml/core/parser/generate_enaml_parser.py index 080fd926b..2ca7654e6 100644 --- a/enaml/core/parser/generate_enaml_parser.py +++ b/enaml/core/parser/generate_enaml_parser.py @@ -6,6 +6,7 @@ # The full license is in the file LICENSE, distributed with this software. # -------------------------------------------------------------------------------------- """Script used to generate the Enaml parser from enaml.gram""" + import pathlib from pegen.build import build_python_parser_and_generator @@ -20,5 +21,6 @@ def main(): str(dir_path / "enaml.gram"), str(dir_path / "enaml_parser.py") ) + if __name__ == "__main__": main() diff --git a/enaml/src/callableref.cpp b/enaml/src/callableref.cpp index 7cf0d2bcf..39456c9cd 100644 --- a/enaml/src/callableref.cpp +++ b/enaml/src/callableref.cpp @@ -8,6 +8,7 @@ #include #include #include +#include "weakref_compat.h" #ifdef __clang__ #pragma clang diagnostic ignored "-Wdeprecated-writable-strings" @@ -98,7 +99,12 @@ PyObject* CallableRef_call( CallableRef* self, PyObject* args, PyObject* kwargs ) { cppy::ptr objrefptr( cppy::incref( self->objref ) ); - cppy::ptr objptr( cppy::incref( PyWeakref_GET_OBJECT( objrefptr.get() ) ) ); + PyObject* obj_raw = weakref_get_object( objrefptr.get() ); + if( !obj_raw ) + { + return nullptr; + } + cppy::ptr objptr( obj_raw ); if( objptr.is_none() ) { Py_RETURN_NONE; diff --git a/enaml/src/signaling.cpp b/enaml/src/signaling.cpp index fdd6a46a4..d84d0a89d 100644 --- a/enaml/src/signaling.cpp +++ b/enaml/src/signaling.cpp @@ -9,6 +9,7 @@ #include #include #include +#include "weakref_compat.h" #ifdef __clang__ @@ -398,7 +399,12 @@ _Disconnector_call( _Disconnector* self, PyObject* args, PyObject* kwargs ) } cppy::ptr objref( cppy::incref( self->objref ) ); - cppy::ptr obj( cppy::incref( PyWeakref_GET_OBJECT( objref.get() ) ) ); + PyObject* obj_raw = weakref_get_object( objref.get() ); + if( !obj_raw ) + { + return nullptr; + } + cppy::ptr obj( obj_raw ); if( obj.is_none() ) { Py_RETURN_NONE; @@ -633,7 +639,12 @@ PyObject* BoundSignal_emit( BoundSignal* self, PyObject* args, PyObject* kwargs ) { cppy::ptr objref( cppy::incref( self->objref ) ); - cppy::ptr obj( cppy::incref( PyWeakref_GET_OBJECT( objref.get() ) ) ); + PyObject* obj_raw = weakref_get_object( objref.get() ); + if( !obj_raw ) + { + return nullptr; + } + cppy::ptr obj( obj_raw ); if( obj.is_none() ) { Py_RETURN_NONE; @@ -720,7 +731,12 @@ PyObject* BoundSignal_connect( BoundSignal* self, PyObject* slot ) { cppy::ptr objref( cppy::incref( self->objref ) ); - cppy::ptr obj( cppy::incref( PyWeakref_GET_OBJECT( objref.get() ) ) ); + PyObject* obj_raw = weakref_get_object( objref.get() ); + if( !obj_raw ) + { + return nullptr; + } + cppy::ptr obj( obj_raw ); if( obj.is_none() ) { Py_RETURN_NONE; diff --git a/enaml/src/weakmethod.cpp b/enaml/src/weakmethod.cpp index 9760ad62d..adb120e64 100644 --- a/enaml/src/weakmethod.cpp +++ b/enaml/src/weakmethod.cpp @@ -9,6 +9,7 @@ #include #include #include // Included to access offsetof +#include "weakref_compat.h" namespace enaml @@ -222,7 +223,12 @@ PyObject* WeakMethod_call( WeakMethod* self, PyObject* args, PyObject* kwargs ) { cppy::ptr selfref( cppy::incref( self->selfref ) ); - cppy::ptr mself( cppy::incref( PyWeakref_GET_OBJECT( selfref.get() ) ) ); + PyObject* mself_raw = weakref_get_object( selfref.get() ); + if( !mself_raw ) + { + return nullptr; + } + cppy::ptr mself( mself_raw ); if( mself.is_none() ) { Py_RETURN_NONE; diff --git a/enaml/src/weakref_compat.h b/enaml/src/weakref_compat.h new file mode 100644 index 000000000..9af1e0c9a --- /dev/null +++ b/enaml/src/weakref_compat.h @@ -0,0 +1,55 @@ +/*----------------------------------------------------------------------------- +| Copyright (c) 2013-2025, Nucleic Development Team. +| +| Distributed under the terms of the Modified BSD License. +| +| The full license is in the file LICENSE, distributed with this software. +|----------------------------------------------------------------------------*/ + +#ifndef ENAML_WEAKREF_COMPAT_H +#define ENAML_WEAKREF_COMPAT_H + +#include + +#if PY_VERSION_HEX < 0x030D0000 +// Can be removed when Python < 3.13 is no longer supported. +static inline int PyWeakref_GetRef(PyObject *ref, PyObject **pobj) { + PyObject *obj = PyWeakref_GET_OBJECT(ref); + *pobj = obj; + Py_XINCREF(*pobj); + return 1; +} +#endif + +namespace enaml +{ + +inline PyObject* +weakref_get_object( PyObject* ref ) +{ + PyObject* obj = nullptr; +#if PY_VERSION_HEX >= 0x030D0000 + int result = PyWeakref_GetRef( ref, &obj ); + if( result < 0 ) + return nullptr; + if( result == 0 ) + { + Py_INCREF( Py_None ); + return Py_None; + } + return obj; +#else + obj = PyWeakref_GET_OBJECT( ref ); + if( obj == nullptr ) + { + Py_INCREF( Py_None ); + return Py_None; + } + Py_INCREF( obj ); + return obj; +#endif +} + +} // namespace enaml + +#endif // ENAML_WEAKREF_COMPAT_H diff --git a/pyproject.toml b/pyproject.toml index 73f45d291..5c8d06f1f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,12 +26,13 @@ classifiers = [ "Programming Language :: Python :: 3.12", "Programming Language :: Python :: 3.13", "Programming Language :: Python :: 3.14", + "Programming Language :: Python :: 3.15", "Programming Language :: Python :: Implementation :: CPython", ] dependencies = [ - "atom>=0.9.0", - "kiwisolver>=1.2.0", - "bytecode>=0.17.0", + "atom>=0.14.0", + "kiwisolver>=1.5.1", + "bytecode>=0.19.0", "pegen>=0.3.0", ] dynamic=["version"] diff --git a/tests/core/parser/__init__.py b/tests/core/parser/__init__.py index 4403542eb..a4fa9b976 100644 --- a/tests/core/parser/__init__.py +++ b/tests/core/parser/__init__.py @@ -1,7 +1,7 @@ -#------------------------------------------------------------------------------ +# ------------------------------------------------------------------------------ # Copyright (c) 2013-2025, Nucleic Development Team. # # Distributed under the terms of the Modified BSD License. # # The full license is in the file LICENSE, distributed with this software. -#------------------------------------------------------------------------------ +# ------------------------------------------------------------------------------ diff --git a/tests/core/parser/test_async.py b/tests/core/parser/test_async.py deleted file mode 100644 index e3fe696ee..000000000 --- a/tests/core/parser/test_async.py +++ /dev/null @@ -1,199 +0,0 @@ -#------------------------------------------------------------------------------ -# Copyright (c) 2018-2024, Nucleic Development Team. -# -# Distributed under the terms of the Modified BSD License. -# -# The full license is in the file LICENSE, distributed with this software. -#------------------------------------------------------------------------------ -import sys -import ast -from textwrap import dedent -import pytest - -from utils import compile_source -from enaml.core.parser import parse - -from .test_parser import validate_ast - -FUNC_TEMPLATE =\ -""" -import asyncio - -async def fetch(query): - return query - -{} -""" - -TEST_SOURCE = { - 'await': """ - async def function(queries): - r = await query() - return r - """, - 'await if': """ - async def function(query): - result = await fetch(query) - if not query: - return - return result - """, - 'if await': """ - async def function(query): - if not query: - return - result = await fetch(query) - return result - """, - 'await future': """ - async def function(query): - f = fetch(query) - await f - return result - """, - 'await subscript': """ - async def function(query): - tasks = [fetch(query)] - await tasks[0] - return result - """, - 'await attr': """ - async def function(query): - class API: - search = fetch - api = API() - await api.fetch(query) - return result - """, - 'await list comp': """ - async def function(queries): - result = [await fetch(q) for q in queries] - return result - """, - 'await dict comp': """ - async def function(queries): - result = {i:await fetch(q) for i, q in enumerate(queries)} - return result - """, - 'async for': """ - async def function(queries): - results = [] - async for r in fetch(queries): - results.append(r) - return result - """, - 'async for or': """ - async def function(queries): - results = [] - async for r in queries or fetch(queries): - results.append(r) - return result - """, - 'async for comp': """ - async def function(queries): - results = [] - async for r in [f for f in fetch(queries)]: - results.append(r) - return result - """, - 'async for or comp': """ - async def function(queries): - results = [] - async for r in queries or [f for f in fetch(queries)]: - results.append(r) - return result - """, - 'async with': """ - async def function(query): - lock = asyncio.lock() - async with lock: - result = await fetch(query) - return result - """, -} - -if sys.version_info >= (3, 6): - TEST_SOURCE.update({ - 'async for list comp': """ - async def function(queries): - result = [r async for r in fetch(q)] - return result - """, - 'async for if list comp': """ - async def function(queries): - result = [r async for r in fetch(queries) if r] - return result - """, - }) - -if sys.version_info < (3, 7): - TEST_SOURCE.update({ - 'async not keyword': """ - def function(queries): - async = False - return queries - """, - 'await not keyword': """ - def function(queries): - await = False - return queries - """, - }) - - -@pytest.mark.parametrize('desc', TEST_SOURCE.keys()) -def test_async(desc): - """Async function with await list comp statement. """ - src = FUNC_TEMPLATE.format(dedent(TEST_SOURCE[desc])) - # Ensure it's valid - py_ast = ast.parse(src) - enaml_ast = parse(src).body[0].ast - validate_ast(py_ast.body[0], enaml_ast.body[0], True) - validate_ast(py_ast.body[1], enaml_ast.body[1], True) - validate_ast(py_ast.body[2], enaml_ast.body[2], True) - - -def test_decl_async_func(): - py_src = dedent(""" - from enaml.core.declarative import d_func - from enaml.widgets.api import Window, Label - - async def fetch(query): - return query - - class MainWindow(Window): - @d_func - async def search(self, query): - result = await fetch(query) - return result - """) - - enaml_src = dedent(""" - from enaml.core.declarative import d_func - from enaml.widgets.api import Window, Label - - async def fetch(query): - return query - - enamldef MainWindow(Window): - async func search(query): - result = await fetch(query) - return result - - enamldef CustomWindow(MainWindow): - async search => (query): - result = await fetch(query) - return result - - """) - py_ast = ast.parse(py_src) - enaml_ast = parse(enaml_src) - validate_ast(py_ast.body[3].body[0], - enaml_ast.body[1].body[0].funcdef, True) - - # Check override syntax - validate_ast(py_ast.body[3].body[0], - enaml_ast.body[2].body[0].funcdef, True) - - # Make sure it compiles - CustomWindow = compile_source(enaml_src, 'CustomWindow') diff --git a/tests/core/parser/test_f_strings.py b/tests/core/parser/test_f_strings.py deleted file mode 100644 index 5dc0305fe..000000000 --- a/tests/core/parser/test_f_strings.py +++ /dev/null @@ -1,72 +0,0 @@ -# ------------------------------------------------------------------------------ -# Copyright (c) 2018-2024, Nucleic Development Team. -# -# Distributed under the terms of the Modified BSD License. -# -# The full license is in the file LICENSE, distributed with this software. -# ------------------------------------------------------------------------------ -import sys -import ast -import pytest - -from enaml.core.parser import parse - -from .test_parser import validate_ast - -TEST_SOURCE = { - "f-string single value": r""" - a = f'test {a:d}' - """, - "f-string multiple values": r""" - a = f'test {a:g}, {b}' - """, - "f-string split 1": r""" - a = (f'{r}' '{t:s}') - """, - "f-string split 2": r""" - a = ('{r}' f'{t:s}') - """, - "f-string raw string": r""" - a = rf'{a}\n' - """, - "f-string raw string 2": r""" - a = fr'{a}\n' - """, -} -for k, v in list(TEST_SOURCE.items()): - TEST_SOURCE[k.replace("f-", "F-")] = v.replace("f'", "F'") - if "rf'" in v: - TEST_SOURCE[k.replace("raw", "RAW")] = v.replace("rf'", "Rf'") - TEST_SOURCE[k.replace("f-", "F-").replace("raw", "RAW")] = v.replace( - "rf'", "RF'" - ) - if "fr'" in v: - TEST_SOURCE[k.replace("raw", "RAW")] = v.replace("fr'", "fR'") - TEST_SOURCE[k.replace("f-", "F-").replace("raw", "RAW")] = v.replace( - "fr'", "FR'" - ) - - -@pytest.mark.skipif(sys.version_info < (3, 6), reason="Requires Python 3.6") -@pytest.mark.parametrize("desc", TEST_SOURCE.keys()) -def test_f_strings(desc): - """Test that we produce valid ast for f-strings.""" - src = TEST_SOURCE[desc].strip() - print(src) - # Ensure it's valid - py_ast = ast.parse(src) - enaml_ast = parse(src).body[0].ast - validate_ast(py_ast.body[0], enaml_ast.body[0], True) - - -@pytest.mark.skipif( - (3, 12) < sys.version_info or sys.version_info < (3, 6), - reason="Requires Python 3.6", -) -@pytest.mark.parametrize("source", [("f'{\\}'"), ("('d'\nf'{\\}')")]) -def test_reporting_errors_f_strings(source): - """Test that we properly report error on f-string.""" - with pytest.raises(SyntaxError) as e: - parse(source) - - assert "backslash" in e.value.args[0] diff --git a/tests/core/parser/test_function_definitions.py b/tests/core/parser/test_function_definitions.py deleted file mode 100644 index 7f18319f0..000000000 --- a/tests/core/parser/test_function_definitions.py +++ /dev/null @@ -1,84 +0,0 @@ -#------------------------------------------------------------------------------ -# Copyright (c) 2018-2024, Nucleic Development Team. -# -# Distributed under the terms of the Modified BSD License. -# -# The full license is in the file LICENSE, distributed with this software. -#----------------------------------------------------------------------------- -import sys -import ast - -import pytest -from enaml.core.parser import parse - -from .test_parser import validate_ast - -FUNC_TEMPLATE =\ -"""def f({}): - pass -""" - - -POS_ARG_TEMP = ['a', - 'a=1', - 'a, b', - 'a, b=1', - 'a=1, b=2'] - - -SIGNATURES = POS_ARG_TEMP[:] -for suffix in (',', ', *args', ', **kwargs', ', *args, **kwargs'): - SIGNATURES.extend([s + suffix for s in POS_ARG_TEMP]) - -if sys.version_info[0] == 2: - tuple_unpacking = ['(a, b)', - '(a, b)=(1, 2)', - '(a, b), c', - '(a, b), c=3', - '(a, b)=(1, 2), c=3'] - for suffix in (',', ', *args', ', **kwargs', ', *args, **kwargs'): - SIGNATURES.extend([s + suffix for s in tuple_unpacking]) - -else: - pos = [''] + [s.replace('a', 'c').replace('b', 'd') + ', ' - for s in POS_ARG_TEMP] - kw_only = [star_arg + s - for s in POS_ARG_TEMP for star_arg in ('*, ', '*args, ')] - for kw in kw_only: - for suffix in ('', ', **kwargs'): - SIGNATURES.extend([p + kw + suffix for p in pos]) - - # annotated signatures - pos = [''] + [s.replace('a', 'a: int') for s in POS_ARG_TEMP] - no_kw_only = [',', ', *args', ', **kwargs', ', *args, **kwargs', - ', *args: int', ', **kwargs: int', - ', *args: int, **kwargs', ', *args, **kwargs: int', - ', *args: int, **kwargs: int'] - kw_only = [s.replace('b', 'b: int') for s in kw_only] - for kw in no_kw_only: - SIGNATURES.extend([p + kw for p in pos if p != '' and kw != ',']) - for kw in kw_only: - for s in ('', ', **kwargs', ', **kwargs: int'): - SIGNATURES.extend([p + ',' + kw + s if p else kw + s for p in pos]) - - -@pytest.mark.parametrize('signature', SIGNATURES) -def test_func_definition_parsing(signature): - """Test parsing all possible function signatures. - - """ - src = FUNC_TEMPLATE.format(signature) - py_ast = ast.parse(src).body[0] - enaml_ast = parse(src).body[0].ast.body[0] - validate_ast(py_ast, enaml_ast, True) - - -@pytest.mark.skipif(sys.version_info < (3,), reason='Requires Python 3') -def test_func_return_annotation_parsing(): - """Test that we parse properly functions with a return type annotation. - - """ - src = "def f() -> int:\n pass" - py_ast = ast.parse(src).body[0] - enaml_ast = parse(src).body[0].ast.body[0] - validate_ast(py_ast, enaml_ast, True) diff --git a/tests/core/parser/test_parser.py b/tests/core/parser/test_parser.py index 25687a61d..7adf3474d 100644 --- a/tests/core/parser/test_parser.py +++ b/tests/core/parser/test_parser.py @@ -1,10 +1,10 @@ -#------------------------------------------------------------------------------ +# ------------------------------------------------------------------------------ # Copyright (c) 2018-2024, Nucleic Development Team. # # Distributed under the terms of the Modified BSD License. # # The full license is in the file LICENSE, distributed with this software. -#------------------------------------------------------------------------------ +# ------------------------------------------------------------------------------ import os import sys import ast @@ -14,6 +14,10 @@ from textwrap import dedent +def _is_stdlib_ast(node): + return isinstance(node, ast.AST) and type(node).__module__ == "ast" + + def validate_ast(py_node, enaml_node, dump_ast=False, offset=0): """Validate each node of an ast against another ast. @@ -22,35 +26,34 @@ def validate_ast(py_node, enaml_node, dump_ast=False, offset=0): """ if dump_ast: - print('Python node:\n', ast.dump(py_node)) - print('Enaml node:\n', ast.dump(enaml_node)) + print("Python node:\n", ast.dump(py_node)) + print("Enaml node:\n", ast.dump(enaml_node)) assert type(py_node) == type(enaml_node) - if isinstance(py_node, ast.AST): + if _is_stdlib_ast(py_node): for name, field in ast.iter_fields(py_node): - if name == 'ctx': + if name == "ctx": assert type(field) == type(getattr(enaml_node, name)) else: field2 = getattr(enaml_node, name, None) - print(' '*offset, 'Validating:', name) - validate_ast(field, field2, offset=offset+1) + print(" " * offset, "Validating:", name) + validate_ast(field, field2, offset=offset + 1) elif isinstance(py_node, list): if len(py_node) != len(enaml_node): return False for i, n1 in enumerate(py_node): - print(' '*offset, 'Validating', i+1, 'th element') - validate_ast(n1, enaml_node[i], offset=offset+1) + print(" " * offset, "Validating", i + 1, "th element") + validate_ast(n1, enaml_node[i], offset=offset + 1) else: assert py_node == enaml_node def test_syntax_error_traceback_correct_path(tmpdir): - """ Test that a syntax error retains the path to the file + """Test that a syntax error retains the path to the file""" + test_module_path = os.path.join(tmpdir.strpath, "view.enaml") - """ - test_module_path = os.path.join(tmpdir.strpath, 'view.enaml') - - with open(os.path.join(tmpdir.strpath, 'test_main.enaml'), 'w') as f: - f.write(dedent(""" + with open(os.path.join(tmpdir.strpath, "test_main.enaml"), "w") as f: + f.write( + dedent(""" from enaml.widgets.api import Window, Container, Label from view import CustomView @@ -58,17 +61,20 @@ def test_syntax_error_traceback_correct_path(tmpdir): CustomView: pass - """)) + """) + ) - with open(test_module_path, 'w') as f: - f.write(dedent(""" + with open(test_module_path, "w") as f: + f.write( + dedent(""" from enaml.widgets.api import Container, Label enamldef CustomLabel(Container): Label # : missing intentionally text = "Hello world" - """)) + """) + ) try: sys.path.append(tmpdir.strpath) @@ -79,7 +85,7 @@ def test_syntax_error_traceback_correct_path(tmpdir): tb = traceback.format_exc() print(tb) lines = tb.strip().split("\n") - line = '\n'.join(lines[-4:]) + line = "\n".join(lines[-4:]) expected = 'File "{}", line 5'.format(test_module_path) assert expected in line finally: @@ -87,19 +93,19 @@ def test_syntax_error_traceback_correct_path(tmpdir): def test_syntax_error_traceback_show_line(tmpdir): - """ Test that a syntax error retains the path to the file + """Test that a syntax error retains the path to the file""" + test_module_path = os.path.join(tmpdir.strpath, "test_syntax.enaml") - """ - test_module_path = os.path.join(tmpdir.strpath, 'test_syntax.enaml') - - with open(test_module_path, 'w') as f: - f.write(dedent(""" + with open(test_module_path, "w") as f: + f.write( + dedent(""" from enaml.widgets.api import Container, Label enamldef CustomLabel(Container): Label # : missing intentionally text = "Hello world" - """)) + """) + ) try: sys.path.append(tmpdir.strpath) @@ -110,16 +116,16 @@ def test_syntax_error_traceback_show_line(tmpdir): tb = traceback.format_exc() print(tb) lines = tb.strip().split("\n") - line = '\n'.join(lines[-4:]) + line = "\n".join(lines[-4:]) - expected = 'Label # : missing intentionally' + expected = "Label # : missing intentionally" assert expected in line finally: sys.path.remove(tmpdir.strpath) INDENTATION_TESTS = { - "enamldef-block": ( + "enamldef-block": ( """ from enaml.widgets.api import Window, Container, Label @@ -161,7 +167,7 @@ def test_syntax_error_traceback_show_line(tmpdir): Label: text = 'Hello world' """, - "text = 'Hello world'" + "text = 'Hello world'", ), "if-block": ( """ @@ -186,7 +192,7 @@ def test_syntax_error_traceback_show_line(tmpdir): for i in range(4): x += 1 """, - "x += 1" + "x += 1", ), "try-block": ( """ @@ -198,7 +204,7 @@ def test_syntax_error_traceback_show_line(tmpdir): except Exception as e: print(e) """, - "x = 1/0" + "x = 1/0", ), "except-block": ( """ @@ -211,7 +217,7 @@ def test_syntax_error_traceback_show_line(tmpdir): except Exception as e: print(e) """, - "print(e)" + "print(e)", ), "finally-block": ( """ @@ -225,7 +231,7 @@ def test_syntax_error_traceback_show_line(tmpdir): x = 2 return 3 """, - "x = 2" + "x = 2", ), "class": ( """ @@ -240,14 +246,13 @@ def add(): ), } + @pytest.mark.parametrize("label", INDENTATION_TESTS.keys()) def test_indent_error_traceback_show_line(tmpdir, label): - """ Test that a syntax error retains the path to the file - - """ - test_module_path = os.path.join(tmpdir.strpath, f'test_indent_{label}.enaml') - source, expected= INDENTATION_TESTS[label] - with open(test_module_path, 'w') as f: + """Test that a syntax error retains the path to the file""" + test_module_path = os.path.join(tmpdir.strpath, f"test_indent_{label}.enaml") + source, expected = INDENTATION_TESTS[label] + with open(test_module_path, "w") as f: f.write(dedent(source.lstrip("\n"))) try: sys.path.append(tmpdir.strpath) @@ -258,7 +263,7 @@ def test_indent_error_traceback_show_line(tmpdir, label): tb = traceback.format_exc() print(tb) lines = tb.strip().split("\n") - line = '\n'.join(lines[-4:]) + line = "\n".join(lines[-4:]) assert expected in line finally: sys.path.remove(tmpdir.strpath) diff --git a/tests/core/parser/test_raise_stmt.py b/tests/core/parser/test_raise_stmt.py deleted file mode 100644 index de27249db..000000000 --- a/tests/core/parser/test_raise_stmt.py +++ /dev/null @@ -1,56 +0,0 @@ -#------------------------------------------------------------------------------ -# Copyright (c) 2019-2024, Nucleic Development Team. -# -# Distributed under the terms of the Modified BSD License. -# -# The full license is in the file LICENSE, distributed with this software. -#----------------------------------------------------------------------------- -import sys -import ast -from textwrap import dedent - -import pytest -from enaml.core.parser import parse - -from .test_parser import validate_ast - - -def test_raise_exception(): - """Test raising an exception. - - """ - src = """raise Exception()""" - py_ast = ast.parse(src).body[0] - enaml_ast = parse(src).body[0].ast.body[0] - validate_ast(py_ast, enaml_ast, True) - - -def test_reraise_exception(): - """Test raising an exception. - - """ - src = dedent(""" - try: - a = ""/0 - except: - raise - """) - py_ast = ast.parse(src).body[0] - enaml_ast = parse(src).body[0].ast.body[0] - validate_ast(py_ast, enaml_ast, True) - - -@pytest.mark.skipif(sys.version_info < (3,), reason='Requires Python 3') -def test_raise_exception_with_cause(): - """Test that we parse properly functions with a return type annotation. - - """ - src = dedent(""" - try: - a = ""/0 - except Exception as e: - raise Exception() from e - """) - py_ast = ast.parse(src).body[0] - enaml_ast = parse(src).body[0].ast.body[0] - validate_ast(py_ast, enaml_ast, True) diff --git a/tests/core/parser/test_return.py b/tests/core/parser/test_return.py deleted file mode 100644 index df3b6eeb8..000000000 --- a/tests/core/parser/test_return.py +++ /dev/null @@ -1,52 +0,0 @@ -#------------------------------------------------------------------------------ -# Copyright (c) 2020-2024, Nucleic Development Team. -# -# Distributed under the terms of the Modified BSD License. -# -# The full license is in the file LICENSE, distributed with this software. -#------------------------------------------------------------------------------ -import sys -import ast -from textwrap import dedent - -import pytest - -from enaml.core.parser import parse - -from .test_parser import validate_ast - -TEST_SOURCE = { - 'return': r""" - def f(): - return - """, - 'return a': r""" - def f(): - return a - """, - 'return a, (b, c)': r""" - def f(): - return a, (b, c) - """, -} - -TEST_SOURCE_38 = { - 'return a, *b': r""" - def f(): - return a, *b - """ -} - -@pytest.mark.parametrize('desc', - list(TEST_SOURCE) + list(TEST_SOURCE_38) if sys.version_info >= (3, 8) else [] -) -def test_return_stmt(desc): - """Test that we produce valid ast use of the := walrus operator. - - """ - src = dedent(TEST_SOURCE.get(desc, TEST_SOURCE_38.get(desc))).strip() - print(src) - # Ensure it's valid - py_ast = ast.parse(src) - enaml_ast = parse(src).body[0].ast - validate_ast(py_ast.body[0], enaml_ast.body[0], True) diff --git a/tests/core/parser/test_syntax_error_handling.py b/tests/core/parser/test_syntax_error_handling.py new file mode 100644 index 000000000..f007b5dbe --- /dev/null +++ b/tests/core/parser/test_syntax_error_handling.py @@ -0,0 +1,497 @@ +import ast +import sys + +import pytest + +from enaml.core.parser import parse + + +def parse_invalid_syntax(source, message, *, py_version=None, start=None, end=None): + with pytest.raises(SyntaxError) as exc: + parse(source, py_version=py_version) + + text = str(exc.value) + messages = (message,) if isinstance(message, str) else message + assert any(m.lower() in text.lower() for m in messages) + + if start is None: + return + + assert exc.value.lineno == start[0] + assert exc.value.offset == start[1] + if end is not None: + assert getattr(exc.value, "end_lineno", None) == end[0] + if end[1] is not None: + assert getattr(exc.value, "end_offset", None) == end[1] + + +@pytest.mark.parametrize( + "source, message", + [ + ("(a 1)", "invalid syntax"), + ("print 1", "Missing parentheses"), + ("a if b", "expected 'else'"), + ( + "f'{x!}'", + ( + "missing conversion", + "missing conversion character", + "invalid conversion character", + ), + ), + ("(a = 1)", "invalid syntax"), + ], +) +def test_invalid_python_syntax_is_rejected(source, message): + parse_invalid_syntax(source, message) + + +@pytest.mark.parametrize( + "source, message", + [ + ("x = f'{x!q}'", "invalid conversion"), + ( + "match x:\n case 0:\n pass\n case _ as y:\n pass", + "cannot use '_' as a target", + ), + ], +) +def test_version_sensitive_invalid_syntax_is_rejected(source, message): + parse_invalid_syntax(source, message) + + +@pytest.mark.skipif( + sys.version_info < (3, 15), reason="Lazy imports are only supported in Python 3.15+" +) +@pytest.mark.parametrize( + "source, message", + [ + ( + "from pkg lazy import name", + "use 'lazy from ... ' instead of 'from ... lazy import'", + ), + ("from pkg import name lazy", "invalid syntax"), + ], +) +def test_invalid_lazy_import_syntax_is_rejected(source, message): + parse_invalid_syntax(source, message) + + +@pytest.mark.skipif( + sys.version_info < (3, 9), reason="Python 3.8 diagnostic is subpar in this case." +) +@pytest.mark.parametrize( + "source, message, start, end", + [ + ( + "f'a = {}'", + ( + "valid expression required before '}'" + if sys.version_info >= (3, 12) + else "f-string: empty expression not allowed" + ), + (1, 8) if sys.version_info >= (3, 12) else None, + (1, 9) if sys.version_info >= (3, 12) else None, + ), + ( + "f'a = {=}'", + ( + "expression required before '='" + if sys.version_info >= (3, 11) + else "f-string: empty expression not allowed" + ), + (1, 8) if sys.version_info >= (3, 12) else None, + (1, 9) if sys.version_info >= (3, 12) else None, + ), + ( + "f'a = {!}'", + ( + "expression required before '!'" + if sys.version_info >= (3, 11) + else "f-string: empty expression not allowed" + ), + (1, 8) if sys.version_info >= (3, 12) else None, + (1, 9) if sys.version_info >= (3, 12) else None, + ), + ( + "f'a = {:}'", + ( + "expression required before ':'" + if sys.version_info >= (3, 11) + else "f-string: empty expression not allowed" + ), + (1, 8) if sys.version_info >= (3, 12) else None, + (1, 9) if sys.version_info >= (3, 12) else (1, 11), + ), + ( + "f'a = {a=d}'", + ( + "expecting '!', or ':', or '}'" + if sys.version_info >= (3, 12) + else "f-string: expecting '}'" + ), + (1, 10) if sys.version_info >= (3, 12) else None, + (1, 11) if sys.version_info >= (3, 12) else None, + ), + ( + "f'a = { 1 + }'", + ( + "f-string: expecting '=', or '!', or ':', or '}'" + if sys.version_info >= (3, 12) + else "f-string: invalid syntax" + ), + (1, 11) if sys.version_info >= (3, 12) else (1, 7), + (1, 12) if sys.version_info >= (3, 12) else (1, 8), + ), + ( + "(\n\t'b'\n\tf'a = { 1 + }'\n)", + ( + "f-string: expecting '=', or '!', or ':', or '}'" + if sys.version_info >= (3, 12) + else "f-string: invalid syntax" + ), + (3, 12) if sys.version_info >= (3, 12) else (3, 7), + (3, 13) if sys.version_info >= (3, 12) else (3, 8), + ), + ( + 'f"{x!z}"', + ( + "f-string: invalid conversion character 'z': expected 's', 'r', or 'a'" + if sys.version_info >= (3, 12) + else "f-string: invalid conversion character: expected 's', 'r', or 'a'" + ), + (1, 6) if sys.version_info >= (3, 12) else None, + (1, 7) if sys.version_info >= (3, 12) else None, + ), + ], +) +def test_syntax_error_in_str(source, message, start, end): + parse_invalid_syntax(source, message, start=start, end=end) + + +@pytest.mark.parametrize( + "source, message, start, end", + [ + ("(a 1)", "invalid syntax. Perhaps you forgot a comma?", (1, 2), (1, 5)), + ("2 if 4", "expected 'else' after 'if' expression", (1, 1), (1, 7)), + ("(a 1 if b else 2)", "invalid syntax. Perhaps you forgot a comma?", (1, 2), (1, 17)), + ("(a lambda: 1)", "invalid syntax. Perhaps you forgot a comma?", (1, 2), (1, 13)), + ("(a b)", "invalid syntax. Perhaps you forgot a comma?", (1, 2), (1, 5)), + ("print 1", "Missing parentheses in call to 'print'", (1, 1), (1, 8)), + ("exec 1", "Missing parentheses in call to 'exec'", (1, 1), (1, 7)), + ("a if b", "expected 'else' after 'if' expression", (1, 1), (1, 7)), + ("c = a if b:", "invalid syntax", (1, 11), (1, 12)), + ], +) +def test_invalid_expression(source, message, start, end): + parse_invalid_syntax(source, message, start=start, end=end) + + +@pytest.mark.parametrize( + "source, message, start, end", + [ + ("global a, 1", "invalid syntax", (1, 11), (1, 12)), + ("nonlocal a, 1", "invalid syntax", (1, 13), (1, 14)), + ("yield raise", "invalid syntax", (1, 7), (1, 12)), + ("assert raise", "invalid syntax", (1, 8), (1, 13)), + ("return def", "invalid syntax", (1, 8), (1, 11)), + ("raise def", "invalid syntax", (1, 7), (1, 10)), + ("del raise", "invalid syntax", (1, 5), (1, 10)), + ("if raise:\n\tpass", "invalid syntax", (1, 4), (1, 9)), + ("@raise\ndef f():\n\tpass", "invalid syntax", (1, 2), (1, 7)), + ("a: int = raise", "invalid syntax", (1, 10), (1, 15)), + ], +) +def test_invalid_statements(source, message, start, end): + parse_invalid_syntax(source, message, start=start, end=end) + + +@pytest.mark.parametrize( + "source, message, start, end", + [ + ("f(**a, *b)", "iterable argument unpacking follows keyword argument unpacking", (1, 6) if sys.version_info >= (3, 12) else None, (1, 10) if sys.version_info >= (3, 12) else None), + ("f(a for a in b, c)", "Generator expression must be parenthesized", (1, 3), (1, None)), + ("f(a for a in b if a, c)", "Generator expression must be parenthesized", (1, 3), (1, None)), + ("f(a for a in b, c for c in d)", "Generator expression must be parenthesized", (1, 3), (1, None)), + ("f(a=1 for i in range(10))", "invalid syntax. Maybe you meant '==' or ':=' instead of '='?", (1, 3), (1, 5)), + ("f(a, b for b in c)", "Generator expression must be parenthesized", (1, 6), (1, None)), + ("f(a, b for b in c, d)", "Generator expression must be parenthesized", (1, 6), (1, None)), + ("f(*a=b)", "cannot assign to iterable argument unpacking", (1, 3), (1, 7)), + ("f(**a, b)", "positional argument follows keyword argument unpacking", (1, 9), (1, 10)), + ("f(a=1, b)", "positional argument follows keyword argument", (1, 9), (1, 10)), + ("f(b=c for c in d)", "invalid syntax. Maybe you meant '==' or ':=' instead of '='?", (1, 3), (1, 5)), + ("f(1 + b=2)", 'expression cannot contain assignment, perhaps you meant "=="?', (1, 3), (1, 9)), + ("f(True=1)", "cannot assign to True", (1, 3), (1, 8)), + ("f(False=1)", "cannot assign to False", (1, 3), (1, 9)), + ("f(None=1)", "cannot assign to None", (1, 3), (1, 8)), + ], +) +def test_invalid_call_arguments(source, message, start, end): + parse_invalid_syntax(source, message, start=start, end=end) + + +@pytest.mark.parametrize( + "source, message, start, end", + [ + ("'a' = 1", "cannot assign to literal", (1, 1), (1, 4)), + ("1 = 1", "cannot assign to literal", (1, 1), (1, 2)), + ("True = 1", "cannot assign to True", (1, 1), (1, 5)), + ("False = 1", "cannot assign to False", (1, 1), (1, 6)), + ("... = 1", "cannot assign to ellipsis", (1, 1), (1, 4)), + ("None = 1", "cannot assign to None", (1, 1), (1, 5)), + ("(a, b) : int = (1, 2)", "only single target (not tuple) can be annotated", (1, 1), (1, 7)), + ("[a, b] : int = [1, 2]", "only single target (not list) can be annotated", (1, 1), (1, 7)), + ("([a, b]) : int = (1, 2)", "only single target (not list) can be annotated", (1, 2), (1, 8)), + ("a, b: int, int = 1, 2", "only single target (not tuple) can be annotated", (1, 1), (1, 2)), + ("{a, b} : set", "illegal target for annotation", (1, 1), (1, 7)), + ("a + 1 = 2", "cannot assign to expression", (1, 1), (1, 6)), + ("[i for i in range(2)] = 2", "cannot assign to list comprehension", (1, 1), (1, 22)), + ("yield a = 1", "assignment to yield expression not possible", (1, 1), (1, 8)), + ("a = yield b = 1", "assignment to yield expression not possible", (1, 5), (1, 12)), + ("a + 1 += 1", "'expression' is an illegal expression for augmented assignment", (1, 1), (1, 6)), + ("a + 1 += yield", "'expression' is an illegal expression for augmented assignment", (1, 1), (1, 6)), + ("[i for i in range(2)] += 1", "'list comprehension' is an illegal expression for augmented assignment", (1, 1), (1, 22)), + ("a += raise", "invalid syntax", (1, 6), (1, 11)), + ], +) +def test_invalid_assignments(source, message, start, end): + parse_invalid_syntax(source, message, start=start, end=end) + + +@pytest.mark.parametrize( + "source, message, start, end", + [ + ("del [i for i in range(2)]", "cannot delete list comprehension", (1, 5), (1, 26)), + ("del a + 1", "cannot delete expression", (1, 5), (1, 10)), + ], +) +def test_invalid_del_statements(source, message, start, end): + parse_invalid_syntax(source, message, start=start, end=end) + + +@pytest.mark.parametrize( + "source, message, start, end", + [ + ("(*a for a in enumerate(range(5)))", "iterable unpacking cannot be used in comprehension", (1, 2), (1, 4)), + ("[*a for a in enumerate(range(5))]", "iterable unpacking cannot be used in comprehension", (1, 2), (1, 4)), + ("{*a for a in enumerate(range(5))}", "iterable unpacking cannot be used in comprehension", (1, 2), (1, 4)), + ("[a, a for a in range(5)]", "did you forget parentheses around the comprehension target?", (1, 2), (1, 6)), + ("[a, for a in range(5)]", "did you forget parentheses around the comprehension target?", (1, 2), (1, 4)), + ("{**a for a in [{1: 2}]}", "dict unpacking cannot be used in dict comprehension", (1, 2), (1, 4)), + ("(a for a in raise)", "invalid syntax", (1, 13), (1, 18)), + ("(a async for a in raise)", "invalid syntax", (1, 19), (1, 24)), + ], +) +def test_invalid_comprehension(source, message, start, end): + parse_invalid_syntax(source, message, start=start, end=end) + + +@pytest.mark.parametrize( + "source, message, start, end, py_version", + [ + ("def f(a=1, b):\n\tpass", "parameter without a default follows parameter with a default", (1, 12), (1, 13), (3, 12)), + ("def f(a=1, /, b):\n\tpass", "parameter without a default follows parameter with a default", (1, 15), (1, 16), (3, 12)), + ("def f(x, (y, z), w):\n\tpass", "parameters cannot be parenthesized", (1, 10), (1, 16), (3, 11)), + ("def f((x, y, z, w)):\n\tpass", "parameters cannot be parenthesized", (1, 7), (1, 19), (3, 11)), + ("def f(x, (y, z, w)):\n\tpass", "parameters cannot be parenthesized", (1, 10), (1, 19), (3, 11)), + ("def f((x, y, z), w):\n\tpass", "parameters cannot be parenthesized", (1, 7), (1, 16), (3, 11)), + ("def foo(/,a,b=,c):\n\tpass", "at least one argument must precede /", (1, 9), (1, 10), (3, 11)), + ("def foo(a,/,/,b,c):\n\tpass", "/ may appear only once", (1, 13), (1, 14), (3, 11)), + ("def foo(a,/,a1,/,b,c):\n\tpass", "/ may appear only once", (1, 16), (1, 17), (3, 11)), + ("def foo(a=1,/,/,*b,/,c):\n\tpass", "/ may appear only once", (1, 15), (1, 16), (3, 11)), + ("def foo(a,/,a1=1,/,b,c):\n\tpass", "/ may appear only once", (1, 18), (1, 19), (3, 11)), + ("def foo(a,*b,c,/,d,e):\n\tpass", "/ must be ahead of *", (1, 16), (1, 17), (3, 11)), + ("def foo(a=1,*b,c=3,/,d,e):\n\tpass", "/ must be ahead of *", (1, 20), (1, 21), (3, 11)), + ("def foo(a,*b=3,c):\n\tpass", "var-positional argument cannot have default value", (1, 13), (1, 14), (3, 11)), + ("def foo(a,*b: int=,c):\n\tpass", "var-positional argument cannot have default value", (1, 18), (1, 19), (3, 11)), + ("def foo(a,**b=3):\n\tpass", "var-keyword argument cannot have default value", (1, 14), (1, 15), (3, 11)), + ("def foo(a,**b: int=3):\n\tpass", "var-keyword argument cannot have default value", (1, 19), (1, 20), (3, 11)), + ("def foo(a,*a, b, **c, d):\n\tpass", "arguments cannot follow var-keyword argument", (1, 23), (1, 24), (3, 11)), + ("def foo(a,*a, b, **c, d=4):\n\tpass", "arguments cannot follow var-keyword argument", (1, 23), (1, 24), (3, 11)), + ("def foo(a,*a, b, **c, *d):\n\tpass", "arguments cannot follow var-keyword argument", (1, 23), (1, 24), (3, 11)), + ("def foo(a,*a, b, **c, **d):\n\tpass", "arguments cannot follow var-keyword argument", (1, 23), (1, 25), (3, 11)), + ("def foo(a=1,/,**b,/,c):\n\tpass", "arguments cannot follow var-keyword argument", (1, 19), (1, 20), (3, 11)), + ("def foo(*b,*d):\n\tpass", "* argument may appear only once", (1, 12), (1, 13), (3, 11)), + ("def foo(a,*b,c,*d,*e,c):\n\tpass", "* argument may appear only once", (1, 16), (1, 17), (3, 11)), + ("def foo(a,b,/,c,*b,c,*d,*e,c):\n\tpass", "* argument may appear only once", (1, 22), (1, 23), (3, 11)), + ("def foo(a,b,/,c,*b,c,*d,**e):\n\tpass", "* argument may appear only once", (1, 22), (1, 23), (3, 11)), + ("def foo(a=1,/*,b,c):\n\tpass", "expected comma between / and *", (1, 14), (1, 15), (3, 11)), + ("def foo(a=1,d=,c):\n\tpasss", "expected default value expression", (1, 14), (1, 15), (3, 11)), + ("def foo(a,d=,c):\n\tpass", "expected default value expression", (1, 12), (1, 13), (3, 11)), + ("def foo(a,d: int=,c):\n\tpass", "expected default value expression", (1, 17), (1, 18), (3, 11)), + ("lambda x=1, y: x", "parameter without a default follows parameter with a default", (1, 13), (1, 14), (3, 12)), + ("lambda x=1, /, y: x", "parameter without a default follows parameter with a default", (1, 16), (1, 17), (3, 12)), + ("lambda x, (y, z), w: None", "parameters cannot be parenthesized", (1, 11), (1, 17), (3, 11)), + ("lambda (x, y, z, w): None", "parameters cannot be parenthesized", (1, 8), (1, 20), (3, 11)), + ("lambda x, (y, z, w): None", "parameters cannot be parenthesized", (1, 11), (1, 20), (3, 11)), + ("lambda (x, y, z), w: None", "parameters cannot be parenthesized", (1, 8), (1, 17), (3, 11)), + ("lambda /,a,b,c: None", "at least one argument must precede /", (1, 8), (1, 9), (3, 11)), + ("lambda a,/,/,b,c: None", "/ may appear only once", (1, 12), (1, 13), (3, 11)), + ("lambda a,/,a1,/,b,c: None", "/ may appear only once", (1, 15), (1, 16), (3, 11)), + ("lambda a=1,/,/,*b,/,c: None", "/ may appear only once", (1, 14), (1, 15), (3, 11)), + ("lambda a,/,a1=1,/,b,c: None", "/ may appear only once", (1, 17), (1, 18), (3, 11)), + ("lambda a,*b,c,/,d,e: None", "/ must be ahead of *", (1, 15), (1, 16), (3, 11)), + ("lambda a=1,*b,c=3,/,d,e: None", "/ must be ahead of *", (1, 19), (1, 20), (3, 11)), + ("lambda a=1,/*,b,c: None", "expected comma between / and *", (1, 13), (1, 14), (3, 11)), + ("lambda a,*b=3,c: None", "var-positional argument cannot have default value", (1, 12), (1, 13), (3, 11)), + ("lambda a,**b=3: None", "var-keyword argument cannot have default value", (1, 13), (1, 14), (3, 11)), + ("lambda a, *a, b, **c, d: None", "arguments cannot follow var-keyword argument", (1, 23), (1, 24), (3, 11)), + ("lambda a,*a, b, **c, d=4: None", "arguments cannot follow var-keyword argument", (1, 22), (1, 23), (3, 11)), + ("lambda a,*a, b, **c, *d: None", "arguments cannot follow var-keyword argument", (1, 22), (1, 23), (3, 11)), + ("lambda a,*a, b, **c, **d: None", "arguments cannot follow var-keyword argument", (1, 22), (1, 24), (3, 11)), + ("lambda a=1,/,**b,/,c: None", "arguments cannot follow var-keyword argument", (1, 18), (1, 19), (3, 11)), + ("lambda *b,*d: None", "* argument may appear only once", (1, 11), (1, 12), (3, 11)), + ("lambda a,*b,c,*d,*e,c: None", "* argument may appear only once", (1, 15), (1, 16), (3, 11)), + ("lambda a,b,/,c,*b,c,*d,*e,c: None", "* argument may appear only once", (1, 21), (1, 22), (3, 11)), + ("lambda a,b,/,c,*b,c,*d,**e: None", "* argument may appear only once", (1, 21), (1, 22), (3, 11)), + ("lambda a=1,d=,c: None", "expected default value expression", (1, 13), (1, 14), (3, 11)), + ("lambda a,d=,c: None", "expected default value expression", (1, 11), (1, 12), (3, 11)), + ], +) +def test_invalid_parameters(source, message, start, end, py_version): + parse_invalid_syntax(source, message, py_version=py_version, start=start, end=end) + + +@pytest.mark.parametrize( + "source, start, end", + [ + ("def f(a, *):\n\tpass", (1, 10), (1, 11)), + ("def f(a, *,):\n\tpass", (1, 10), (1, 11)), + ("def f(a, *, **):\n\tpass", (1, 10), (1, 11)), + ("lambda a, *: a", (1, 12), (1, 13)), + ("lambda a, *, **:a", (1, 14), (1, 16)), + ], +) +def test_invalid_star_etc(source, start, end): + parse_invalid_syntax(source, "named arguments must follow bare *", start=start, end=end) + + +@pytest.mark.parametrize( + "source, message, start, end", + [ + ("with open(a) as {b: 1}:\n\tpass", "cannot assign to dict", (1, 17), (1, 23)), + ("with open(a) as {b}:\n\tpass", "cannot assign to set", (1, 17), (1, 20)), + ("with open(a) as 1:\n\tpass", "cannot assign to literal", (1, 17), (1, 18)), + ], +) +def test_invalid_with_item(source, message, start, end): + parse_invalid_syntax(source, message, start=start, end=end) + + +@pytest.mark.parametrize( + "source, message, start, end", + [ + ("for {a} in [[1]]:\n\tpass", "cannot assign to set display", (1, 5), (1, 8)), + ("async for (a := i)", "cannot assign to named expression", (1, 12), (1, 18)), + ], +) +def test_invalid_for_target(source, message, start, end): + parse_invalid_syntax(source, message, start=start, end=end) + + +@pytest.mark.parametrize( + "source, message, start, end", + [ + ("a = (1+1 := 2)", "cannot use assignment expressions with expression", (1, 6), (1, 9)), + ("a := raise", "invalid syntax", (1, 3), (1, 5)), + ], +) +def test_named_expression(source, message, start, end): + parse_invalid_syntax(source, message, start=start, end=end) + + +@pytest.mark.parametrize( + "source, message, start, end", + [ + ("a = (*b)", "cannot use starred expression here", (1, 6), (1, 8)), + ("a = (**b)", "cannot use double starred expression here", (1, 6), (1, 8)), + ], +) +def test_invalid_group(source, message, start, end): + parse_invalid_syntax(source, message, start=start, end=end) + + +@pytest.mark.parametrize( + "source, message, start, end", + [ + ("from a import b,", "trailing comma not allowed without surrounding parentheses", (1, 17), (1, 18) if sys.version_info >= (3, 12) else (1, 17)), + ("from a import b, and 3", "invalid syntax", (1, 18), (1, 21)), + ("from a import raise", "invalid syntax", (1, 15), (1, 20)), + ], +) +def test_invalid_import_from_as_names(source, message, start, end): + parse_invalid_syntax(source, message, start=start, end=end) + + +@pytest.mark.parametrize( + "source, message, start, end", + [ + ("with open(a) as f, b as d:\npass", "expected an indented block after 'with' statement on line 1", (2, 1), (2, 5)), + ("with open(a) as f, b as d\npass", "expected ':'", (1, 26), (1, 27) if sys.version_info >= (3, 12) else (1, 26)), + ], +) +def test_invalid_with_statements(source, message, start, end): + parse_invalid_syntax(source, message, start=start, end=end) + + +@pytest.mark.skipif(sys.version_info < (3, 14), reason="T-strings are only supported in Python 3.14+") +@pytest.mark.parametrize( + "source, message, start, end", + [ + ('t"{x!}"', "t-string: missing conversion character", (1, 6), (1, 7)), + ('t"{x!z}"', "invalid conversion character 'z': expected 's', 'r', or 'a'", (1, 6), (1, 7)), + ('t"{x:{y}"', "expecting '}', or format specs", (1, 9), (1, 10)), + ], +) +def test_invalid_tstring_replacement_field(source, message, start, end): + parse_invalid_syntax(source, message, start=start, end=end) + + +@pytest.mark.skipif( + sys.version_info < (3, 15), reason="Lazy imports are only supported in Python 3.15+" +) +@pytest.mark.parametrize( + "source, message", + [ + ("from pkg lazy import name", "use 'lazy from ... ' instead of 'from ... lazy import'"), + ("from pkg import name lazy", "invalid syntax"), + ], +) +def test_invalid_lazy_import_syntax(source, message): + parse_invalid_syntax(source, message) + + +@pytest.mark.parametrize( + "source, message", + [ + ("x = f'{x!q}'", "invalid conversion"), + ( + "match x:\n case 0:\n pass\n case _ as y:\n pass", + "cannot use '_' as a target", + ), + ], +) +def test_version_sensitive_invalid_syntax_is_rejected_2(source, message): + parse_invalid_syntax(source, message) + + +@pytest.mark.parametrize( + "source, message", + [ + ("\nasync with (open(a) as f, b as d):\npass", "expected an indented block after 'with' statement on line 2"), + ("\nasync with (open(a) as f, b as d)\npass", "expected ':'"), + ], +) +def test_async_with_syntax_errors(source, message): + parse_invalid_syntax(source, message) + + +@pytest.mark.parametrize( + "source, message, py_version", + [ + ("try:\n a = 1\nexcept *ValueError:\n pass", "Exception groups are", (3, 10)), + ("match a:\n case 1:\n pass", "Pattern matching is", (3, 9)), + ], +) +def test_version_guarded_syntax(source, message, py_version): + parse_invalid_syntax(source, message, py_version=py_version) diff --git a/tests/core/parser/test_unsupported_syntax.py b/tests/core/parser/test_unsupported_syntax.py new file mode 100644 index 000000000..a35b50628 --- /dev/null +++ b/tests/core/parser/test_unsupported_syntax.py @@ -0,0 +1,160 @@ +import io +import tokenize + +import pytest + +from enaml.core.parser import parse + + +@pytest.mark.parametrize("source", ["a @ b", "a @= b"]) +def test_matrix_multiplication_requires_python_35(source): + with pytest.raises(SyntaxError) as exc: + parse(source, py_version=(3, 4)) + + assert "The '@' operator is" in str(exc.value) + + +@pytest.mark.parametrize("source", ["await b", "async def f():\n pass"]) +def test_await_and_async_require_python_35(source): + with pytest.raises(SyntaxError) as exc: + parse(source, py_version=(3, 4)) + + assert "Await expressions are" in str(exc.value) or "Async functions are" in str(exc.value) + + +@pytest.mark.parametrize( + "source, message", + [ + ("async def f():\n pass", "Async functions are"), + ("async with a:\n pass", "Async with statements are"), + ("async for a in b:\n pass", "Async for loops are"), + ], +) +def test_async_requires_python_35(source, message): + with pytest.raises(SyntaxError) as exc: + parse(source, py_version=(3, 4)) + + assert message in str(exc.value) + + +@pytest.mark.parametrize("source", ["[a async for a in b if c]"]) +def test_async_comprehension_requires_python_36(source): + with pytest.raises(SyntaxError) as exc: + parse(source, py_version=(3, 5)) + + assert "Async comprehensions are" in str(exc.value) + + +@pytest.mark.parametrize("source", ["a: int = 1", "(a): int "]) +def test_variable_annotation_requires_python_36(source): + with pytest.raises(SyntaxError) as exc: + parse(source, py_version=(3, 5)) + + assert "Variable annotation syntax is" in str(exc.value) + + +@pytest.mark.parametrize("source", ["def f(a,/):\n\tpass", "def f(a=1,/):\n\tpass"]) +def test_pos_only_args_require_python_38(source): + with pytest.raises(SyntaxError) as exc: + parse(source, py_version=(3, 7)) + + assert "Positional only arguments are" in str(exc.value) + + +@pytest.mark.parametrize("source", ["a := 1"]) +def test_assignment_operator_requires_python_38(source): + with pytest.raises(SyntaxError) as exc: + parse(source, py_version=(3, 7)) + + assert "The ':=' operator is" in str(exc.value) + + +@pytest.mark.parametrize("source", ["@f[1]\ndef f():\n\tpass"]) +def test_generic_decorators_require_python_39(source): + with pytest.raises(SyntaxError) as exc: + parse(source, py_version=(3, 8)) + + assert "Generic decorator are" in str(exc.value) + + +@pytest.mark.parametrize("source", ["with (a, b):\n\tpass"]) +def test_parenthesized_with_items_require_python_39(source): + with pytest.raises(SyntaxError) as exc: + parse(source, py_version=(3, 8)) + + assert "Parenthesized with items" in str(exc.value) + + +@pytest.mark.parametrize( + "source", + ["match a:\n\tcase 1:\n\t\tpass", "match a", "match a:\ncase b"], +) +def test_match_requires_python_310(source): + with pytest.raises(SyntaxError) as exc: + parse(source, py_version=(3, 9)) + + assert "Pattern matching is" in str(exc.value) + + +@pytest.mark.parametrize("source", ["try:\n\ta = 1\nexcept *ValueError:\n\tpass"]) +def test_except_star_requires_python_311(source): + with pytest.raises(SyntaxError) as exc: + parse(source, py_version=(3, 10)) + + assert "Exception groups are" in str(exc.value) + + +@pytest.mark.parametrize("source", ["type T = int", "type T[U] = tuple[U]"]) +def test_type_statement_requires_python_312(source): + with pytest.raises(SyntaxError) as exc: + parse(source, py_version=(3, 11)) + + assert "Type statement is" in str(exc.value) or "Type parameter lists are" in str(exc.value) + + +@pytest.mark.parametrize("source", ["def f[T]():\n\tpass", "async def f[T]():\n\tpass"]) +def test_generic_function_statement_requires_python_312(source): + with pytest.raises(SyntaxError) as exc: + parse(source, py_version=(3, 11)) + + assert "Type parameter lists are" in str(exc.value) + + +@pytest.mark.parametrize("source", ["class A[T]:\n\tpass"]) +def test_generic_class_statement_requires_python_312(source): + with pytest.raises(SyntaxError) as exc: + parse(source, py_version=(3, 11)) + + assert "Type parameter lists are" in str(exc.value) + + +@pytest.mark.parametrize("source", ["try:\n\tpass\nexcept ValueError, IndexError:\n\tpass"]) +def test_unparenthesized_except_requires_python_314(source): + with pytest.raises(SyntaxError) as exc: + parse(source, py_version=(3, 13)) + + assert "multiple exception types must be parenthesized" in str(exc.value) + + +@pytest.mark.parametrize( + "source, message", + [ + ("[*a for a in b]", "iterable unpacking cannot be used in comprehension"), + ("{*a for a in b}", "iterable unpacking cannot be used in comprehension"), + ("(*a for a in b)", "iterable unpacking cannot be used in comprehension"), + ("{**a for a in b}", "dict unpacking cannot be used in dict comprehension"), + ], +) +def test_comprehension_unpacking_requires_python_315(source, message): + with pytest.raises(SyntaxError) as exc: + parse(source, py_version=(3, 14)) + + assert message in str(exc.value) + + +@pytest.mark.parametrize("source", ["lazy import foo", "lazy import foo as bar", "lazy from pkg import name"]) +def test_lazy_import_requires_python_315(source): + with pytest.raises(SyntaxError) as exc: + parse(source, py_version=(3, 14)) + + assert "Lazy imports are" in str(exc.value) or "use 'lazy from ... ' instead of 'from ... lazy import'" in str(exc.value) diff --git a/tests/core/parser/test_valid_files.py b/tests/core/parser/test_valid_files.py new file mode 100644 index 000000000..3bc6bd06d --- /dev/null +++ b/tests/core/parser/test_valid_files.py @@ -0,0 +1,146 @@ +import ast +import sys +from pathlib import Path + +import pytest + +from enaml.core.enaml_compiler import EnamlCompiler +from enaml.core.parser import parse + +VALID_DIR = Path(__file__).resolve().parent / "valid" / "enaml" +PYTHON_VALID_DIR = Path(__file__).resolve().parent / "valid" / "python" + + +def _is_stdlib_ast(node): + """Return True for stdlib AST nodes, excluding Enaml wrapper nodes.""" + return isinstance(node, ast.AST) and type(node).__module__ == "ast" + + +def _dump_node(node, *, seen=None, include_attributes=True): + """Return a stable structural representation for AST-like objects.""" + if seen is None: + seen = set() + + if node is None: + return "None" + if _is_stdlib_ast(node): + return ast.dump(node, include_attributes=include_attributes) + if isinstance(node, list): + return ( + "[" + + ", ".join( + _dump_node(value, seen=seen, include_attributes=include_attributes) + for value in node + ) + + "]" + ) + if isinstance(node, tuple): + inner = ", ".join( + _dump_node(value, seen=seen, include_attributes=include_attributes) + for value in node + ) + return "(" + inner + (")" if len(node) != 1 else ",)") + if isinstance(node, dict): + items = [ + f"{key!r}: {_dump_node(value, seen=seen, include_attributes=include_attributes)}" + for key, value in node.items() + ] + return "{" + ", ".join(items) + "}" + if isinstance(node, str): + return repr(node) + if isinstance(node, (int, float, bool)): + return repr(node) + if hasattr(node, "_fields"): + node_id = id(node) + if node_id in seen: + return f"" + seen.add(node_id) + try: + fields = [ + f"{field}={_dump_node(getattr(node, field), seen=seen, include_attributes=include_attributes)}" + for field in getattr(node, "_fields", ()) + ] + return f"{type(node).__name__}({', '.join(fields)})" + finally: + seen.remove(node_id) + return repr(node) + + +def _unwrap_python_ast(node): + """Return the underlying Python AST while ignoring Enaml-wrapper nodes.""" + seen = set() + while node is not None and id(node) not in seen: + seen.add(id(node)) + if _is_stdlib_ast(node): + return node + if hasattr(node, "ast") and getattr(node, "ast") is not None: + node = getattr(node, "ast") + continue + body = getattr(node, "body", None) + if isinstance(body, list): + for item in body: + if hasattr(item, "ast") and getattr(item, "ast") is not None: + node = item + break + else: + return node + continue + return node + return node + + +def _iter_python_snippets(): + if not PYTHON_VALID_DIR.exists(): + return [] + + items = [] + for path in sorted( + PYTHON_VALID_DIR.rglob("*.py"), + key=lambda path: str(path.relative_to(PYTHON_VALID_DIR)), + ): + items.append(path) + return items + + +def _iter_enaml_fixtures(): + if not VALID_DIR.exists(): + return [] + return sorted( + VALID_DIR.rglob("*.enaml"), key=lambda path: str(path.relative_to(VALID_DIR)) + ) + + +def _should_skip_python_fixture(path): + stem = path.stem.lower() + if sys.version_info < (3, 14) and "tstring" in stem: + return True + if sys.version_info < (3, 15) and "lazy_import" in stem: + return True + return False + + +@pytest.mark.parametrize("path", _iter_python_snippets()) +def test_valid_python_fixtures_match_stdlib_ast(path): + if _should_skip_python_fixture(path): + pytest.skip("t-strings require Python 3.14+") + + source = path.read_text(encoding="utf-8") + parsed = _unwrap_python_ast(parse(source)) + python_ast = ast.parse(source) + + assert _dump_node(parsed, include_attributes=True) == _dump_node( + python_ast, include_attributes=True + ) + + + +@pytest.mark.parametrize( + "path", _iter_enaml_fixtures(), ids=lambda path: str(path.relative_to(VALID_DIR)) +) +def test_valid_enaml_fixtures_parse_without_error(path): + source = path.read_text(encoding="utf-8") + module = parse(source) + + assert hasattr(module, "body") + assert isinstance(module.body, list) + EnamlCompiler.compile(module, str(path)) diff --git a/tests/core/parser/test_walrus.py b/tests/core/parser/test_walrus.py deleted file mode 100644 index 69a55fc11..000000000 --- a/tests/core/parser/test_walrus.py +++ /dev/null @@ -1,82 +0,0 @@ -#------------------------------------------------------------------------------ -# Copyright (c) 2020-2024, Nucleic Development Team. -# -# Distributed under the terms of the Modified BSD License. -# -# The full license is in the file LICENSE, distributed with this software. -#------------------------------------------------------------------------------ -import sys -import ast -from textwrap import dedent - -import pytest - -from enaml.core.parser import parse - -from .test_parser import validate_ast - -TEST_SOURCE = { - ':= in expr': r""" - a = (b := 1) - """, - ':= in tuple': r""" - a = (2, b := 1) - """, - ':= in list': r""" - a = [2, b := 1] - """, - ':= in if': r""" - if b := 1: - pass - """, - ':= in elif': r""" - a = 0 - if a: - pass - elif b := 1: - pass - """, - ':= in while': r""" - while b := 1: - pass - """, - ':= in function argument': r""" - f(a, b := c or None) - """ -} - - -@pytest.mark.skipif(sys.version_info < (3, 8), reason='Requires Python 3.8') -@pytest.mark.parametrize('desc', TEST_SOURCE.keys()) -def test_walrus_operator(desc): - """Test that we produce valid ast use of the := walrus operator. - - """ - src = dedent(TEST_SOURCE[desc]).strip() - print(src) - # Ensure it's valid - py_ast = ast.parse(src) - enaml_ast = parse(src).body[0].ast - validate_ast(py_ast.body[0], enaml_ast.body[0], True) - - -TEST_BAD_SOURCE = { - ':= in while': r""" - while 2 := 1: - pass - """, - ':= in function argument': r""" - f(a, 2 := c or None) - """ -} - -@pytest.mark.skipif(sys.version_info < (3, 8), reason='Requires Python 3.8') -@pytest.mark.parametrize('desc', TEST_BAD_SOURCE.keys()) -def test_invalid_walrus_operator(desc): - """Test that we produce valid ast use of the := walrus operator. - - """ - src = dedent(TEST_BAD_SOURCE[desc]).strip() - print(src) - with pytest.raises(SyntaxError): - enaml_ast = parse(src).body[0].ast diff --git a/tests/core/parser/test_yield.py b/tests/core/parser/test_yield.py deleted file mode 100644 index 4d0e7a9e5..000000000 --- a/tests/core/parser/test_yield.py +++ /dev/null @@ -1,56 +0,0 @@ -#------------------------------------------------------------------------------ -# Copyright (c) 2020-2024, Nucleic Development Team. -# -# Distributed under the terms of the Modified BSD License. -# -# The full license is in the file LICENSE, distributed with this software. -#------------------------------------------------------------------------------ -import sys -import ast -from textwrap import dedent - -import pytest - -from enaml.core.parser import parse - -from .test_parser import validate_ast - -TEST_SOURCE = { - 'yield': r""" - def f(): - yield - """, - 'yield a': r""" - def f(): - yield a - """, - 'yield a, (b, c)': r""" - def f(): - yield a, (b, c) - """, - 'yield from a': r""" - def f(): - yield from a - """ -} - -TEST_SOURCE_38 = { - 'yield a, *b': r""" - def f(): - yield a, *b - """ -} - -@pytest.mark.parametrize('desc', - list(TEST_SOURCE) + list(TEST_SOURCE_38) if sys.version_info >= (3, 8) else [] -) -def test_return_stmt(desc): - """Test that we produce valid ast use of the := walrus operator. - - """ - src = dedent(TEST_SOURCE.get(desc, TEST_SOURCE_38.get(desc))).strip() - print(src) - # Ensure it's valid - py_ast = ast.parse(src) - enaml_ast = parse(src).body[0].ast - validate_ast(py_ast.body[0], enaml_ast.body[0], True) diff --git a/tests/core/parser/valid/README.md b/tests/core/parser/valid/README.md new file mode 100644 index 000000000..62bd9174e --- /dev/null +++ b/tests/core/parser/valid/README.md @@ -0,0 +1,10 @@ +# Parser validation fixtures + +This directory contains the validation corpus used to bring the Enaml parser closer to the pegen-style parser test model. + +The structure is intentionally split into two categories: + +- `python/`: Python source snippets used to validate compatibility with the standard library AST behavior. +- `enaml/`: Enaml grammar fixtures exercised as parser acceptance checks for grammar coverage. + +This keeps the broad corpus separate from the targeted regression tests already present in the surrounding `tests/core/parser` modules. diff --git a/tests/core/parser/valid/enaml/README.md b/tests/core/parser/valid/enaml/README.md new file mode 100644 index 000000000..d68fca37f --- /dev/null +++ b/tests/core/parser/valid/enaml/README.md @@ -0,0 +1,15 @@ +# Enaml grammar fixtures + +This directory stores Enaml programs that should parse successfully as part of the corpus-based validation layer. + +Fixtures are kept as a single file per grammar construct at the root of this directory so the accepted syntax is easy to scan and extend without artificial "basic_" prefixes: + +- attributes.enaml +- bindings.enaml +- events.enaml +- functions.enaml +- templates.enaml +- async.enaml +- other Enaml syntax files that represent a single construct or family + +The goal is to keep the broad grammar acceptance checks readable and maintainable rather than hiding them inside unrelated parser tests. diff --git a/tests/core/parser/valid/enaml/async.enaml b/tests/core/parser/valid/enaml/async.enaml new file mode 100644 index 000000000..8b28dd85d --- /dev/null +++ b/tests/core/parser/valid/enaml/async.enaml @@ -0,0 +1,26 @@ +from enaml.widgets.api import Window, Container, Field +import asyncio + + +enamldef Main(Window): + attr value = "idle" + + async func refresh(): + await asyncio.sleep(0) + return value.upper() + + async func fetch(path: str, /, *, timeout: float = 1.5, **extra: object) -> tuple[str, float, dict[str, object]]: + await asyncio.sleep(0) + return path, timeout, extra + + async func combine(name: str, count: int = 1, *, suffix: str = "!", **meta: object) -> tuple[str, int, dict[str, object]]: + await asyncio.sleep(0) + return f"{name}{suffix}", count, meta + + async func with_annotations(a: int, b: str = "x", /, *, c: float = 1.25, **kw: object) -> tuple[int, str, float, dict[str, object]]: + await asyncio.sleep(0) + return a, b, c, kw + + Container: + Field: + text = value diff --git a/tests/core/parser/valid/enaml/attributes.enaml b/tests/core/parser/valid/enaml/attributes.enaml new file mode 100644 index 000000000..907483aa3 --- /dev/null +++ b/tests/core/parser/valid/enaml/attributes.enaml @@ -0,0 +1,11 @@ +from enaml.widgets.api import Window, Container, Field + + +enamldef Main(Window): + attr name = "demo" + attr count = 3 + + Container: + Field: + text = name + enabled = count > 0 diff --git a/tests/core/parser/valid/enaml/bindings.enaml b/tests/core/parser/valid/enaml/bindings.enaml new file mode 100644 index 000000000..dc606a4d2 --- /dev/null +++ b/tests/core/parser/valid/enaml/bindings.enaml @@ -0,0 +1,8 @@ +from enaml.widgets.api import Window, Field + + +enamldef Main(Window): + attr value = "hello" + + Field: + text := value diff --git a/tests/core/parser/valid/enaml/events.enaml b/tests/core/parser/valid/enaml/events.enaml new file mode 100644 index 000000000..78b84ce69 --- /dev/null +++ b/tests/core/parser/valid/enaml/events.enaml @@ -0,0 +1,8 @@ +from enaml.widgets.api import Window, Container, PushButton + + +enamldef Main(Window): + Container: + PushButton: button: + event changed + clicked :: changed() diff --git a/tests/core/parser/valid/enaml/functions.enaml b/tests/core/parser/valid/enaml/functions.enaml new file mode 100644 index 000000000..ef1944628 --- /dev/null +++ b/tests/core/parser/valid/enaml/functions.enaml @@ -0,0 +1,21 @@ +from enaml.widgets.api import Window, Container, Field + + +enamldef Main(Window): + attr text_value = "ready" + + func format_value(prefix): + return f"{prefix}:{text_value}" + + func positional_only(a: int, b: str = "x", /, c: float = 1.25, *rest: int, flag: bool = False, **meta: object) -> tuple[int, str, tuple[int, ...], bool, dict[str, object]]: + return a, b, rest, flag, meta + + func keyword_only(*, label: str, count: int = 1) -> tuple[str, int]: + return label, count + + func result(value: int, label: str = "x") -> str: + return f"{label}:{value}" + + Container: + Field: + text = format_value("demo") diff --git a/tests/core/parser/valid/enaml/templates.enaml b/tests/core/parser/valid/enaml/templates.enaml new file mode 100644 index 000000000..1f5ce415a --- /dev/null +++ b/tests/core/parser/valid/enaml/templates.enaml @@ -0,0 +1,16 @@ +from enaml.widgets.api import Window, Container, Field, PushButton + + +template LabelPanel(Content): + const panel_label = "Apply" + Container: + Content: content: + pass + PushButton: action: + text = "Apply" + + +enamldef Main(Window): + Container: + LabelPanel(Field): panel: + panel.content.text = "hello" diff --git a/tests/core/parser/valid/python/README.md b/tests/core/parser/valid/python/README.md new file mode 100644 index 000000000..d87999509 --- /dev/null +++ b/tests/core/parser/valid/python/README.md @@ -0,0 +1,9 @@ +# Python parser compatibility fixtures + +This directory stores Python snippets that are intended to be parsed by the Enaml parser and compared against the stdlib `ast` module. + +These fixtures are the foundation of the pegen-style valid-corpus migration. They should be grouped by language feature rather than by ad hoc file name alone. + +Examples include assignment, function definitions, comprehensions, async syntax, and version-gated grammar features. + +The corpus includes modern Python grammar cases such as template strings, walrus expressions, async syntax, and function definitions, and compares their AST output directly against the stdlib parser. diff --git a/tests/core/parser/valid/python/assignment.py b/tests/core/parser/valid/python/assignment.py new file mode 100644 index 000000000..17feb5363 --- /dev/null +++ b/tests/core/parser/valid/python/assignment.py @@ -0,0 +1,2 @@ +value = 1 +result = value + 2 diff --git a/tests/core/parser/valid/python/async.py b/tests/core/parser/valid/python/async.py new file mode 100644 index 000000000..3e22a9665 --- /dev/null +++ b/tests/core/parser/valid/python/async.py @@ -0,0 +1,9 @@ +async def fetch(query): + return await query() + + +async def gather(items): + result = [] + async for item in items: + result.append(item) + return result diff --git a/tests/core/parser/valid/python/expressions.py b/tests/core/parser/valid/python/expressions.py new file mode 100644 index 000000000..1e6b27fd6 --- /dev/null +++ b/tests/core/parser/valid/python/expressions.py @@ -0,0 +1,8 @@ +value = 1 + 2 * 3 +nested = (value + 4) / 5 +comparison = value > 0 and nested < 10 +result = [x for x in range(3) if x % 2] + +assigned = (value := 1) +paired = (2, value := 3) +container = [2, (item := 4)] diff --git a/tests/core/parser/valid/python/fstrings.py b/tests/core/parser/valid/python/fstrings.py new file mode 100644 index 000000000..5315bdc55 --- /dev/null +++ b/tests/core/parser/valid/python/fstrings.py @@ -0,0 +1,4 @@ +value = 3 +message = f"hello {value}" +formatted = f"{value:>5}" +debug = f"{value=}" diff --git a/tests/core/parser/valid/python/function_def.py b/tests/core/parser/valid/python/function_def.py new file mode 100644 index 000000000..9e985c67c --- /dev/null +++ b/tests/core/parser/valid/python/function_def.py @@ -0,0 +1,9 @@ +def add(left, right=0): + return left + right + + +def outer(name): + def inner(value): + return f"{name}:{value}" + + return inner diff --git a/tests/core/parser/valid/python/functions.py b/tests/core/parser/valid/python/functions.py new file mode 100644 index 000000000..b77fc0dc9 --- /dev/null +++ b/tests/core/parser/valid/python/functions.py @@ -0,0 +1,6 @@ +def add(x, y=0): + return x + y + + +def build(prefix): + return [prefix + str(i) for i in range(3)] diff --git a/tests/core/parser/valid/python/imports.py b/tests/core/parser/valid/python/imports.py new file mode 100644 index 000000000..106e0a3ac --- /dev/null +++ b/tests/core/parser/valid/python/imports.py @@ -0,0 +1,5 @@ +import math +from pathlib import Path + +import math as m +from collections import defaultdict diff --git a/tests/core/parser/valid/python/lambdas.py b/tests/core/parser/valid/python/lambdas.py new file mode 100644 index 000000000..a8b8f4921 --- /dev/null +++ b/tests/core/parser/valid/python/lambdas.py @@ -0,0 +1,2 @@ +square = lambda x: x * x +applicator = lambda func, value: func(value) diff --git a/tests/core/parser/valid/python/lazy_imports.py b/tests/core/parser/valid/python/lazy_imports.py new file mode 100644 index 000000000..30de51bed --- /dev/null +++ b/tests/core/parser/valid/python/lazy_imports.py @@ -0,0 +1,7 @@ +lazy import test +lazy import test as t +lazy import test.a + +lazy from test import a +lazy from test import a as b +lazy from test import a, b diff --git a/tests/core/parser/valid/python/statements.py b/tests/core/parser/valid/python/statements.py new file mode 100644 index 000000000..2d30b66ad --- /dev/null +++ b/tests/core/parser/valid/python/statements.py @@ -0,0 +1,23 @@ +if value > 0: + result = "positive" +else: + result = "non-positive" + +for item in range(3): + result = item + +try: + raise ValueError("demo") +except ValueError as exc: + result = str(exc) + + +def compute(): + if value > 0: + return value + return None + + +def generate(): + yield value + yield from range(3) diff --git a/tests/core/parser/valid/python/tstrings.py b/tests/core/parser/valid/python/tstrings.py new file mode 100644 index 000000000..c657ba37b --- /dev/null +++ b/tests/core/parser/valid/python/tstrings.py @@ -0,0 +1,13 @@ +a = 10 +t"{a * x()}" + +t"no formatted values" +t"eggs {a * x()} spam {b + y()}" + +# Raw t-strings +rt"{a}\n" +rt"{a}\n" + +x = 2 +t"{x=}" +t"{x:{y}}" diff --git a/tests/core/test_declarative_function.py b/tests/core/test_declarative_function.py index e3759b1fc..7335f1403 100644 --- a/tests/core/test_declarative_function.py +++ b/tests/core/test_declarative_function.py @@ -5,6 +5,7 @@ # # The full license is in the file LICENSE, distributed with this software. #------------------------------------------------------------------------------ +import asyncio import gc from textwrap import dedent from collections import Counter @@ -92,6 +93,29 @@ def test_declarative_function_get_and_call(): assert '1 argument' in excinfo.exconly() +def test_async_declarative_function_get_and_call(): + """Test calling an async declarative function and awaiting the result. + + """ + source = dedent("""\ + from enaml.widgets.window import Window + + enamldef MyWindow(Window): main: + + async func call(arg, kwarg=1): + assert main is self + return main, arg, kwarg + + """) + tester = compile_source(source, 'MyWindow')() + bdmethod = tester.call + assert isinstance(bdmethod, BoundDeclarativeMethod) + for i in range(3): + assert asyncio.run(bdmethod(1)) == (tester, 1, 1) + assert asyncio.run(bdmethod(arg=2)) == (tester, 2, 1) + assert asyncio.run(bdmethod(1, kwarg=1)) == (tester, 1, 1) + + def test_declarative_function_defaults(): """Test calling DeclarativeFunction and BoundDeclarativeMethod. @@ -111,6 +135,67 @@ def test_declarative_function_defaults(): assert r == (2, 3) +def test_async_declarative_function_defaults(): + """Test default arguments for async declarative methods. + + """ + source = dedent("""\ + from enaml.widgets.window import Window + + enamldef MyWindow(Window): main: + + async func call(arg, kwarg=1): + return arg, kwarg + """) + tester = compile_source(source, 'MyWindow')() + r = asyncio.run(tester.call(2)) + assert r == (2, 1) + r = asyncio.run(tester.call(2, 3)) + assert r == (2, 3) + + +def test_declarative_function_argument_variants_and_annotations(): + """Exercise the full declarative-function argument surface. + + """ + source = dedent("""\ + from enaml.widgets.window import Window + + enamldef MyWindow(Window): main: + + func call(a: int, b: str = "x", *rest: int, flag: bool = False, **meta: object) -> tuple[int, str, tuple[int, ...], bool, dict[str, object]]: + return a, b, rest, flag, meta + + func result(value: int, label: str = "x") -> str: + return f"{label}:{value}" + + async func fetch(path: str, /, *, timeout: float = 1.5, **extra: object) -> tuple[str, float, dict[str, object]]: + return path, timeout, extra + """) + tester = compile_source(source, 'MyWindow')() + + result = tester.call(1, "y", 2, 3, flag=True, mode="fast") + assert result == (1, "y", (2, 3), True, {"mode": "fast"}) + + annotations = type(tester).call.__func__.__annotations__ + assert annotations["a"] is int + assert annotations["b"] is str + assert annotations["rest"] is int + assert annotations["flag"] is bool + assert annotations["meta"] is object + assert annotations["return"] == tuple[int, str, tuple[int, ...], bool, dict[str, object]] + + assert tester.result(7) == "x:7" + result_annotations = type(tester).result.__func__.__annotations__ + assert result_annotations["value"] is int + assert result_annotations["label"] is str + assert result_annotations["return"] is str + assert tester.result(7) == "x:7" + + r = asyncio.run(tester.fetch("demo", timeout=2.5, mode="fast")) + assert r == ("demo", 2.5, {"mode": "fast"}) + + def test_declarative_function_eq_and_hash(): """Test that BoundDeclarativeMethod eq works. diff --git a/tests/core/test_importer.py b/tests/core/test_importer.py index ffb7b6a55..ecf621348 100644 --- a/tests/core/test_importer.py +++ b/tests/core/test_importer.py @@ -5,6 +5,7 @@ # # The full license is in the file LICENSE, distributed with this software. #------------------------------------------------------------------------------ +from enaml.compat import PY315 import importlib import os import sys @@ -83,7 +84,9 @@ def test_import_and_cache_generation(enaml_module): mod = sys.modules[name] assert mod.__name__ == name assert mod.__file__ == os.path.join(folder, name + ".enaml") - assert os.path.join(folder, "__enamlcache__") in mod.__cached__ + if not PY315: + assert mod.__cached__ + assert os.path.join(folder, "__enamlcache__") in mod.__cached__ assert isinstance(mod.__loader__, EnamlImporter) assert isinstance(mod.__spec__, ModuleSpec) diff --git a/tests/core/test_zipimporter.py b/tests/core/test_zipimporter.py index 77ab0f40e..b6b47ea8f 100644 --- a/tests/core/test_zipimporter.py +++ b/tests/core/test_zipimporter.py @@ -5,6 +5,7 @@ # # The full license is in the file LICENSE, distributed with this software. #------------------------------------------------------------------------------ +from enaml.compat import PY315 import os import sys import enaml @@ -112,7 +113,8 @@ def test_zipimport_from_module(enaml_qtbot, enaml_sleep, zip_library): assert buttons.__name__ == "buttons" assert buttons.__file__ - assert buttons.__cached__ + if not PY315: + assert buttons.__cached__ assert isinstance(buttons.__loader__, EnamlImporter) assert isinstance(buttons.__spec__, ModuleSpec) diff --git a/tests/test_stdlib.py b/tests/test_stdlib.py index ef9de8e71..b4adc6307 100644 --- a/tests/test_stdlib.py +++ b/tests/test_stdlib.py @@ -41,4 +41,5 @@ def test_task_dialog(): def test_message_box(): import enaml with enaml.imports(): - import enaml.stdlib.message_box + from enaml.stdlib.message_box import MessageBox + assert MessageBox.__name__ == 'MessageBox'