Skip to content

Commit

Permalink
bpo-33517: dataclasses: Add the field type to Field repr (GH-6858)
Browse files Browse the repository at this point in the history
(cherry picked from commit 01abc6e)

Co-authored-by: Eric V. Smith <ericvsmith@users.noreply.github.com>
  • Loading branch information
miss-islington and ericvsmith committed May 15, 2018
1 parent 28ff86e commit 5c7e079
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions Lib/dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,14 @@ class _MISSING_TYPE:
_EMPTY_METADATA = types.MappingProxyType({})

# Markers for the various kinds of fields and pseudo-fields.
_FIELD = object() # An actual field.
_FIELD_CLASSVAR = object() # Not a field, but a ClassVar.
_FIELD_INITVAR = object() # Not a field, but an InitVar.
class _FIELD_BASE:
def __init__(self, name):
self.name = name
def __repr__(self):
return self.name
_FIELD = _FIELD_BASE('_FIELD')
_FIELD_CLASSVAR = _FIELD_BASE('_FIELD_CLASSVAR')
_FIELD_INITVAR = _FIELD_BASE('_FIELD_INITVAR')

# The name of an attribute on the class where we store the Field
# objects. Also used to check if a class is a Data Class.
Expand Down Expand Up @@ -237,7 +242,8 @@ def __repr__(self):
f'repr={self.repr!r},'
f'hash={self.hash!r},'
f'compare={self.compare!r},'
f'metadata={self.metadata!r}'
f'metadata={self.metadata!r},'
f'_field_type={self._field_type}'
')')

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

0 comments on commit 5c7e079

Please sign in to comment.