chex icon indicating copy to clipboard operation
chex copied to clipboard

Typing issue with chex.dataclass

Open wookayin opened this issue 2 years ago • 2 comments

Static type checkers like pyright, mypy, etc. will think chex.dataclass-decorated dataclass has a constructor with no parameters.

Example:

@chex.dataclass(frozen=True)
class Foo:
    a: int
    b: int
image

However, Foo() is not a valid call: A legitimate call would be something like Foo(a=1, b=2). This does not agree with static type checker's analysis.

Compare the behavior with built-in dataclass:

image

wookayin avatar Apr 15 '22 08:04 wookayin

This can be solved with dataclass_transform. I can send a PR if desired.

tmke8 avatar Aug 20 '22 09:08 tmke8

Hi @wookayin, thanks for reporting this issue.

@thomkeh that would be very helpful! I'm happy to review your PR.

hbq1 avatar Sep 01 '22 10:09 hbq1