Skip to content

Commit

Permalink
drgndoc: handle removal of deprecated ast nodes in Python 3.14
Browse files Browse the repository at this point in the history
The Num, Str, Bytes, Ellipsis, and NameConstant ast nodes have been
deprecated since Python 3.8 and were finally removed in Python 3.14.
This causes an AttributeError in drgndoc. We already transform them to
the replacement Constant node, so we just need to stop trying to use the
old names.

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=2325185.

Signed-off-by: Omar Sandoval <[email protected]>
  • Loading branch information
osandov committed Nov 11, 2024
1 parent b7d8877 commit 025a04d
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions docs/exts/drgndoc/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,19 @@ def visit_AnnAssign(self, node: ast.AnnAssign) -> ast.AnnAssign:

# Replace the old constant nodes produced by ast.parse() before Python 3.8
# with Constant.
def visit_Num(self, node: ast.Num) -> ast.Constant:
def visit_Num(self, node: Any) -> ast.Constant:
return ast.copy_location(ast.Constant(node.n), node)

def visit_Str(self, node: ast.Str) -> ast.Constant:
def visit_Str(self, node: Any) -> ast.Constant:
return ast.copy_location(ast.Constant(node.s), node)

def visit_Bytes(self, node: ast.Bytes) -> ast.Constant:
def visit_Bytes(self, node: Any) -> ast.Constant:
return ast.copy_location(ast.Constant(node.s), node)

def visit_Ellipsis(self, node: ast.Ellipsis) -> ast.Constant:
def visit_Ellipsis(self, node: Any) -> ast.Constant:
return ast.copy_location(ast.Constant(...), node)

def visit_NameConstant(self, node: ast.NameConstant) -> ast.Constant:
def visit_NameConstant(self, node: Any) -> ast.Constant:
return ast.copy_location(ast.Constant(node.value), node)

# Get rid of Index nodes, which are deprecated as of Python 3.9.
Expand Down Expand Up @@ -186,9 +186,7 @@ def _docstring_from_node(node: Optional[ast.AST]) -> Optional[str]:
if not isinstance(node, ast.Expr):
return None
node = node.value
if isinstance(node, ast.Str):
text = node.s
elif isinstance(node, ast.Constant) and isinstance(node.value, str):
if isinstance(node, ast.Constant) and isinstance(node.value, str):
text = node.value
else:
return None
Expand Down

0 comments on commit 025a04d

Please sign in to comment.