[BUG] setup.cfg attr: value is inconsistent between parsing and loading module
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 2.9k
- Forks
- 1.4k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 1
Description
setuptools version
setuptools===49.6.0.post20210108
Python version
Python 3.9.2
OS
macOS Catalina
Additional environment information
No response
Description
In https://github.com/pypa/setuptools/blob/b2f7b8f92725c63b164d5776f85e67cc560def4e/setuptools/config.py#L35 StaticModule parses the statements in order to find a relevant assignment, but it should parse statements in reverse order to be consistent with the behavior when loading a module (i.e., the last assignment wins when loading a module).
I think the line should probably read
for statement in reversed(self.module.body)
Expected behavior
I expect the parsing shortcut for finding module attributes to be consistent with loading the module.
How to Reproduce
This inconsistency is illustrated when having a project with a setup.cfg that contains version = attr: mypackage.__version__, where mypackage/__init__.py is
__version__ = "0.1.0"
__version__ = "0.4.0"
With this setup, the version will be 0.1.0, but if the first line is changed to something literal_parse does not understand, forcing setuptools to load the module (like __version__ = "0.1.0" + ""), then the version is 0.4.0.
Output
Code of Conduct
- I agree to follow the PSF Code of Conduct
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in setuptools/config.py at StaticModule and compare the parsing order with module loading. Reproduce the issue using setup.cfg with attr: mypackage.version and duplicate assignments in mypackage/init.py; done means the parsed value matches Python's last-assignment behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 42/100