Skip to content

pylint's type checker ignores type interface files #9423

@jakevdp

Description

@jakevdp

Bug description

First reported at jax-ml/jax#19713, here's a minimal repro:

$ ls
mymodule.py  mymodule.pyi  test.py

$ cat mymodule.py
class Foo:
  pass
setattr(Foo, "__neg__", lambda self: self)

$ cat mymodule.pyi
class Foo:
  def __neg__(self) -> Foo: ...

$ cat test.py
"""Test file for incorrect E1130"""
from mymodule import Foo
result = -Foo()

$ mypy test.py
Success: no issues found in 1 source file

$ pylint test.py
************* Module test
test.py:3:9: E1130: bad operand type for unary -: Foo (invalid-unary-operand-type)

------------------------------------------------------------------
Your code has been rated at 0.00/10 (previous run: 0.00/10, +0.00)

mypy returns no error because the code is typed correctly: Foo supports __neg__, as declared in the type interface file.

pylint incorrectly errors because it doesn't recognize either the dynamically-defined method or its declaration in the interface file.

Configuration

No response

Command used

see above

Pylint output

see above

Expected behavior

pylint should not error for valid code

Pylint version

pylint 3.0.3
astroid 3.0.3
Python 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0]

OS / Environment

Linux (google Colab)

Additional dependencies

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Duplicate 🐫Duplicate of an already existing issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions