gh-104799: PEP 695 backward compatibility for ast.unparse (#105846)

This commit is contained in:
Jelle Zijlstra 2023-06-16 09:31:23 -07:00 committed by GitHub
parent 70c075c194
commit 957a974d4f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 80 additions and 3 deletions

View file

@ -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: