summaryrefslogtreecommitdiffstats
path: root/Lib/dataclasses.py
diff options
context:
space:
mode:
authorEric V. Smith <ericvsmith@users.noreply.github.com>2018-05-15 12:36:21 (GMT)
committerGitHub <noreply@github.com>2018-05-15 12:36:21 (GMT)
commit01abc6ec3a61769c55ee86834a432fb97801d28f (patch)
tree43a34e99cb7d6145b0ec8e5a05f0170766e520b6 /Lib/dataclasses.py
parent540162260c09cf58c7477d4b94941e6908283970 (diff)
downloadcpython-01abc6ec3a61769c55ee86834a432fb97801d28f.zip
cpython-01abc6ec3a61769c55ee86834a432fb97801d28f.tar.gz
cpython-01abc6ec3a61769c55ee86834a432fb97801d28f.tar.bz2
bpo-33517: dataclasses: Add the field type to Field repr (GH-6858)
Diffstat (limited to 'Lib/dataclasses.py')
-rw-r--r--Lib/dataclasses.py14
1 files changed, 10 insertions, 4 deletions
diff --git a/Lib/dataclasses.py b/Lib/dataclasses.py
index 2ce6a02..0f90416 100644
--- a/Lib/dataclasses.py
+++ b/Lib/dataclasses.py
@@ -166,9 +166,14 @@ MISSING = _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.
@@ -237,7 +242,8 @@ class Field:
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