mypy icon indicating copy to clipboard operation
mypy copied to clipboard

Spurious error for dataclass(slots=True)

Open hauntsaninja opened this issue 1 year ago • 0 comments

I get a spurious top/fid/yod.py:6: error: "File" both defines "__slots__" and is used with "slots=True" [misc].

Similar to https://github.com/python/mypy/issues/11821 / https://github.com/python/mypy/issues/11827, but a more involved repro. I found it not trivial to minimise the repro beyond the following script:

rm -rf top

mkdir top
echo 'from . import fid' > top/__init__.py

mkdir top/fid
echo 'from .dug import X
from .fun import *
from .yod import File' > top/fid/__init__.py

echo 'from dataclasses import dataclass
import top.fid.fun as T
@dataclass
class X(T.MB): ...' > top/fid/dug.py

echo 'from dataclasses import dataclass
from top import does_not_exist  # type: ignore
@dataclass
class MB:
    ...' > top/fid/fun.py

echo 'from dataclasses import dataclass
import top
@dataclass(slots=True)
class File:
    path: str' > top/fid/yod.py

mypy top

cc @sobolevn in case you're interested, since you fixed the previous report :-)

hauntsaninja avatar Apr 13 '24 03:04 hauntsaninja