Skip to content

Commit 4ddc99d

Browse files
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 8e4560a) Co-authored-by: Eric V. Smith <[email protected]>
1 parent f5625d5 commit 4ddc99d

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

Lib/dataclasses.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
__all__ = ['dataclass',
77
'field',
8+
'Field',
89
'FrozenInstanceError',
910
'InitVar',
1011
'MISSING',
@@ -513,7 +514,7 @@ def _get_field(cls, a_name, a_type):
513514
# and InitVars are also returned, but marked as such (see
514515
# f._field_type).
515516

516-
# If the default value isn't derived from field, then it's
517+
# If the default value isn't derived from Field, then it's
517518
# only a normal default value. Convert it to a Field().
518519
default = getattr(cls, a_name, MISSING)
519520
if isinstance(default, Field):

Lib/test/test_dataclasses.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
from dataclasses import (
2-
dataclass, field, FrozenInstanceError, fields, asdict, astuple,
3-
make_dataclass, replace, InitVar, Field, MISSING, is_dataclass,
4-
)
1+
# Deliberately use "from dataclasses import *". Every name in __all__
2+
# is tested, so they all must be present. This is a way to catch
3+
# missing ones.
4+
5+
from dataclasses import *
56

67
import pickle
78
import inspect
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add 'Field' to dataclasses.__all__.

0 commit comments

Comments
 (0)