Dataclasses: No overload variant of "asdict" matches argument type "Self" [call-overload]
when deciding decorator conditionally
#17242
Labels
bug
mypy got something wrong
Bug Report
Mypy raises a false positive for
dataclass.asdict
(No overload variant of "asdict" matches argument type "Self" [call-overload]
) on the very specific circumstances:dataclass
is decided based on a condition (e.g. Python version)datalcasses.asdict
method is called from a method that uses PEP 673's Self Type.I also noted a similar problem occurs for
dataclasses.replace
:Value of type variable "_DataclassT" of "replace" cannot be "Self" [type-var]
.To Reproduce
Gist URL: https://gist.github.com/mypy-play/70b801fbe15391f0750be8f6c403fdf4
Playground URL: https://mypy-play.net/?mypy=latest&python=3.12&flags=show-error-context%2Cstrict&gist=70b801fbe15391f0750be8f6c403fdf4
Expected Behavior
There should be no false negative.
The program works fine in runtime:
Actual Behavior
Your Environment
--show-error-context
,--strict
mypy.ini
(and other config files):The text was updated successfully, but these errors were encountered: