Skip to content

Unbound method rejected as FunctionType, Callable cast as FunctionType #9934

Closed
@tlambert03

Description

@tlambert03

Bug Report

This feels related to #8869, but different enough to warrant a separate issue.
There, the issue was that a bound method of MethodType is incorrectly rejected as a Callable, here, I'm noticing that an unbound class method is rejected as a FunctionType:

To Reproduce

import types

class Cls:
    def meth(self):
        pass

assert isinstance(Cls.meth, types.FunctionType)  # no problem

x: types.FunctionType = Cls.meth
Incompatible types in assignment (expression has type "Callable[[Cls], Any]", variable has type "FunctionType")  [assignment]

Expected Behavior

I expected an unbound class method to work for an argument expecting FunctionType

Actual Behavior

Incompatible types in assignment

Your Environment

  • mypy 0.790
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.8.6
  • Operating system and version: macos 10.15.7

Additional info

(In this case, I didn't want to use x: Callable because I'd like to be able to assert that the standard function object methods will be available)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions