-
Notifications
You must be signed in to change notification settings - Fork 80
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
base: main
Are you sure you want to change the base?
Conversation
There seems to be an unrelated error in 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. |
ae2a2cc
to
37447a4
Compare
# 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #374
Please remove unknown `Extension` options: {','.join(extra)} | ||
this kind of usage is deprecated and may cause errors in the future. | ||
""" | ||
warnings.warn(msg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If/when lenient behaviour is not needed the whole custom __init__
can be removed (and the classes _Extension/Extension
can be unified.
""" | ||
|
||
|
||
# Legal keyword arguments for the Extension constructor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The phrase Legal keyword arguments for the Extension constructorwas copied from core.py
(not sure if `"legal"is the best term to use).
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 indistutils.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.