-
-
Notifications
You must be signed in to change notification settings - Fork 32.7k
gh-116021: Deprecate support for instantiating abstract AST nodes #137865
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
base: main
Are you sure you want to change the base?
gh-116021: Deprecate support for instantiating abstract AST nodes #137865
Conversation
check(_ast.AST(), size('P')) | ||
with self.assertWarns(DeprecationWarning): | ||
check(_ast.AST(), size('P')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should probably be rewritten, but I'm not sure I understand the goal of this test well enough to do that. Suggestions welcome!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's to check that objects in Python/
have the correct types. I don't know why it's actually in test_sys
though. I think we should split this test and move each check to the module it belongs (ast.AST's size should be checked in test_ast).
For now, leave it here. A separate issue should be opened.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be easier to have a module function checking if a node is abstract? say _ast.is_abstract(node)
(in the C module, not the Python module). That way we don't need an additional method on AST objects (which could be shadowed).
check(_ast.AST(), size('P')) | ||
with self.assertWarns(DeprecationWarning): | ||
check(_ast.AST(), size('P')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's to check that objects in Python/
have the correct types. I don't know why it's actually in test_sys
though. I think we should split this test and move each check to the module it belongs (ast.AST's size should be checked in test_ast).
For now, leave it here. A separate issue should be opened.
Parser/asdl_c.py
Outdated
@@ -1443,6 +1458,23 @@ def visitModule(self, mod): | |||
return result; | |||
} | |||
|
|||
/* Helper for checking if a node class is abstract in the tests. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should use clinic here, but this would create a new file as we don't use it at all. Maybe we can do it in a follow-up PR though.
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Demonstration:
This tracks which AST nodes are abstract using an internal set that gets built during node type initialization. I tried a few different approaches, and this seemed the simplest. A nice thing about this approach is that the check for abstract-ness depends on the exact node type, so this avoids most inheritance subtleties that could interfere with existing user-defined subclasses.
📚 Documentation preview 📚: https://cpython-previews--137865.org.readthedocs.build/