Skip to content
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

gh-121332: Make AST node constructor check _attributes instead of hardcoding attributes #121334

Merged
merged 4 commits into from
Jul 11, 2024

Conversation

JelleZijlstra
Copy link
Member

@JelleZijlstra JelleZijlstra commented Jul 3, 2024

"Support for arbitrary keyword arguments is deprecated "
"and will be removed in Python 3.15.",
Py_TYPE(self)->tp_name, key
) < 0) {
Copy link
Member

Choose a reason for hiding this comment

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

Do you need to actually check later whether there are remaining attributes to be initialized or not? because I would say "ok, they can be left uninitialized if they are already present on the class dictionary" for instance?

For instance ast.Tuple().end_lineno is None, but ast.Tuple().lineno raises AttributeError. So maybe we should document the behaviour for AST nodes custom subclasses?

Copy link
Member Author

Choose a reason for hiding this comment

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

The current behavior is to allow omitting most attributes, though a few default to None. That behavior is somewhat questionable but I'd rather leave it alone for now, at least for 3.13.

@JelleZijlstra
Copy link
Member Author

Going to merge this soon so it can go into 3.13.

Copy link
Contributor

@ncoghlan ncoghlan left a comment

Choose a reason for hiding this comment

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

Getting rid of the hardcoded check LGTM, although I am now mildly curious as to how the hardcoding ever came to be :)

@@ -0,0 +1,3 @@
Fix constructor of :mod:`ast` nodes with custom ``_attributes``. Previously,
Copy link
Member

Choose a reason for hiding this comment

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

Previously? Isn't it still raising DeprecationWarning?

Copy link
Member Author

Choose a reason for hiding this comment

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

It still raises a DeprecationWarning if you pass attributes the class doesn't know about. But now it no longer raises a warning if you set _attributes on a custom subclass and pass those attributes.

@JelleZijlstra JelleZijlstra enabled auto-merge (squash) July 11, 2024 13:19
@JelleZijlstra JelleZijlstra merged commit 58e8cf2 into python:main Jul 11, 2024
36 checks passed
@miss-islington-app
Copy link

Thanks @JelleZijlstra for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

@miss-islington-app
Copy link

Sorry, @JelleZijlstra, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 58e8cf2bb61f82df9eabd1209fe5e3d146e4c8cd 3.13

@JelleZijlstra JelleZijlstra deleted the astattr branch July 11, 2024 15:26
JelleZijlstra added a commit to JelleZijlstra/cpython that referenced this pull request Jul 11, 2024
…nstead of hardcoding attributes (pythonGH-121334)

(cherry picked from commit 58e8cf2)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
@bedevere-app
Copy link

bedevere-app bot commented Jul 11, 2024

GH-121625 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label Jul 11, 2024
JelleZijlstra added a commit that referenced this pull request Jul 11, 2024
… of hardcoding attributes (GH-121334) (#121625)

(cherry picked from commit 58e8cf2)
noahbkim pushed a commit to hudson-trading/cpython that referenced this pull request Jul 11, 2024
estyxx pushed a commit to estyxx/cpython that referenced this pull request Jul 17, 2024
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.

4 participants