google-deepmind / chex

https://chex.readthedocs.io
Apache License 2.0
747 stars 43 forks source link

`chex.dataclass` wrapper causes type error: Expected no arguments to dataclass constructor #321

Open carlosgmartin opened 8 months ago

carlosgmartin commented 8 months ago

Applying the chex.dataclass wrapper to a class yields the following error:

import chex

@chex.dataclass(frozen=True)
class Class:
    x: int

Class(4)
$ pyright --version
pyright 1.1.337
$ python3 --version
Python 3.11.6
$ python3 -c "import chex; print(chex.__version__)"
0.1.85
$ pyright test.py
/Users/user/Desktop/test.py
  /Users/user/Desktop/test.py:7:1 - error: Expected no arguments to "Class" constructor (reportGeneralTypeIssues)
1 error, 0 warnings, 0 informations 

https://github.com/microsoft/pyright/issues/6536#issuecomment-1826087060

This is a bug in the chex library. The chex.dataclass decorator has no type annotations despite the fact that the package contains a "py.typed" marker file.

https://github.com/microsoft/pyright/issues/6536#issuecomment-1862080880

I recommend looking at the stdlib dataclass class in the typeshed dataclass.pyi stub.

https://github.com/python/typeshed/blob/main/stdlib/dataclasses.pyi

Artur-Galstyan commented 3 weeks ago

This issue still persists. The only way to handle this is to add a # pyright: ignore at the end of the line, which is obviously not the right solution here.