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

delegate fails for Literal type #328

Closed
q0w opened this issue Nov 23, 2021 · 2 comments
Closed

delegate fails for Literal type #328

q0w opened this issue Nov 23, 2021 · 2 comments
Labels
bug Something isn't working

Comments

@q0w
Copy link
Contributor

q0w commented Nov 23, 2021

Bug report

What's wrong

from classes import typeclass
from typing import Literal


class _Car(type):
    def __instancecheck__(self, instance) -> bool:
        return isinstance(instance, str) and instance == "car"


class Car(str, metaclass=_Car):
    ...


class _Pony(type):
    def __instancecheck__(self, instance) -> bool:
        return isinstance(instance, str) and instance == "pony"


class Pony(str, metaclass=_Pony):
    ...


@typeclass
def get_repr(type, name: str) -> str:
    pass


@get_repr.instance(delegate=Pony) # error: Instance "Literal['pony']" does not match inferred type "t.Pony*"
def _pony(type: Literal["pony"], name: str) -> str:
    return f"Pony {name}"


@get_repr.instance(delegate=Car) # error: Instance "Literal['car']" does not match inferred type "t.Car*"
def _car(type: Literal["car"], name: str) -> str:
    return f"Car {name}"


if __name__ == "__main__":
    print(get_repr('car', 'test')) # error: Argument 1 to "get_repr" has incompatible type "str"; expected <nothing>

How is that should be

System information

  • python version: 3.9.6
  • classes version: 0.4.0
  • mypy version: 0.910
@q0w q0w added the bug Something isn't working label Nov 23, 2021
@thepabloaguilar
Copy link
Member

Thanks for your issue, Literal is not supported yet!

Related #274

@sobolevn
Copy link
Member

I guess we can close it in favor of #274 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

3 participants