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

functools.partialmethod not supported properly? #8619

Open
DevilXD opened this issue Apr 2, 2020 · 2 comments
Open

functools.partialmethod not supported properly? #8619

DevilXD opened this issue Apr 2, 2020 · 2 comments
Labels
feature priority-1-normal topic-plugins The plugin API and ideas for new plugins

Comments

@DevilXD
Copy link

DevilXD commented Apr 2, 2020

  • Are you reporting a bug, or opening a feature request?

Bug

  • Please insert below the code you are checking with mypy.
import operator
from functools import partialmethod


class IntCmp:
    def __init__(self, value):
        self._value = value

    def _cmp(self, opr, other: int) -> bool:
        if isinstance(other, int):
            return opr(self._value, other)
        return NotImplemented

    __eq__ = partialmethod(_cmp, operator.eq)  # Incompatible types in assignment (expression has type "partialmethod[bool]", base class "object" defined the type as "Callable[[object, object], bool]")
    __ne__ = partialmethod(_cmp, operator.ne)  # Incompatible types in assignment (expression has type "partialmethod[bool]", base class "object" defined the type as "Callable[[object, object], bool]")
    # rest of the comparison operators (lt, le, gt, ge) type checks correctly


c = IntCmp(1)
assert c == 1  # Cannot determine type of '__eq__'
  • What is the actual behavior/output?

MyPy reports an error on the comparison, saying Cannot determine type of '__eq__', as well as incompatible types on assignment as shown.
The code correctly passes at runtime.

  • What is the behavior/output you expect?

__eq__ and __ne__ should correctly type-check the partialmethod, and comparison should give no error. This particular partialmethod usage is shown in Python docs: https://docs.python.org/3/library/functools.html#functools.partialmethod

  • What are the versions of mypy and Python you are using?
    Do you see the same issue after installing mypy from Git master?

Using latest git master, Python 3.8.1

  • What are the mypy flags you are using? (For example --strict-optional)
--follow-imports=silent
--show-column-numbers
--ignore-missing-imports
--check-untyped-defs

EDIT: I am aware of #2967 and #1484 being a thing, however this covers partialmethod usage which wasn't mentioned as a topic in the two other issues.

@Dreamsorcerer
Copy link
Contributor

partial() was added in #16939. Is this likely to be an easy addition to repeat for partialmethod()?

@emmatyping
Copy link
Collaborator

Yeah, it looks like no specific support for partialmethod is in mypy. I expect it to be a bit more complicated than partial support because partialmethod works with descriptors, but I'll have to think about how much more work it would be.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature priority-1-normal topic-plugins The plugin API and ideas for new plugins
Projects
None yet
Development

No branches or pull requests

4 participants