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

not-an-iterable false positive with class methods with @typing.overload decorator #8314

Closed
Parnassius opened this issue Feb 18, 2023 · 1 comment
Labels
Duplicate 🐫 Duplicate of an already existing issue

Comments

@Parnassius
Copy link

Bug description

# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring,too-few-public-methods,invalid-name,unused-argument

from typing import overload

class A:
    @overload
    def func(self, arg: int) -> list[int]:
        ...

    @overload
    def func(self, arg: str) -> list[int]:
        ...

    def func(self, arg: str | int) -> list[int]:
        return [1, 2, 3]

a = A()

for x in a.func(1):
    pass

The typing overloads don't really make sense here, but they are required to reproduce the issue.

Configuration

No response

Command used

pylint class_overload.py

Pylint output

************* Module class_overload
class_overload.py:19:9: E1133: Non-iterable value a.func(1) is used in an iterating context (not-an-iterable)

-----------------------------------
Your code has been rated at 5.45/10

Expected behavior

No error.

The issue only appears with an @overloaded class method, the following three similar situations work correctly:

Class method with no overloads:

# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring,too-few-public-methods,invalid-name,unused-argument

class A:
    def func(self, arg: str | int) -> list[int]:
        return [1, 2, 3]

a = A()

for x in a.func(1):
    pass

Function with overloads:

# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring,too-few-public-methods,invalid-name,unused-argument

from typing import overload

@overload
def func(arg: int) -> list[int]:
    ...

@overload
def func(arg: str) -> list[int]:
    ...

def func(arg: str | int) -> list[int]:
    return [1, 2, 3]

for x in func(1):
    pass

Function with no overloads:

# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring,too-few-public-methods,invalid-name,unused-argument

def func(arg: str | int) -> list[int]:
    return [1, 2, 3]

for x in func(1):
    pass

Pylint version

pylint 2.16.2
astroid 2.14.2
Python 3.10.9 (main, Dec 08 2022, 14:49:06) [GCC]

The issue is also present on the latest commit (490c40525c286483e8b7405870a8d2f0ae627de4)

OS / Environment

OpenSUSE Tumbleweed

Additional dependencies

No response

@Parnassius Parnassius added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Feb 18, 2023
@jacobtylerwalls
Copy link
Member

Duplicate of pylint-dev/astroid#1015

@jacobtylerwalls jacobtylerwalls marked this as a duplicate of pylint-dev/astroid#1015 Feb 18, 2023
@jacobtylerwalls jacobtylerwalls closed this as not planned Won't fix, can't repro, duplicate, stale Feb 18, 2023
@jacobtylerwalls jacobtylerwalls added Duplicate 🐫 Duplicate of an already existing issue and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Feb 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate 🐫 Duplicate of an already existing issue
Projects
None yet
Development

No branches or pull requests

2 participants