Skip to content

Fix building on Python 3.14, where ast.Str was removed - #615

Open
draarivpatel-ui wants to merge 1 commit into
html5lib:masterfrom
draarivpatel-ui:py314-ast-str-removal
Open

draarivpatel-ui wants to merge 1 commit into
html5lib:masterfrom
draarivpatel-ui:py314-ast-str-removal

Conversation

@draarivpatel-ui

Copy link
Copy Markdown

Summary

Fixes #588.

setup.py reads the package version from html5lib/__init__.py with an isinstance(a.value, ast.Str) check. ast.Str was deprecated since Python 3.8 and removed in Python 3.14, so building or installing html5lib on 3.14 fails with:

File "setup.py", line 96, in <module>
    isinstance(a.value, ast.Str)):
                       ^
AttributeError: module 'ast' has no attribute 'Str'

Change

Neither node class can cover every version html5lib supports on its own: literals parse as ast.Str before Python 3.8 and as ast.Constant since, and ast.Str no longer exists at all on 3.14. The string value is now extracted by duck-typing both node shapes (ast.Str stores the string in s, ast.Constant in value), which behaves identically on Python 2.7 through 3.13 and additionally works on 3.14.

Verification

  • Python 3.14.7, python setup.py --version on the original code: AttributeError: module 'ast' has no attribute 'Str' (the reported failure).
  • Same interpreter with the fix: prints 1.2.dev0.
  • Full pip install . on Python 3.14 succeeds, import html5lib reports version 1.2-dev and html5lib.parse round-trips a document.
  • Python 3.9 python setup.py --version still prints 1.2.dev0 (no regression on older interpreters).

Note: on Python 3.14 with setuptools >= 81 the build then stops at the unrelated missing pkg_resources import already tracked as #593; this fix is independent of it.

setup.py read the package version with an isinstance check against
ast.Str, which raises AttributeError on Python 3.14 because the class
was removed there after being deprecated since Python 3.8. Neither
ast.Str nor ast.Constant can cover every supported version on its own,
since literals parse as ast.Str before Python 3.8 and ast.Constant
after, so the string value is now extracted by duck-typing both node
shapes.

Fixes html5lib#588
Copilot AI balanced review requested due to automatic review settings November 26, 2026 01:42

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

html5lib fails to build on Python 3.14 (uses removed ast.Str node)

2 participants