From: Daniele Varrazzo Date: Sat, 2 Sep 2023 21:18:30 +0000 (+0100) Subject: refactor(async_to_sync): finally solved the Tuple mystery X-Git-Tag: pool-3.2.0~12^2~39 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=24ff1271ec9eb6fcd8e9a5a5acefba92a015a710;p=thirdparty%2Fpsycopg.git refactor(async_to_sync): finally solved the Tuple mystery The problem came from names shadowing in the ast_comment module. To be reported upstream. --- diff --git a/tools/async_to_sync.py b/tools/async_to_sync.py index 080267e57..ada8b596d 100755 --- a/tools/async_to_sync.py +++ b/tools/async_to_sync.py @@ -11,6 +11,19 @@ from argparse import ArgumentParser, Namespace import ast_comments as ast +# The ast_comment has an import: +# +# from typing import Dict, List, Tuple, Union +# +# which shadows some of the types defined in ast. +# +# TODO: report the issue upstream +import ast as ast_orig + +ast.Dict = ast_orig.Dict +ast.List = ast_orig.List +ast.Tuple = ast_orig.Tuple + def main() -> int: opt = parse_cmdline() @@ -206,9 +219,7 @@ class RenameAsyncToSync(ast.NodeTransformer): for base in node.bases: if not isinstance(base, ast.Subscript): continue - # if not isinstance(base.slice, ast.Tuple): - # ast.Tuple is typing.Tuple??? - if type(base.slice).__name__ != "Tuple": + if not isinstance(base.slice, ast.Tuple): continue for elt in base.slice.elts: if not (isinstance(elt, ast.Constant) and isinstance(elt.value, str)):