Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion docs/source/additional_features.rst
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,43 @@ class can be used:
For more information see `official docs <https://docs.python.org/3/library/dataclasses.html>`_
and `PEP 557 <https://www.python.org/dev/peps/pep-0557/>`_.

**Note:** Some functions in the ``dataclasses`` module, such as ``replace()`` and ``asdict()``,
Caveats/Known Issues
====================

Some functions in the ``dataclasses`` module, such as ``replace()`` and ``asdict()``,
have imprecise (too permissive) types. This will be fixed in future releases.

Mypy does not yet recognize aliases of ``dataclasses.dataclass``, and will
probably never recognize dynamically computed decorators. The following examples
do **not** work:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would actually skip the examples, the textual formulation is already clear (except maybe the dynamically computed decorators).


.. code-block:: python

from dataclasses import dataclass

dataclass_alias = dataclass
def dataclass_wrapper(cls):
return dataclass(cls)

@dataclass_alias
class AliasDecorated:
"""
Mypy doesn't recognize this as a dataclass because it is decorated by an
alias of `dataclass` rather than by `dataclass` itself.
"""
attribute: int

@dataclass_wrapper
class DynamicallyDecoarted:
"""
Mypy doesn't recognize this as a dataclass because it is decorated by a
function returning `dataclass` rather than by `dataclass` itself.
"""
attribute: int

AliasDecorated(attribute=1) # error: Unexpected keyword argument
DynamicallyDecoarted(attribute=1) # error: Unexpected keyword argument

.. _attrs_package:

The attrs package
Expand Down