Skip to content

Add support for dataclasses #4792

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

Closed
gwk opened this issue Mar 26, 2018 · 5 comments · Fixed by #5010
Closed

Add support for dataclasses #4792

gwk opened this issue Mar 26, 2018 · 5 comments · Fixed by #5010

Comments

@gwk
Copy link

gwk commented Mar 26, 2018

I have added preliminary support for dataclasses in python/typeshed#1944.

These seem to work for declarations, but not for instantiation. For example:

@dataclass
class D0:
  x: int

d0 = D0(x=0)

The constructor is erroneously flagged, and points to the __init__ annotation for object:

error: Unexpected keyword argument "x" for "D0"
/Users/gwk/work/python/mypy/typeshed/stdlib/3/builtins.pyi:38:5: note: "D0" defined here

It appears that we need to teach mypy about dataclasses more deeply.

@JelleZijlstra
Copy link
Member

Yes, we will definitely need a mypy plugin to support dataclasses. It can probably be somewhat similar to the existing one for attrs.

@JelleZijlstra JelleZijlstra changed the title Python 3.7 dataclasses may require additional mypy support Add plugin to support dataclasses in 3.7 Mar 26, 2018
@ilevkivskyi
Copy link
Member

It is good that you opened this issue, we definitely wanted to have a dedicated support for this, so now we have a place to track it. (Btw, I wanted to do this.)

@ilevkivskyi ilevkivskyi changed the title Add plugin to support dataclasses in 3.7 Add support for dataclasses Mar 26, 2018
@ilevkivskyi ilevkivskyi self-assigned this Mar 26, 2018
@gwk
Copy link
Author

gwk commented Mar 26, 2018 via email

@gwk
Copy link
Author

gwk commented Mar 27, 2018

One other point: I backported dataclasses to 3.6 as a third party module inside of a general-purpose utility package that I maintain. I wonder, will it be possible/easy to get this dataclass plugin to recognize that module for < 3.7?

@ilevkivskyi
Copy link
Member

Yes.

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

Successfully merging a pull request may close this issue.

3 participants