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

Regression involving generic class methods #7925

Closed
msullivan opened this issue Nov 11, 2019 · 1 comment · Fixed by #7938
Closed

Regression involving generic class methods #7925

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

Comments

@msullivan
Copy link
Collaborator

Distilled from an issue in S:

from typing import Generic, List, Optional, TypeVar

Q = TypeVar("Q")
T = TypeVar("T", bound="RequestWrapper")

class RequestWrapper(Generic[Q]):
    @classmethod
    def valid(cls, reqs):
        # type: (List[T]) -> List[T]
        pass

class _ConcreteRequestWrapper(RequestWrapper[int]):
    pass

def test(valid_reqs):
    # type: (List[_ConcreteRequestWrapper]) -> None
    _ConcreteRequestWrapper.valid(valid_reqs)

This produces an error in test: error: Argument 1 to "valid" of "RequestWrapper" has incompatible type "List[_ConcreteRequestWrapper]"; expected "List[<nothing>]"

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

This one is pretty bad actually. I understand why this happens: bind_self() just always binds the first type variable, but instead it should bind only variable(s) that appear in the self-type. I have a decent quick-fix, but I want to spend a bit more time maybe I will find a more principled fix for this while I am at it.

msullivan pushed a commit that referenced this issue Nov 12, 2019
* Moves TypeVarExtractor to typeops.py
* Infers and applies all and only type variables that appear in an explicit self type (instead of just always the first one as currently)

Fixes #7925
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-0-high
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants