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 8e4560a9da
)
Co-authored-by: Eric V. Smith <ericvsmith@users.noreply.github.com>
This commit is contained in:
parent
f5625d58fa
commit
4ddc99d159
|
@ -5,6 +5,7 @@ import inspect
|
||||||
|
|
||||||
__all__ = ['dataclass',
|
__all__ = ['dataclass',
|
||||||
'field',
|
'field',
|
||||||
|
'Field',
|
||||||
'FrozenInstanceError',
|
'FrozenInstanceError',
|
||||||
'InitVar',
|
'InitVar',
|
||||||
'MISSING',
|
'MISSING',
|
||||||
|
@ -513,7 +514,7 @@ def _get_field(cls, a_name, a_type):
|
||||||
# and InitVars are also returned, but marked as such (see
|
# and InitVars are also returned, but marked as such (see
|
||||||
# f._field_type).
|
# 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().
|
# only a normal default value. Convert it to a Field().
|
||||||
default = getattr(cls, a_name, MISSING)
|
default = getattr(cls, a_name, MISSING)
|
||||||
if isinstance(default, Field):
|
if isinstance(default, Field):
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
from dataclasses import (
|
# Deliberately use "from dataclasses import *". Every name in __all__
|
||||||
dataclass, field, FrozenInstanceError, fields, asdict, astuple,
|
# is tested, so they all must be present. This is a way to catch
|
||||||
make_dataclass, replace, InitVar, Field, MISSING, is_dataclass,
|
# missing ones.
|
||||||
)
|
|
||||||
|
from dataclasses import *
|
||||||
|
|
||||||
import pickle
|
import pickle
|
||||||
import inspect
|
import inspect
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Add 'Field' to dataclasses.__all__.
|
Loading…
Reference in New Issue