Skip to content

Type setuptools compiler attributes#15375

Draft
Avasam wants to merge 1 commit intopython:mainfrom
Avasam:setuptools-compiler-attributes
Draft

Type setuptools compiler attributes#15375
Avasam wants to merge 1 commit intopython:mainfrom
Avasam:setuptools-compiler-attributes

Conversation

@Avasam
Copy link
Collaborator

@Avasam Avasam commented Feb 5, 2026

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
Copy link
Contributor

github-actions bot commented Feb 5, 2026

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

setuptools (https://github.com/pypa/setuptools)
+ setuptools/command/build_ext.py:226: error: Argument "compiler" to "new_compiler" has incompatible type "Compiler | str | None"; expected "str | None"  [arg-type]
+ 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]

@Avasam
Copy link
Collaborator Author

Avasam commented Feb 5, 2026

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

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