Make type information on make_dataclass() optional.
This commit is contained in:
parent
a790b3821c
commit
b78c28504e
21
pep-0557.rst
21
pep-0557.rst
|
@ -6,7 +6,7 @@ Type: Standards Track
|
|||
Content-Type: text/x-rst
|
||||
Created: 02-Jun-2017
|
||||
Python-Version: 3.7
|
||||
Post-History: 08-Sep-2017, 25-Nov-2017, 30-Nov-2017, 01-Dec-2017, 02-Dec-2017
|
||||
Post-History: 08-Sep-2017, 25-Nov-2017, 30-Nov-2017, 01-Dec-2017, 02-Dec-2017, 06-Jan-2018
|
||||
Resolution: https://mail.python.org/pipermail/python-dev/2017-December/151034.html
|
||||
|
||||
Notice for Reviewers
|
||||
|
@ -576,15 +576,19 @@ Module level helper functions
|
|||
- ``make_dataclass(cls_name, fields, *, bases=(), namespace=None)``:
|
||||
Creates a new Data Class with name ``cls_name``, fields as defined
|
||||
in ``fields``, base classes as given in ``bases``, and initialized
|
||||
with a namespace as given in ``namespace``. This function is not
|
||||
strictly required, because any Python mechanism for creating a new
|
||||
class with ``__annotations__`` can then apply the ``dataclass``
|
||||
function to convert that class to a Data Class. This function is
|
||||
provided as a convenience. For example::
|
||||
with a namespace as given in ``namespace``. ``fields`` is an
|
||||
iterable whose elements are either ``name``, ``(name, type)``, or
|
||||
``(name, type, Field)``. If just ``name`` is supplied,
|
||||
``typing.Any`` is used for ``type``. This function is not strictly
|
||||
required, because any Python mechanism for creating a new class with
|
||||
``__annotations__`` can then apply the ``dataclass`` function to
|
||||
convert that class to a Data Class. This function is provided as a
|
||||
convenience. For example::
|
||||
|
||||
C = make_dataclass('C',
|
||||
[('x', int),
|
||||
('y', int, field(default=5))],
|
||||
'y',
|
||||
('z', int, field(default=5))],
|
||||
namespace={'add_one': lambda self: self.x + 1})
|
||||
|
||||
Is equivalent to::
|
||||
|
@ -592,7 +596,8 @@ Module level helper functions
|
|||
@dataclass
|
||||
class C:
|
||||
x: int
|
||||
y: int = 5
|
||||
y: 'typing.Any'
|
||||
z: int = 5
|
||||
|
||||
def add_one(self):
|
||||
return self.x + 1
|
||||
|
|
Loading…
Reference in New Issue