Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
carlosgmartin opened this issue Nov 24, 2023 · 1 comment

Comments

@carlosgmartin
Copy link

carlosgmartin commented Nov 24, 2023

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 

microsoft/pyright#6536 (comment)

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.

microsoft/pyright#6536 (comment)

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
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants