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

Child of abstract class with Literal field doesn't support Final as field #7751

Closed
b0g3r opened this issue Oct 19, 2019 · 3 comments
Closed
Labels
bug mypy got something wrong false-positive mypy gave an error on correct code priority-1-normal topic-literal-types

Comments

@b0g3r
Copy link

b0g3r commented Oct 19, 2019

Possibly bug. Child of abstract class with Literal field doesn't support Final as field type.Reproducible example:

import abc

from typing_extensions import Literal, Final

PossibleKeysType = Literal['KEY1', 'KEY2']


class AbstractParent(abc.ABC):
    @property
    @abc.abstractmethod
    def key(self) -> PossibleKeysType:
        pass


class LiteralChild(AbstractParent):
    key: Literal['KEY1'] = 'KEY1'


class FinalChild(AbstractParent):
    key: Final = 'KEY1'  #  error: Incompatible types in assignment (expression has type "str", base class "AbstractParent" defined the type as "Union[Literal['KEY1'], Literal['KEY2']]")

I expect that FinalChild type checking should work similarly to LiteralChild and something: Final = 'str' is equal to something: Literal['str'] = 'str' like in TypedDict key checking.

I use mypy 0.740, python 3.6

@ilevkivskyi
Copy link
Member

Yes, this is a bug, it looks like the Liskov check happens before we finalize the type. Essentially this is just another one in the #7724 bucket.

@ilevkivskyi ilevkivskyi added bug mypy got something wrong false-positive mypy gave an error on correct code priority-1-normal topic-literal-types labels Oct 20, 2019
@b0g3r
Copy link
Author

b0g3r commented Oct 20, 2019

@ilevkivskyi Thank you for the fast response, It sounds like good news!

@97littleleaf11
Copy link
Collaborator

Had been fixed in latest master branch!

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-literal-types
Projects
None yet
Development

No branches or pull requests

3 participants