Skip to content

Add __new__ to old ast.Constant aliases - #14397

Merged
srittau merged 16 commits into
python:mainfrom
srittau:deprecated-ast
Jul 11, 2025
Merged

srittau merged 16 commits into
python:mainfrom
srittau:deprecated-ast

Conversation

@srittau

@srittau srittau commented Jul 11, 2025 •

Copy link
Copy Markdown
Collaborator

This aligns the old constant classes closer to the actual implementation. It's not perfect, as it doesn't replicate the __instancecheck__ and doesn't replicate the fact that theoretical sub-classes of the old constant classes are still possible and don't get replaced with Constant.

@github-actions

This comment has been minimized.

Comment thread stdlib/ast.pyi Outdated
@github-actions

This comment has been minimized.

@srittau

srittau commented Jul 11, 2025

Copy link
Copy Markdown
Collaborator Author

The only primer hit is (as expected) in a piece of code that won't work on Python 3.14, but can actually be simplified.

@srittau
srittau marked this pull request as ready for review July 11, 2025 11:39
@srittau

srittau commented Jul 11, 2025

Copy link
Copy Markdown
Collaborator Author

This aligns the old constant classes closer to the actual implementation. It's not perfect, as it doesn't replicate the __instancecheck__ and doesn't replicate the fact that theoretical sub-classes of the old constant classes are still possible and don't get replaced with Constant.

That said, the minimal primer fallout and the fact that these are deprecated classes, so no new code will use them, indicates that this is not a problem.

Comment thread stdlib/ast.pyi
@github-actions

This comment has been minimized.

@github-actions

Copy link
Copy Markdown
Contributor

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

spack (https://github.com/spack/spack)
+ lib/spack/spack/cmd/style.py:666: error: Incompatible types in assignment (expression has type "str | bytes | int | float | complex | EllipsisType | None", variable has type "str")  [assignment]

@srittau
srittau merged commit d5af6be into python:main Jul 11, 2025
@srittau
srittau deleted the deprecated-ast branch July 11, 2025 12:59
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.

2 participants