]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
refactor(async_to_sync): finally solved the Tuple mystery
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sat, 2 Sep 2023 21:18:30 +0000 (22:18 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Wed, 11 Oct 2023 21:45:38 +0000 (23:45 +0200)
The problem came from names shadowing in the ast_comment module. To be
reported upstream.

tools/async_to_sync.py

index 080267e57870eac65916e17eb4b70947f1ca65c9..ada8b596d06a9a7595ff99a5923ce95d79cfd39a 100755 (executable)
@@ -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)):