Skip to content

Regression involving overloaded classmethods #7926

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
msullivan opened this issue Nov 11, 2019 · 1 comment · Fixed by #7937
Closed

Regression involving overloaded classmethods #7926

msullivan opened this issue Nov 11, 2019 · 1 comment · Fixed by #7937
Assignees
Labels
bug mypy got something wrong false-positive mypy gave an error on correct code priority-1-normal

Comments

@msullivan
Copy link
Collaborator

The following fails now:

from typing import Optional, Type, TypeVar, overload, Union

Gid = int

A = TypeVar("A", bound="Assoc")

class Assoc:

    @overload
    @classmethod
    def delete(cls, gid, gid2):
        # type: (Type[A], Gid, Gid) -> Optional[int]
        pass

    @overload  # noqa
    @classmethod
    def delete(cls, gid, gid2=None):
        # type: (Type[A], A, None) -> Optional[int]
        pass

    @classmethod  # noqa
    def delete(cls, gid, gid2=None):
        # type: (Type[A], Union[A, Gid], Optional[Gid]) -> Optional[int]
        pass


def delete_assoc(assoc_type):
    # type: (Type[Assoc]) -> None
    assoc = assoc_type()
    assoc.delete(10, 20)

def delete_assoc2(assoc):
    # type: (Assoc) -> None
    assoc.delete(10, 20)

with errors in the delete_assoc functions saying Invalid self argument "Assoc" to attribute function "delete" with type "Callable[[Type[A], int, int], Optional[int]]".

Looks like this was introduced in #7860.

@msullivan msullivan added bug mypy got something wrong priority-1-normal false-positive mypy gave an error on correct code labels Nov 11, 2019
@ilevkivskyi
Copy link
Member

Oh, this one is pretty annoying, I always forget a class method can be a Decorator or an OverloadedFuncDef. Should be easy to fix.

ilevkivskyi added a commit that referenced this issue Nov 12, 2019
)

Fixes #7926

The fix is straightforward, pass `is_classmethod` where it should be. Also wrap self argument in `Type[...]` only once, not on every iteration over overload items.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong false-positive mypy gave an error on correct code priority-1-normal
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants