summaryrefslogtreecommitdiffstats
path: root/Lib/ast.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2023-06-16 16:59:25 (GMT)
committerGitHub <noreply@github.com>2023-06-16 16:59:25 (GMT)
commit5ca707d1e41af165d6bbc6bbc8026256a0a941d3 (patch)
tree49c59fcb0f645a4082aec941384014b4a609e7f8 /Lib/ast.py
parente6982c58602bba9bc1f7c1e6e9cc5f65610d1c6e (diff)
downloadcpython-5ca707d1e41af165d6bbc6bbc8026256a0a941d3.zip
cpython-5ca707d1e41af165d6bbc6bbc8026256a0a941d3.tar.gz
cpython-5ca707d1e41af165d6bbc6bbc8026256a0a941d3.tar.bz2
[3.12] gh-104799: PEP 695 backward compatibility for ast.unparse (GH-105846) (#105862)
(cherry picked from commit 957a974d4fc1575787e4a29a399a47520d6df6d3) Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Diffstat (limited to 'Lib/ast.py')
-rw-r--r--Lib/ast.py6
1 files changed, 4 insertions, 2 deletions
diff --git a/Lib/ast.py b/Lib/ast.py
index 226910e..a307f3e 100644
--- a/Lib/ast.py
+++ b/Lib/ast.py
@@ -1051,7 +1051,8 @@ class _Unparser(NodeVisitor):
self.fill("@")
self.traverse(deco)
self.fill("class " + node.name)
- self._type_params_helper(node.type_params)
+ if hasattr(node, "type_params"):
+ self._type_params_helper(node.type_params)
with self.delimit_if("(", ")", condition = node.bases or node.keywords):
comma = False
for e in node.bases:
@@ -1083,7 +1084,8 @@ class _Unparser(NodeVisitor):
self.traverse(deco)
def_str = fill_suffix + " " + node.name
self.fill(def_str)
- self._type_params_helper(node.type_params)
+ if hasattr(node, "type_params"):
+ self._type_params_helper(node.type_params)
with self.delimit("(", ")"):
self.traverse(node.args)
if node.returns: