Skip to content

Type setuptools compiler attributes - #15375

Draft
Avasam wants to merge 2 commits into
python:mainfrom
Avasam:setuptools-compiler-attributes
Draft

Avasam wants to merge 2 commits into
python:mainfrom
Avasam:setuptools-compiler-attributes

Conversation

@Avasam

@Avasam Avasam commented Feb 5, 2026 •

Copy link
Copy Markdown
Collaborator

The compiler attr in commands is weird, it's never set in finalize_options, but rather in run instead. (normally we treat anything in finalize_options in setuptools the same as if it's been initialized in __init__)
With downstream command subclasses also intended to override finalize_options, this means compiler may not be an actual Compiler class instance yet.

Tentatively opening to see ecosystem check.

This would, once again, benefit from AnyOf: python/typing#566

@github-actions

This comment has been minimized.

@Avasam

Avasam commented Feb 5, 2026

Copy link
Copy Markdown
Collaborator Author

So this is an issue for setuptools itself... I might be able to push for upstream changes, but I'm not yet sure how to do so in a backwards compatible way.

Maybe I'll have to keep these as Any

@github-actions

Copy link
Copy Markdown
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

setuptools (https://github.com/pypa/setuptools)
+ setuptools/command/build_clib.py:77: error: Item "str" of "Compiler | str | None" has no attribute "object_filenames"  [union-attr]
+ setuptools/command/build_clib.py:77: error: Item "None" of "Compiler | str | None" has no attribute "object_filenames"  [union-attr]
+ setuptools/command/build_clib.py:89: error: Item "str" of "Compiler | str | None" has no attribute "compile"  [union-attr]
+ setuptools/command/build_clib.py:89: error: Item "None" of "Compiler | str | None" has no attribute "compile"  [union-attr]
+ setuptools/command/build_clib.py:101: error: Item "str" of "Compiler | str | None" has no attribute "create_static_lib"  [union-attr]
+ setuptools/command/build_clib.py:101: error: Item "None" of "Compiler | str | None" has no attribute "create_static_lib"  [union-attr]

This branch has not been deployed

No deployments
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.

1 participant