equinox icon indicating copy to clipboard operation
equinox copied to clipboard

MyPy doesn't understand Module

Open NeilGirdhar opened this issue 1 year ago • 1 comments

MyPy only looks at the first definition of Module, so it doesn't see the redefinition in TYPE_CHECKING:

import dataclasses
from typing import TYPE_CHECKING, dataclass_transform


class _ModuleMeta(type):  # This needs to be in a if not TYPE_CHECKING block.
    pass


if TYPE_CHECKING:
    @dataclass_transform(field_specifiers=(dataclasses.field,))
    class _ModuleMeta(type):
        pass


class Module(metaclass=_ModuleMeta):
    pass


class A(Module):
    x: int


A(1)  # MyPy doesn't realize that A is a dataclass

NeilGirdhar avatar Aug 29 '24 13:08 NeilGirdhar

Ah -- this must be a mypy vs pyright difference.

Happy to take a PR on this :)

patrick-kidger avatar Aug 29 '24 16:08 patrick-kidger

Fixed in #822 :)

patrick-kidger avatar Aug 31 '24 10:08 patrick-kidger