bpo-33100: Dataclasses now handles __slots__ and default values correctly. (GH-6152)

If the class has a member that's a MemberDescriptorType, it's not a default value, it's from that member being in __slots__.
This commit is contained in:
Eric V. Smith 2018-03-19 21:07:51 -04:00 committed by GitHub
parent 4573820d2a
commit 7389fd935c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 47 additions and 0 deletions

View file

@ -519,6 +519,9 @@ def _get_field(cls, a_name, a_type):
if isinstance(default, Field):
f = default
else:
if isinstance(default, types.MemberDescriptorType):
# This is a field in __slots__, so it has no default value.
default = MISSING
f = field(default=default)
# Assume it's a normal field until proven otherwise.