[Python-checkins] bpo-33116: Add 'Field' to dataclasses.__all__. (GH-6182) (GH-6183)

Eric V. Smith webhook-mailer at python.org
Wed Mar 21 17:44:26 EDT 2018

commit: 4ddc99d15963b0374f9dbfd57f14e6194ad65669
branch: 3.7
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: Eric V. Smith <ericvsmith at users.noreply.github.com>
date: 2018-03-21T17:44:23-04:00

bpo-33116: Add 'Field' to dataclasses.__all__. (GH-6182) (GH-6183)

- Add missing 'Field' to __all__.
- Improve tests to catch this.
(cherry picked from commit 8e4560a9da6a02aa157dd7df8bd0be0d258c0a73)

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

A Misc/NEWS.d/next/Library/2018-03-21-16-52-26.bpo-33116.Tvzerj.rst
M Lib/dataclasses.py
M Lib/test/test_dataclasses.py

diff --git a/Lib/dataclasses.py b/Lib/dataclasses.py
index d61643249148..41b5b5da325c 100644
--- a/Lib/dataclasses.py
+++ b/Lib/dataclasses.py
@@ -5,6 +5,7 @@
 __all__ = ['dataclass',
+           'Field',
@@ -513,7 +514,7 @@ def _get_field(cls, a_name, a_type):
     #  and InitVars are also returned, but marked as such (see
     #  f._field_type).
-    # If the default value isn't derived from field, then it's
+    # If the default value isn't derived from Field, then it's
     #  only a normal default value.  Convert it to a Field().
     default = getattr(cls, a_name, MISSING)
     if isinstance(default, Field):
diff --git a/Lib/test/test_dataclasses.py b/Lib/test/test_dataclasses.py
index 9b5aad25745f..69ace36c2c58 100755
--- a/Lib/test/test_dataclasses.py
+++ b/Lib/test/test_dataclasses.py
@@ -1,7 +1,8 @@
-from dataclasses import (
-    dataclass, field, FrozenInstanceError, fields, asdict, astuple,
-    make_dataclass, replace, InitVar, Field, MISSING, is_dataclass,
+# Deliberately use "from dataclasses import *".  Every name in __all__
+# is tested, so they all must be present.  This is a way to catch
+# missing ones.
+from dataclasses import *
 import pickle
 import inspect
diff --git a/Misc/NEWS.d/next/Library/2018-03-21-16-52-26.bpo-33116.Tvzerj.rst b/Misc/NEWS.d/next/Library/2018-03-21-16-52-26.bpo-33116.Tvzerj.rst
new file mode 100644
index 000000000000..90072d8e3030
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2018-03-21-16-52-26.bpo-33116.Tvzerj.rst
@@ -0,0 +1 @@
+Add 'Field' to dataclasses.__all__.

More information about the Python-checkins mailing list