Skip to content

Use dataclass to add type annotations to Extension so that it can easily be extended in setuptools. #373

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

abravalheri
Copy link
Contributor

@abravalheri abravalheri commented Jul 11, 2025

In pypa/setuptools#5022, there is an effort to add type annotations to setuptools.extension.Extension.

However, right now it basically requires repeating all the __init__ arguments that are already specified in distutils.extension.Extension and all the type annotations.
If any argument changes (added/removed/changed type annotation), that needs to be repeated in setuptools.

There is a discussion in https://github.com/pypa/setuptools/pull/5022/files#r2124429494 about how would it be possible to avoid this duplication and need for manual synchronisation.

This PR is an attempt to use dataclass for that.

I have experimented with other approaches (like attempting to use a TypedDict), but in the end of the day, this approach is what seems to me the most promising.

If I am not mistaken, this should allow backward compatibility. Type checkers are likely to start catching unknown keyword arguments, but I think that is a good thing.

On a related not, I did modify the warning to mention using unknown keywords is deprecated, the reasoning is that removing this lenient behaviour simplifies a lot of stuff and we can use dataclasses by the book.

The docstrings for the properties were basically moved from the existing class docstring.

@abravalheri
Copy link
Contributor Author

abravalheri commented Jul 11, 2025

There seems to be an unrelated error in [mypy] distutils/compilers/C/base.py, possibly caused by recent versions of dependencies being released: see https://github.com/pypa/distutils/pull/374/files.

I have rebased this PR on top of #374, so that we can see if the main log fails on not in the majority of the CI workers. Now the same unrelated errors as in #374 (comment) can be found.

@@ -70,7 +70,7 @@ class Compiler:
# dictionary (see below -- used by the 'new_compiler()' factory
# function) -- authors of new compiler interface classes are
# responsible for updating 'compiler_class'!
compiler_type: ClassVar[str] = None # type: ignore[assignment]
compiler_type: ClassVar[str] = None
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #374

@abravalheri abravalheri marked this pull request as ready for review July 11, 2025 15:52
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