Skip to content

Dataclass classmethods don't work #5974

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
catern opened this issue Nov 29, 2018 · 4 comments
Closed

Dataclass classmethods don't work #5974

catern opened this issue Nov 29, 2018 · 4 comments
Labels
false-positive mypy gave an error on correct code priority-1-normal topic-plugins The plugin API and ideas for new plugins

Comments

@catern
Copy link

catern commented Nov 29, 2018

On master and 0.630, the following code fails with error: Incompatible return value type (got "Foo", expected "T"):

from dataclasses import dataclass
import typing as t

T = t.TypeVar('T', bound="Foo")
@dataclass
class Foo:
    @classmethod
    def make(cls: t.Type[T]) -> T:
        return cls()

If I remove the dataclass annotation, it works fine.

@JelleZijlstra JelleZijlstra added priority-1-normal topic-plugins The plugin API and ideas for new plugins false-positive mypy gave an error on correct code labels Nov 29, 2018
@JelleZijlstra
Copy link
Member

cc @euresti since this seems to be due to the dataclasses plugin.

@euresti
Copy link
Contributor

euresti commented Nov 29, 2018

Hmm. In my code I usually annotate this as:

@dataclass
class Foo:
    @classmethod
    def make(cls) -> 'Foo':
        return cls()

But I hardly use inheritance.

Also I don't know why the decorator would break it. Does it happens with @attr.s?

@ilevkivskyi
Copy link
Member

This works on master

@ilevkivskyi
Copy link
Member

Also this is a duplicate of #5263 that was fixed by #5646

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
false-positive mypy gave an error on correct code priority-1-normal topic-plugins The plugin API and ideas for new plugins
Projects
None yet
Development

No branches or pull requests

4 participants