Skip to content

Commit 01abc6e

Browse files
authored
bpo-33517: dataclasses: Add the field type to Field repr (GH-6858)
1 parent 5401622 commit 01abc6e

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

Lib/dataclasses.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,14 @@ class _MISSING_TYPE:
166166
_EMPTY_METADATA = types.MappingProxyType({})
167167

168168
# Markers for the various kinds of fields and pseudo-fields.
169-
_FIELD = object() # An actual field.
170-
_FIELD_CLASSVAR = object() # Not a field, but a ClassVar.
171-
_FIELD_INITVAR = object() # Not a field, but an InitVar.
169+
class _FIELD_BASE:
170+
def __init__(self, name):
171+
self.name = name
172+
def __repr__(self):
173+
return self.name
174+
_FIELD = _FIELD_BASE('_FIELD')
175+
_FIELD_CLASSVAR = _FIELD_BASE('_FIELD_CLASSVAR')
176+
_FIELD_INITVAR = _FIELD_BASE('_FIELD_INITVAR')
172177

173178
# The name of an attribute on the class where we store the Field
174179
# objects. Also used to check if a class is a Data Class.
@@ -237,7 +242,8 @@ def __repr__(self):
237242
f'repr={self.repr!r},'
238243
f'hash={self.hash!r},'
239244
f'compare={self.compare!r},'
240-
f'metadata={self.metadata!r}'
245+
f'metadata={self.metadata!r},'
246+
f'_field_type={self._field_type}'
241247
')')
242248

243249
# This is used to support the PEP 487 __set_name__ protocol in the

0 commit comments

Comments
 (0)