Skip to content

Pylint doesn't get correct method signatures when a variable type is checked with isinstance #10469

@Porter-K

Description

@Porter-K

Bug description

When a variable could be multiple types but is then narrowed down with isinstance() Pylint does not get the correct method signatures.

# pylint: disable=too-few-public-methods,missing-module-docstring,missing-class-docstring
import random


class TestClassA:
    def test_method(self, a: int) -> int:
        """Method that takes in one input."""
        return a**2


class TestClassB:
    def test_method(self, a: int, b: int) -> int:
        """Method that takes in two inputs."""
        return a*b


def test_function():
    """Function that creates the Pylint bug."""
    rand_num = random.randint(0, 10)
    if rand_num > 5:
        a = TestClassA()
    else:
        a = TestClassB()

    if isinstance(a, TestClassB):
        print(a.test_method(2, 3))
    if isinstance(a, TestClassA):
        print(a.test_method(2))


    rand_num = random.randint(0, 10)
    if rand_num > 5:
        b = TestClassB()
    else:
        b = TestClassA()

    if isinstance(b, TestClassB):
        print(b.test_method(2, 3))
    if isinstance(b, TestClassA):
        print(b.test_method(2))

Command used

uv run pylint pylint_test.py

Pylint output

************* Module pylint_test
pylint_test.py:26:14: E1121: Too many positional arguments for method call (too-many-function-args)
pylint_test.py:40:14: E1120: No value for argument 'b' in method call (no-value-for-parameter)

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

Expected behavior

No messages.

Pylint version

pylint 4.0.0-dev0
astroid 4.0.0b0
Python 3.13.4 (main, Jun  4 2025, 17:37:06) [Clang 20.1.4 ]

OS / Environment

Arch Linux
uv 0.8.3 (7e78f54e7 2025-07-24)

Metadata

Metadata

Assignees

No one assigned

    Labels

    AstroidRelated to astroidControl flowRequires control flow understandingFalse Positive 🦟A message is emitted but nothing is wrong with the codeNeeds astroid updateNeeds an astroid update (probably a release too) before being mergable

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions