mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
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:
parent
4573820d2a
commit
7389fd935c
3 changed files with 47 additions and 0 deletions
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue