bpo-33175: dataclasses should look up __set_name__ on class, not instance (GH-6305)

This commit is contained in:
Eric V. Smith 2018-03-29 11:07:48 -04:00 committed by GitHub
parent b9e7fe38a0
commit 521995205a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 7 deletions

View file

@ -248,11 +248,11 @@ class Field:
# 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)
func = getattr(type(self.default), '__set_name__', None)
if func:
# There is a __set_name__ method on the descriptor,
# call it.
func(owner, name)
func(self.default, owner, name)
class _DataclassParams: