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

bpo-33141: Have dataclasses.Field pass through __set_name__ to any default descriptor. #6260

Merged

Conversation

ericvsmith
Copy link
Member

@ericvsmith ericvsmith commented Mar 26, 2018

@ericvsmith
Copy link
Member Author

This is part of PEP 487 and the descriptor protocol.

@ericvsmith ericvsmith merged commit de7a2f0 into python:master Mar 26, 2018
@miss-islington
Copy link
Contributor

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

@ericvsmith ericvsmith deleted the bpo-33141-descriptor-__set_name__ branch March 26, 2018 17:29
@bedevere-bot
Copy link

GH-6261 is a backport of this pull request to the 3.7 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Mar 26, 2018
…fault argument. (pythonGH-6260)

This is part of PEP 487 and the descriptor protocol.
(cherry picked from commit de7a2f0)

Co-authored-by: Eric V. Smith <ericvsmith@users.noreply.github.com>
miss-islington added a commit that referenced this pull request Mar 26, 2018
…fault argument. (GH-6260)

This is part of PEP 487 and the descriptor protocol.
(cherry picked from commit de7a2f0)

Co-authored-by: Eric V. Smith <ericvsmith@users.noreply.github.com>
# the default value, so the end result is a descriptor that had
# __set_name__ called on it at the right time.
def __set_name__(self, owner, name):
func = getattr(self.default, '__set_name__', None)
Copy link
Member

Choose a reason for hiding this comment

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

I got here late, but shouldn't this check for __set_name__ on type(self.default) instead? That's how dunder protocols usually work, and it's also how typeobject.c itself implements __set_name__ (using _PyObject_LookupSpecial).

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch, thanks. I've created https://bugs.python.org/issue33175.

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.

5 participants