Skip to content

Mark AST with kwargs as deprecated #13811

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

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions stdlib/ast.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ class _Attributes(TypedDict, Generic[_EndPositionT], total=False):
# but they consider themselves to live in the ast module,
# so we'll define the stubs in this file.
class AST:
@overload
def __init__(self) -> None: ...
Copy link
Member

Choose a reason for hiding this comment

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

This probably doesn't do much in practice since nobody is constructing the base AST class. We could add this sort of overloads to every AST subclass below but I'm not sure that would make users' lives better.

Copy link
Collaborator Author

@Avasam Avasam Apr 10, 2025

Choose a reason for hiding this comment

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

but I'm not sure that would make users' lives better

Same, personally I wouldn't mind just closing this PR and #4760 . I mostly opened it to leave a trace when closing that issue.

But if we go for it, I'll update subclasses as well.

if sys.version_info < (3, 15):
@overload
@deprecated("Support for arbitrary keyword arguments is deprecated and will be removed in Python 3.15.")
def __init__(self, **kwargs: Any) -> None: ...
Copy link
Collaborator Author

@Avasam Avasam Apr 10, 2025

Choose a reason for hiding this comment

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

I didn't add a comment explaining this Any because I figured the deprecation comment calling this an "arbitrary keyword argument" was self-explanatory enough that these values are arbitrary.

Comment on lines 36 to +42
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I also considered the following (see #4760 (comment)):

Suggested change
class AST:
@overload
def __init__(self) -> None: ...
if sys.version_info < (3, 15):
@overload
@deprecated("Support for arbitrary keyword arguments is deprecated and will be removed in Python 3.15.")
def __init__(self, **kwargs: Any) -> None: ...
class AST(Generic[_CustomASTArgumentT]):
@overload
def __init__(self) -> None: ...
if sys.version_info < (3, 15):
@overload
@deprecated("Support for arbitrary keyword arguments is deprecated and will be removed in Python 3.15.")
def __init__(self, **kwargs: _CustomASTArgumentT) -> None: ...
def __getattribute__(self, name: str) -> _CustomASTArgumentT: ...

if sys.version_info >= (3, 10):
__match_args__ = ()
_attributes: ClassVar[tuple[str, ...]]
Expand Down
Loading