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

Wrong warning when assigning __str__ #3951

Open
nicoulaj opened this issue Sep 13, 2017 · 1 comment
Open

Wrong warning when assigning __str__ #3951

nicoulaj opened this issue Sep 13, 2017 · 1 comment
Labels
bug mypy got something wrong topic-descriptors Properties, class vs. instance attributes topic-runtime-semantics mypy doesn't model runtime semantics correctly

Comments

@nicoulaj
Copy link

I have the following decorator:

from typing import Type, Any

def generate_str(cls: Type) -> Type:
    """
    Class decorator that auto generates __str__().
    :param cls: class to modify
    :return: modified class
    """
    def __str__(self) -> str:
        return _pretty_print_obj(self)

    cls.__str__ = __str__
    return cls

Mypy 0.521 on Python 3.6.2 emits this warning:

error: Incompatible types in assignment (expression has type Callable[[Any], str], variable has type Callable[[], str])
@ilevkivskyi
Copy link
Member

This may be related to #2427, mypy sometimes has problems distinguishing bound and unbound methods. In the meantime you can just put # type: ignore there.

@AlexWaygood AlexWaygood added bug mypy got something wrong topic-runtime-semantics mypy doesn't model runtime semantics correctly topic-descriptors Properties, class vs. instance attributes labels Mar 24, 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 topic-descriptors Properties, class vs. instance attributes topic-runtime-semantics mypy doesn't model runtime semantics correctly
Projects
None yet
Development

No branches or pull requests

3 participants