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

false not-an-iterable for __truediv__ with @overload #2448

Open
davetapley opened this issue May 21, 2024 · 2 comments
Open

false not-an-iterable for __truediv__ with @overload #2448

davetapley opened this issue May 21, 2024 · 2 comments

Comments

@davetapley
Copy link

davetapley commented May 21, 2024

Steps to reproduce

from dataclasses import dataclass
from typing import Any, Iterable, Iterator, overload


@dataclass
class MyIterable(Iterable[int]):

    def __iter__(self) -> Iterator[int]:
        for n in range(1, 10):
            yield n


@dataclass
class IterableMaker():
    @overload
    def __truediv__(self, right: bool) -> bool:
        ...

    @overload
    def __truediv__(self, right: str) -> MyIterable:
        ...

    def __truediv__(self, right: Any):
        if isinstance(right, bool):
            return right
        return MyIterable()


for sensor in IterableMaker() / 'thing':
    print(sensor)

Current behavior

E1133: Non-iterable value IterableMaker() / 'thing' is used in an iterating context (not-an-iterable)

Expected behavior

No error.

python -c "from astroid import __pkginfo__; print(__pkginfo__.version)" output

3.2.2

@davetapley
Copy link
Author

I'd hoped this was fixed by #1015, but alas no.

It is specific to __truediv__.

rbrazinskas added a commit to iqm-finland/cirq-on-iqm that referenced this issue May 23, 2024
There has been a recent regression in astroid module (since version 3.2.0, most likely related to changes in igetattr method). It causes our CI workflows runs to fail. astroid is a transitive dependency (pytest-pylint <- pylint <- astroid). Versions of transitive dependencies are not pinned in the project configuration, which allowed astroid regression to break the CI.

pylint checks should be re-enabled once astroid bug pylint-dev/astroid#2448 gets fixed.
rbrazinskas added a commit to iqm-finland/cirq-on-iqm that referenced this issue May 23, 2024
There has been a recent regression in astroid module (since version 3.2.0, most likely related to changes in igetattr method). It causes our CI workflows runs to fail. astroid is a transitive dependency (pytest-pylint <- pylint <- astroid). Versions of transitive dependencies are not pinned in the project configuration, which allowed astroid regression to break the CI.

pylint checks should be re-enabled once astroid bug pylint-dev/astroid#2448 gets fixed.
@The-Compiler
Copy link
Contributor

I see something similar with:

from typing import overload, Iterator, Union


class Sequence:

    def __init__(self, data: list[str]) -> None:
        self._data = data

    @overload
    def __getitem__(self, idx: int) -> str:
        ...

    @overload
    def __getitem__(self, idx: slice) -> "Sequence":
        ...

    def __getitem__(self, idx: Union[int, slice]) -> Union[str, "Sequence"]:
        if isinstance(idx, slice):
            return self.__class__(*self._data[idx])
        else:
            return self._data[idx]


s = Sequence(["a", "b"])
print(s[0].upper())

where pylint complains: E1101: Instance of 'Sequence' has no 'upper' member (no-member)

For my real code (implementation, usage) this only started happening with pylint 3.2.1 and astroid 3.2.2 (but not 3.1.x). However, the minimal example seems to show the error even in older versions.

The-Compiler added a commit to qutebrowser/qutebrowser that referenced this issue May 24, 2024
- Add a couple new "raise utils.Unreachable" to avoid
  possibly-used-before-assignment issues.
- Simplify an "if" for the same reason
- Remove an unneeded "return"
- Use "NoReturn" to prepare for pylint knowing about it in the future:
  pylint-dev/pylint#9674
- Add some ignores for used-before-assignment false-positives
- Ignore new undefined-variable messages for Qt wrapers
- Ignore a new no-member warning for KeySequence:
  pylint-dev/astroid#2448 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants