8000 gh-105858: Improve AST node constructors by JelleZijlstra · Pull Request #105880 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-105858: Improve AST node constructors #105880

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

Merged
merged 18 commits into from
Feb 28, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Reword Whats New note (based on suggestion by Alex Waygood)
  • Loading branch information
JelleZijlstra committed Feb 27, 2024
commit 4bb06566c7ec55bc422f20239d5a5f6b36b115e2
23 changes: 15 additions & 8 deletions Doc/whatsnew/3.13.rst
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,21 @@ array
ast
---

* The constructors of node types in the :mod:`ast` module are stricter
in the arguments they accept. If an optional field is not passed to the
constructor, it is set to ``None``, and if a list field is not passed,
it is set to the empty list. (Previously, the attribute would be missing.)
If any other field is not passed to the constructor, a :exc:`DeprecationWarning`
is raised. This will raise an exception in Python 3.15. Similarly, passing
a keyword argument that does not map to a field on the AST node now raises
a :exc:`DeprecationWarning` and will raise an exception in Python 3.15.
* The constructors of node types in the :mod:`ast` module are now stricter
in the arguments they accept, and have more intuitive behaviour when
arguments are omitted.

If an optional field on an AST node is not included as an argument when
constructing an instance, the field will now be set to ``None``. Similarly,
if a list field is omitted, that field will now be set to an empty list.
(Previously, in both cases, the attribute would be missing on the newly
constructed AST node instance.)

If other arguments are omitted, a :exc:`DeprecationWarning` is emitted.
This will cause an exception in Python 3.15. Similarly, passing a keyword
argument that does not map to a field on the AST node is now deprecated,
and will raise an exception in Python 3.15.

* :func:`ast.parse` now accepts an optional argument ``optimize``
which is passed on to the :func:`compile` built-in. This makes it
possible to obtain an optimized ``AST``.
Expand Down
0