Skip to content
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

[BUG] setuptools.depends:get_module_constant returns None on Python 3.13.0a1 #4090

Closed
hroncok opened this issue Oct 24, 2023 · 2 comments · Fixed by #4094
Closed

[BUG] setuptools.depends:get_module_constant returns None on Python 3.13.0a1 #4090

hroncok opened this issue Oct 24, 2023 · 2 comments · Fixed by #4094

Comments

@hroncok
Copy link
Contributor

hroncok commented Oct 24, 2023

setuptools version

65.6.3.post20230109

Python version

3.13.0a1

OS

Fedora Linux

Additional environment information

This happens with later versions as well, but I reproduced from the main branch @ 2384d91

Description

The get_module_constant function from setuptools.depends returns None instead of the actual constant value on Python 3.13.0a1. This works fine on Python 3.12.0.

Expected behavior

The function should work the same on Python 3.12 and 3.13.

How to Reproduce

  1. Create a simple Python file with a constant in it.
  2. Run setuptools.depends:get_module_constant to retrieve it.

Output

$ cat foobar.py 
__version__ = "1"

$ venv3.12/bin/python -c 'import setuptools; print(setuptools.__version__); from setuptools.depends import get_module_constant; print(get_module_constant("foobar", "__version__"))'
65.6.3.post20230109
1

$ venv3.13/bin/python -c 'import setuptools; print(setuptools.__version__); from setuptools.depends import get_module_constant; print(get_module_constant("foobar", "__version__"))'
65.6.3.post20230109
None
@hroncok hroncok added bug Needs Triage Issues that need to be evaluated for severity and status. labels Oct 24, 2023
@hroncok
Copy link
Contributor Author

hroncok commented Oct 24, 2023

By debugging the setuptools code, I figured out the bytecode numbers must have changed:

$ venv3.13/bin/python -c 'import setuptools; print(setuptools.__version__); from setuptools.depends import get_module_constant; print(get_module_constant("foobar", "__version__"))'
65.6.3.post20230109
RESUME 149
LOAD_CONST 83
STORE_NAME 114
RETURN_CONST 103
None
$ venv3.12/bin/python -c 'import setuptools; print(setuptools.__version__); from setuptools.depends import get_module_constant; print(get_module_constant("foobar", "__version__"))'
65.6.3.post20230109
RESUME 151
LOAD_CONST 100
STORE_NAME 90
1

That's from

STORE_NAME = 90
STORE_GLOBAL = 97
LOAD_CONST = 100

@abravalheri abravalheri added help wanted and removed Needs Triage Issues that need to be evaluated for severity and status. labels Oct 24, 2023
@encukou
Copy link
Contributor

encukou commented Oct 25, 2023

This should use dis.opmap rather than hardcoding the numeric values.
However, there is also no guarantee that e.g. LOAD_CONST will continue to be used for all loads of a constant -- CPython could, for example, add LOAD_CONST_STR that load string constants. So even dis.opmap isn't future-proof.

$ python3.13
>>> import dis
>>> dis.opmap['LOAD_CONST']
83

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

Successfully merging a pull request may close this issue.

3 participants