-
Notifications
You must be signed in to change notification settings - Fork 302
setup.py: fix version parsing on Python 3.14 (ast.Str removed)
#589
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
atsampson
commented
Oct 8, 2025
This isn't right for pre-3.14 versions - the version = line fails because there's no a.value.value on older versions. Something like this works (tested on 2.7 and 3.11-3.14):
version = None
with open(join(here, "html5lib", "__init__.py"), "rb") as init_file:
t = ast.parse(init_file.read(), filename="__init__.py", mode="exec")
assert isinstance(t, ast.Module)
assignments = filter(lambda x: isinstance(x, ast.Assign), t.body)
for a in assignments:
if (len(a.targets) == 1 and
isinstance(a.targets[0], ast.Name) and
a.targets[0].id == "__version__"):
if hasattr(ast, "Str") and isinstance(a.value, ast.Str):
version = a.value.s
elif (hasattr(ast, "Constant")
and isinstance(a.value, ast.Constant)
and isinstance(a.value.value, str)):
version = a.value.value
assert version is not None
Python 3.14 removes the ast.Str node type. String literals now appear as ast.Constant(value=str). Update the AST check to accept both ast.Str (for older Pythons) and ast.Constant with a string value (for Python 3.8+), allowing html5lib to build successfully on Python 3.14 while remaining compatible with older version.
cc43f00 to
b90daff
Compare
sookach
commented
Oct 10, 2025
Thanks! Updated the PR.
reneleonhardt
commented
Nov 26, 2025
Could you fix appveyor? For example the flake8 formatting.
https://ci.appveyor.com/project/gsnedders/html5lib-python/builds/52890634
setup.py declares python_requires >= 2.7, but Python 3.13 is not tested in appveyor.
Python 3.7 is EOL since 2023年06月27日, when will it be allowed to not stay compatible anymore?
py --list
-V:3.8 Python 3.8 (64-bit)
No suitable Python runtime found
Python 2.7 is EOL since 2020年01月01日, when will it be allowed to not stay compatible anymore?
Microsoft Visual C++ 9.0 is 15 years old and not available anymore officially of course.
running build_ext
building 'lxml.etree' extension
error: Microsoft Visual C++ 9.0 is required. Get it from http://aka.ms/vcpython27
Uh oh!
There was an error while loading. Please reload this page.
Python 3.14 removes the ast.Str node type. String literals now appear as ast.Constant(value=str).
Update the AST check to accept both ast.Str (for older Pythons) and ast.Constant with a string value (for Python 3.8+), allowing html5lib to build successfully on Python 3.14 while remaining compatible with older version. Tested at desk with
pip install -e .Fixes: #588