Closed
Description
Here's the code:
from abc import ABCMeta, abstractmethod
from classes import typeclass
@typeclass
def my_typeclass(instance) -> int:
"""Example typeclass."""
class _MyABC(object, metaclass=ABCMeta):
@abstractmethod
def get_number(self) -> int:
"""Example abstract method."""
class _MyConcrete(_MyABC):
def get_number(self) -> int:
"""Concrete method."""
return 1
def _my_abc(instance: _MyABC) -> int:
return instance.get_number()
my_typeclass.instance(_MyABC)(_my_abc)
assert my_typeclass(_MyConcrete()) == 1
This works in runtime, but mypy
reveals invalid type:
reveal_type(my_typeclass)
Reveals:
ex.py:48: note: Revealed type is "classes._typeclass._TypeClass[ex._MyABC, def (instance: ex._MyABC) -> builtins.int, <nothing>, Literal['ex.my_typeclass']]"
It should be:
ex.py:48: note: Revealed type is "classes._typeclass._TypeClass[ex._MyABC, def (instance: Any) -> builtins.int, <nothing>, Literal['ex.my_typeclass']]"
For some reason, first argument of our initial signature gets mutated.