Skip to content

bpo-39981: Default values for AST nodes #19031

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 5 commits into from

Conversation

isidentical
Copy link
Member

@isidentical isidentical commented Mar 16, 2020

@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@pablogsal
Copy link
Member

Some initial comments, without commenting on the approach itself.

@serhiy-storchaka should confirm that he is happy with this approach as he was working on some related functionality.

Lib/ast.py Outdated
@@ -101,8 +102,20 @@ def _convert(node):
return _convert_signed_num(node)
return _convert(node_or_string)

@lru_cache
def _field_defaults(node_type):
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand this function. When we set the node_type._field_defaults we could already place None or [] in there instead of this intermediary "?" and "*".

Copy link
Member Author

Choose a reason for hiding this comment

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

I dont think so, at least for lists. We are keeping _field_defaults as the same way we keep _fields, arrays of const char pointers. And then we construct a tuple from them and intern the values. I dont think it would be practical to do this with the original values.

Copy link
Member

@pablogsal pablogsal Mar 17, 2020

Choose a reason for hiding this comment

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

I don't fully understand the problem. What is wrong with having _field_defaults as a list of the defaults themselves? When constructing the _field_defaults tuple you can do this logic already and populate them with None or the empty list or whatever, no?

For instance, in the make_type function you could set the defaults in the tuple instead of interning the strings.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, that makes sense. Do you have an idea about what we should put if there is no field default, I think Ellipsis should work.

Copy link
Member

Choose a reason for hiding this comment

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

You don't need that if you use a dictionary instead of a tuple

@isidentical isidentical added the type-feature A feature request or enhancement label Mar 17, 2020
@isidentical
Copy link
Member Author

I have made the requested changes; please review again

@bedevere-bot
Copy link

Thanks for making the requested changes!

@pablogsal: please review the changes made to this pull request.

@bedevere-bot bedevere-bot requested a review from pablogsal March 17, 2020 07:21
@isidentical isidentical force-pushed the bpo-39981 branch 2 times, most recently from 9cdb15f to 0cbc2a8 Compare March 18, 2020 09:39
@isidentical
Copy link
Member Author

@serhiy-storchaka It would be awesome to have your review / thoughts on this before alpha cut.

@isidentical
Copy link
Member Author

Closing this in favor of #21417

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting change review type-feature A feature request or enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants