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

generic super false-posistive error on argument type #6224

Open
Levitanus opened this issue Jan 19, 2019 · 3 comments
Open

generic super false-posistive error on argument type #6224

Levitanus opened this issue Jan 19, 2019 · 3 comments
Labels
bug mypy got something wrong false-positive mypy gave an error on correct code priority-1-normal topic-inheritance Inheritance and incompatible overrides topic-type-variables

Comments

@Levitanus
Copy link

Levitanus commented Jan 19, 2019

input:

NT = TypeVar('NT', int, float)
NTU = Union['KspVar[NT]', 'AstBase[NT]', 'ProcessNum[NT]', NT]


class AstOperatorUnary(AstBase[NT], ProcessNum[NT]):
    arg1: NTU[NT]
    string: ClassVar[str]
    priority: ClassVar[int]

    def __init__(self, arg1: NTU[NT]) -> None:
        self.arg1: NTU[NT] = arg1
        self.arg1_pure: NT = get_value(arg1)
        self.arg1_str: str = get_compiled(arg1)


class AstOperatorDouble(AstOperatorUnary[NT]):
    arg2: NTU[NT]

    def __init__(self, arg1: NTU[NT], arg2: NTU[NT]) -> None:
        super().__init__(arg1)
        self.arg2 = arg2
        self.arg2_pure: NT = get_value(arg2)
        self.arg2_str: str = get_compiled(arg2)

Traceback:

E:\packages\pyksp\pyksp\new_base_types.py:285: error: Argument 1 to "__init__" of "AstOperatorUnary" has incompatible type "Union[KspVar[int], AstBase[int], ProcessNum[int], int]"; expected "Union[KspVar[NT], AstBase[NT], ProcessNum[NT], NT]"
E:\packages\pyksp\pyksp\new_base_types.py:285: error: Argument 1 to "__init__" of "AstOperatorUnary" has incompatible type "Union[KspVar[float], AstBase[float], ProcessNum[float], float]"; expected "Union[KspVar[NT], AstBase[NT], ProcessNum[NT], NT]"

ProcessNum has not got __init__

@JelleZijlstra
Copy link
Member

Could you post a self-contained code sample that reproduces the error? What you posted is missing several base classes.

@Levitanus
Copy link
Author

Levitanus commented Jan 19, 2019

Sorry, the minimal example is this:
[updated]

import typing as t

NT = t.TypeVar('NT', int, float)
NTU = t.Union['AstOperatorUnary[NT]', NT]


class AstOperatorUnary(t.Generic[NT]):

    def __init__(self, arg1: NTU[NT]) -> None:
        pass


class AstOperatorDouble(AstOperatorUnary[NT]):

    def __init__(self, arg1: NTU[NT], arg2: NTU[NT]) -> None:
        super().__init__(arg1)

Traceback:

E:\packages\pyksp\pyksp\reproduce.py:16: error: Argument 1 to "__init__" of "AstOperatorUnary" has incompatible type "Union[AstOperatorUnary[int], int]"; expected "Union[AstOperatorUnary[NT], NT]"
E:\packages\pyksp\pyksp\reproduce.py:16: error: Argument 1 to "__init__" of "AstOperatorUnary" has incompatible type "Union[AstOperatorUnary[float], float]"; expected "Union[AstOperatorUnary[NT], NT]"

@JelleZijlstra
Copy link
Member

JelleZijlstra commented Jan 19, 2019

I minimized what you posted before to:

import typing as t

T = t.TypeVar('T')
NT = t.TypeVar('NT', int, float)


class AstBase(t.Generic[T]):
    pass


class AstOperatorUnary(t.Generic[NT]):
    def __init__(self, arg1: AstBase[NT]) -> None:
        pass


class AstOperatorDouble(AstOperatorUnary[NT]):
    def __init__(self, arg1: AstBase[NT]) -> None:
        super().__init__(arg1)

which fails on master with

bin/falspos.py:18: error: Argument 1 to "__init__" of "AstOperatorUnary" has incompatible type "AstBase[int]"; expected "AstBase[NT]"
bin/falspos.py:18: error: Argument 1 to "__init__" of "AstOperatorUnary" has incompatible type "AstBase[float]"; expected "AstBase[NT]"

That does look like a bug to me.

@ilevkivskyi ilevkivskyi added bug mypy got something wrong topic-type-variables priority-1-normal false-positive mypy gave an error on correct code labels Jan 19, 2019
@AlexWaygood AlexWaygood added the topic-inheritance Inheritance and incompatible overrides label Apr 4, 2022
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 topic-inheritance Inheritance and incompatible overrides topic-type-variables
Projects
None yet
Development

No branches or pull requests

4 participants