From 76da49ae7d089957284796e2c64ddc6be766785b Mon Sep 17 00:00:00 2001 From: Nicola Soranzo Date: Thu, 19 Sep 2024 01:29:27 +0100 Subject: [PATCH] Merge upstream lib2to3 from v3.12.2-989-gfcfe78664bf --- cpython | 2 +- fissix/Grammar.txt | 52 +++++++++++++++++++++++++++++++---- fissix/__init__.py | 5 ++-- fissix/btm_utils.py | 1 - fissix/fixes/fix_metaclass.py | 2 +- fissix/fixes/fix_paren.py | 2 +- fissix/fixes/fix_urllib.py | 1 + fissix/patcomp.py | 1 + fissix/pgen2/driver.py | 1 + fissix/pgen2/grammar.py | 1 + fissix/pgen2/pgen.py | 5 +++- fissix/pgen2/token.py | 2 +- fissix/pgen2/tokenize.py | 8 ++++-- fissix/pygram.py | 1 + fissix/pytree.py | 6 ++-- fissix/refactor.py | 1 + 16 files changed, 71 insertions(+), 20 deletions(-) diff --git a/cpython b/cpython index 7443d42..fcfe786 160000 --- a/cpython +++ b/cpython @@ -1 +1 @@ -Subproject commit 7443d42021d433da0497f8ba651daa47e7dc1991 +Subproject commit fcfe78664bf740a7fb059f9817e584a612e09f54 diff --git a/fissix/Grammar.txt b/fissix/Grammar.txt index e007dc1..fa7b150 100644 --- a/fissix/Grammar.txt +++ b/fissix/Grammar.txt @@ -18,15 +18,55 @@ decorated: decorators (classdef | funcdef | async_funcdef) async_funcdef: ASYNC funcdef funcdef: 'def' NAME parameters ['->' test] ':' suite parameters: '(' [typedargslist] ')' -typedargslist: ((tfpdef ['=' test] ',')* - ('*' [tname] (',' tname ['=' test])* [',' ['**' tname [',']]] | '**' tname [',']) - | tfpdef ['=' test] (',' tfpdef ['=' test])* [',']) + +# The following definition for typedarglist is equivalent to this set of rules: +# +# arguments = argument (',' argument)* +# argument = tfpdef ['=' test] +# kwargs = '**' tname [','] +# args = '*' [tname] +# kwonly_kwargs = (',' argument)* [',' [kwargs]] +# args_kwonly_kwargs = args kwonly_kwargs | kwargs +# poskeyword_args_kwonly_kwargs = arguments [',' [args_kwonly_kwargs]] +# typedargslist_no_posonly = poskeyword_args_kwonly_kwargs | args_kwonly_kwargs +# typedarglist = arguments ',' '/' [',' [typedargslist_no_posonly]])|(typedargslist_no_posonly)" +# +# It needs to be fully expanded to allow our LL(1) parser to work on it. + +typedargslist: tfpdef ['=' test] (',' tfpdef ['=' test])* ',' '/' [ + ',' [((tfpdef ['=' test] ',')* ('*' [tname] (',' tname ['=' test])* + [',' ['**' tname [',']]] | '**' tname [',']) + | tfpdef ['=' test] (',' tfpdef ['=' test])* [','])] + ] | ((tfpdef ['=' test] ',')* ('*' [tname] (',' tname ['=' test])* + [',' ['**' tname [',']]] | '**' tname [',']) + | tfpdef ['=' test] (',' tfpdef ['=' test])* [',']) + tname: NAME [':' test] tfpdef: tname | '(' tfplist ')' tfplist: tfpdef (',' tfpdef)* [','] -varargslist: ((vfpdef ['=' test] ',')* - ('*' [vname] (',' vname ['=' test])* [',' ['**' vname [',']]] | '**' vname [',']) - | vfpdef ['=' test] (',' vfpdef ['=' test])* [',']) + +# The following definition for varargslist is equivalent to this set of rules: +# +# arguments = argument (',' argument )* +# argument = vfpdef ['=' test] +# kwargs = '**' vname [','] +# args = '*' [vname] +# kwonly_kwargs = (',' argument )* [',' [kwargs]] +# args_kwonly_kwargs = args kwonly_kwargs | kwargs +# poskeyword_args_kwonly_kwargs = arguments [',' [args_kwonly_kwargs]] +# vararglist_no_posonly = poskeyword_args_kwonly_kwargs | args_kwonly_kwargs +# varargslist = arguments ',' '/' [','[(vararglist_no_posonly)]] | (vararglist_no_posonly) +# +# It needs to be fully expanded to allow our LL(1) parser to work on it. + +varargslist: vfpdef ['=' test ](',' vfpdef ['=' test])* ',' '/' [',' [ + ((vfpdef ['=' test] ',')* ('*' [vname] (',' vname ['=' test])* + [',' ['**' vname [',']]] | '**' vname [',']) + | vfpdef ['=' test] (',' vfpdef ['=' test])* [',']) + ]] | ((vfpdef ['=' test] ',')* + ('*' [vname] (',' vname ['=' test])* [',' ['**' vname [',']]]| '**' vname [',']) + | vfpdef ['=' test] (',' vfpdef ['=' test])* [',']) + vname: NAME vfpdef: vname | '(' vfplist ')' vfplist: vfpdef (',' vfpdef)* [','] diff --git a/fissix/__init__.py b/fissix/__init__.py index 9c5c43f..2032d5b 100644 --- a/fissix/__init__.py +++ b/fissix/__init__.py @@ -7,7 +7,6 @@ import logging import os -import sys import tempfile from pathlib import Path @@ -16,8 +15,8 @@ from .__version__ import __version__ from .pgen2 import driver, grammar, pgen -__base_version__ = "3.9.0a6+" -__base_revision__ = "v3.9.0a5-508-g7443d42021" +__base_version__ = "3.12.6+" +__base_revision__ = "v3.12.2-989-gfcfe78664bf" CACHE_DIR = Path(user_cache_dir("fissix", version=__version__)) diff --git a/fissix/btm_utils.py b/fissix/btm_utils.py index 9fdc663..b116e0f 100644 --- a/fissix/btm_utils.py +++ b/fissix/btm_utils.py @@ -222,7 +222,6 @@ def reduce_tree(node, parent=None): else: # TODO: handle {min, max} repeaters raise NotImplementedError - pass # add children if details_node and new_node is not None: diff --git a/fissix/fixes/fix_metaclass.py b/fissix/fixes/fix_metaclass.py index b4140a9..9634f9d 100644 --- a/fissix/fixes/fix_metaclass.py +++ b/fissix/fixes/fix_metaclass.py @@ -51,7 +51,7 @@ def fixup_parse_tree(cls_node): # already in the preferred format, do nothing return - # !%@#! oneliners have no suite node, we have to fake one up + # !%@#! one-liners have no suite node, we have to fake one up for i, node in enumerate(cls_node.children): if node.type == token.COLON: break diff --git a/fissix/fixes/fix_paren.py b/fissix/fixes/fix_paren.py index 545c545..3c4112c 100644 --- a/fissix/fixes/fix_paren.py +++ b/fissix/fixes/fix_paren.py @@ -1,4 +1,4 @@ -"""Fixer that addes parentheses where they are required +"""Fixer that adds parentheses where they are required This converts ``[x for x in 1, 2]`` to ``[x for x in (1, 2)]``.""" diff --git a/fissix/fixes/fix_urllib.py b/fissix/fixes/fix_urllib.py index 4ff6b07..2ac4163 100644 --- a/fissix/fixes/fix_urllib.py +++ b/fissix/fixes/fix_urllib.py @@ -128,6 +128,7 @@ def build_pattern(): class FixUrllib(FixImports): + def build_pattern(self): return "|".join(build_pattern()) diff --git a/fissix/patcomp.py b/fissix/patcomp.py index dd7ee7f..4b8d220 100644 --- a/fissix/patcomp.py +++ b/fissix/patcomp.py @@ -36,6 +36,7 @@ def tokenize_wrapper(input): class PatternCompiler(object): + def __init__(self, grammar_file=None): """Initializer. diff --git a/fissix/pgen2/driver.py b/fissix/pgen2/driver.py index 7228514..e2ac281 100644 --- a/fissix/pgen2/driver.py +++ b/fissix/pgen2/driver.py @@ -27,6 +27,7 @@ class Driver(object): + def __init__(self, grammar, convert=None, logger=None): self.grammar = grammar if logger is None: diff --git a/fissix/pgen2/grammar.py b/fissix/pgen2/grammar.py index a35f5e8..f1dfdb4 100644 --- a/fissix/pgen2/grammar.py +++ b/fissix/pgen2/grammar.py @@ -193,3 +193,4 @@ def report(self): if line: op, name = line.split() opmap[op] = getattr(token, name) +del line, op, name diff --git a/fissix/pgen2/pgen.py b/fissix/pgen2/pgen.py index 1da6925..fdf0458 100644 --- a/fissix/pgen2/pgen.py +++ b/fissix/pgen2/pgen.py @@ -10,10 +10,11 @@ class PgenGrammar(grammar.Grammar): class ParserGenerator(object): + def __init__(self, filename, stream=None): close_stream = None if stream is None: - stream = open(filename) + stream = open(filename, encoding="utf-8") close_stream = stream.close self.filename = filename self.stream = stream @@ -342,6 +343,7 @@ def raise_error(self, msg, *args): class NFAState(object): + def __init__(self): self.arcs = [] # list of (label, NFAState) pairs @@ -352,6 +354,7 @@ def addarc(self, next, label=None): class DFAState(object): + def __init__(self, nfaset, final): assert isinstance(nfaset, dict) assert isinstance(next(iter(nfaset)), NFAState) diff --git a/fissix/pgen2/token.py b/fissix/pgen2/token.py index 1d086d3..8681efa 100755 --- a/fissix/pgen2/token.py +++ b/fissix/pgen2/token.py @@ -72,7 +72,7 @@ tok_name = {} for _name, _value in list(globals().items()): - if type(_value) is type(0): + if isinstance(_value, int): tok_name[_value] = _name diff --git a/fissix/pgen2/tokenize.py b/fissix/pgen2/tokenize.py index dd78551..e081fb6 100644 --- a/fissix/pgen2/tokenize.py +++ b/fissix/pgen2/tokenize.py @@ -206,6 +206,7 @@ def tokenize_loop(readline, tokeneater): class Untokenizer: + def __init__(self): self.tokens = [] self.prev_row = 1 @@ -592,11 +593,12 @@ def generate_tokens(readline): stashed = tok continue - if token == "def": + if token in ("def", "for"): if stashed and stashed[0] == NAME and stashed[1] == "async": - async_def = True - async_def_indent = indents[-1] + if token == "def": + async_def = True + async_def_indent = indents[-1] yield ( ASYNC, diff --git a/fissix/pygram.py b/fissix/pygram.py index 2ecaff0..2cc8b0d 100644 --- a/fissix/pygram.py +++ b/fissix/pygram.py @@ -17,6 +17,7 @@ class Symbols(object): + def __init__(self, grammar): """Initializer. diff --git a/fissix/pytree.py b/fissix/pytree.py index 3426d98..e2374d0 100644 --- a/fissix/pytree.py +++ b/fissix/pytree.py @@ -502,6 +502,7 @@ def generate_matches(self, nodes): class LeafPattern(BasePattern): + def __init__(self, type=None, content=None, name=None): """ Initializer. Takes optional type, content, and name. @@ -731,8 +732,8 @@ def generate_matches(self, nodes): r[self.name] = nodes[:count] yield count, r except RuntimeError: - # We fall back to the iterative pattern matching scheme if the recursive - # scheme hits the recursion limit. + # Fall back to the iterative pattern matching scheme if the + # recursive scheme hits the recursion limit (RecursionError). for count, r in self._iterative_matches(nodes): if self.name: r[self.name] = nodes[:count] @@ -802,6 +803,7 @@ def _recursive_matches(self, nodes, count): class NegatedPattern(BasePattern): + def __init__(self, content=None): """ Initializer. diff --git a/fissix/refactor.py b/fissix/refactor.py index 96e2a80..d08bbc9 100644 --- a/fissix/refactor.py +++ b/fissix/refactor.py @@ -691,6 +691,7 @@ class MultiprocessingUnsupported(Exception): class MultiprocessRefactoringTool(RefactoringTool): + def __init__(self, *args, **kwargs): super(MultiprocessRefactoringTool, self).__init__(*args, **kwargs) self.queue = None