[Python-checkins] bpo-33517: dataclasses: Add the field type to Field repr (GH-6858)

Miss Islington (bot) webhook-mailer at python.org
Tue May 15 09:01:54 EDT 2018


https://github.com/python/cpython/commit/5c7e079158db869c9ede1ac9b5b9735091d3ffb6
commit: 5c7e079158db869c9ede1ac9b5b9735091d3ffb6
branch: 3.7
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2018-05-15T06:01:51-07:00
summary:

bpo-33517: dataclasses: Add the field type to Field repr (GH-6858)

(cherry picked from commit 01abc6ec3a61769c55ee86834a432fb97801d28f)

Co-authored-by: Eric V. Smith <ericvsmith at users.noreply.github.com>

files:
M Lib/dataclasses.py

diff --git a/Lib/dataclasses.py b/Lib/dataclasses.py
index 2ce6a02dcd7a..0f9041604a5a 100644
--- a/Lib/dataclasses.py
+++ b/Lib/dataclasses.py
@@ -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.
@@ -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



More information about the Python-checkins mailing list