Skip to content

Classmethod bound with an additional name trigger stubtest errors #15717

Description

@dalcinl

Bug Report

Classmethods bound with an additional name trigger stubtest errors.

To Reproduce

Consider the following trivial module and companion typing stub file

# mod.py
class T:
    def a(self): pass
    b = a
    @classmethod
    def c(cls): pass
    d = c
# mod.pyi
class T:
    def a(self) -> None: pass
    b = a
    @classmethod
    def c(cls) -> None: pass
    d = c

then run stubtest the following way:

PYTHONPATH=$PWD stubtest mod

Expected Behavior

stubtest succeeds with no output printed

Actual Behavior

error: mod.T.d variable differs from runtime type def () -> Any
Stub: in file /home/dalcinl/tmp/pkg/mod.pyi:6
def (cls: Type[mod.T])
Runtime: in file /tmp/mod.py:4
<bound method T.c of <class 'mod.T'>>

Found 1 error (checked 1 module)

Please note that the issue comes from a @classmethod, a regular method does not trigger the error.

Your Environment

  • Mypy version used: 1.4.1
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.11.4

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions