Removed isdataclass().

This commit is contained in:
Eric V. Smith 2017-12-01 07:57:12 -05:00
parent 87d7bd9fc3
commit dba3334a07
1 changed files with 22 additions and 4 deletions

View File

@ -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
Post-History: 08-Sep-2017, 25-Nov-2017, 30-Nov-2017, 01-Dec-2017
Notice for Reviewers
====================
@ -570,9 +570,6 @@ Module level helper functions
Raises ``TypeError`` if ``instance`` is not a Data Class instance.
- ``isdataclass(instance)``: Returns ``True`` if ``instance`` is an
instance of a Data Class, otherwise returns ``False``.
- ``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
@ -798,6 +795,27 @@ decision is to disallow the 3 known built-in mutable types: list,
dict, and set. For a complete discussion of this and other options,
see [#]_.
Providing isdataclass()
-----------------------
An earlier version of this PEP defined an ``isdataclass(obj)`` helper
function. However, there was no known use case for this, and there
was debate on whether it should return ``True`` for instances or
classes or both. In the end, ``isdataclass()`` was removed.
The supported way of writing a function that checks if an object is a
dataclass instance or class is::
def isdataclass(obj):
try:
dataclasses.fields(obj)
return True
except TypeError:
return False
If needed, a further check for ``isinstance(obj, type)`` can be added
to discern if ``obj`` is a class.
Examples
========