Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 737470e

Browse files
wkschwartzilevkivskyi
authored andcommitted
Refs #5383: Document that aliasing dataclass fails (#5387)
This documentation is a temporary solution. It should be altered or removed when #5383 is fixed.
1 parent 413eb55 commit 737470e

1 file changed

Lines changed: 35 additions & 1 deletion

File tree

docs/source/additional_features.rst

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,43 @@ class can be used:
6868
For more information see `official docs <https://docs.python.org/3/library/dataclasses.html>`_
6969
and `PEP 557 <https://www.python.org/dev/peps/pep-0557/>`_.
7070

71-
**Note:** Some functions in the ``dataclasses`` module, such as ``replace()`` and ``asdict()``,
71+
Caveats/Known Issues
72+
====================
73+
74+
Some functions in the ``dataclasses`` module, such as ``replace()`` and ``asdict()``,
7275
have imprecise (too permissive) types. This will be fixed in future releases.
7376

77+
Mypy does not yet recognize aliases of ``dataclasses.dataclass``, and will
78+
probably never recognize dynamically computed decorators. The following examples
79+
do **not** work:
80+
81+
.. code-block:: python
82+
83+
from dataclasses import dataclass
84+
85+
dataclass_alias = dataclass
86+
def dataclass_wrapper(cls):
87+
return dataclass(cls)
88+
89+
@dataclass_alias
90+
class AliasDecorated:
91+
"""
92+
Mypy doesn't recognize this as a dataclass because it is decorated by an
93+
alias of `dataclass` rather than by `dataclass` itself.
94+
"""
95+
attribute: int
96+
97+
@dataclass_wrapper
98+
class DynamicallyDecoarted:
99+
"""
100+
Mypy doesn't recognize this as a dataclass because it is decorated by a
101+
function returning `dataclass` rather than by `dataclass` itself.
102+
"""
103+
attribute: int
104+
105+
AliasDecorated(attribute=1) # error: Unexpected keyword argument
106+
DynamicallyDecoarted(attribute=1) # error: Unexpected keyword argument
107+
74108
.. _attrs_package:
75109

76110
The attrs package

0 commit comments

Comments
 (0)