Skip to content

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.

# 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
Please remove unknown `Extension` options: {','.join(extra)}
this kind of usage is deprecated and may cause errors in the future.
"""
warnings.warn(msg)
Copy link
Contributor Author

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

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).

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