8000 Invalid revealed type for `ABC` usage · Issue #259 · dry-python/classes · GitHub
[go: up one dir, main page]

Skip to content

Invalid revealed type for ABC usage #259

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

Closed
sobolevn opened this issue Jul 8, 2021 · 0 comments · Fixed by #256
Closed

Invalid revealed type for ABC usage #259

sobolevn opened this issue Jul 8, 2021 · 0 comments · Fixed by #256
Labels
bug Something isn't working

Comments

@sobolevn
Copy link
Member
sobolevn commented Jul 8, 2021

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.

@sobolevn sobolevn added the bug Something isn't working label Jul 8, 2021
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

Successfully merging a pull request may close this issue.

1 participant
0