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

Erroneous not-an-iterable when inheriting from NamedTuple #9538

Closed
One-Nose opened this issue Apr 4, 2024 · 3 comments
Closed

Erroneous not-an-iterable when inheriting from NamedTuple #9538

One-Nose opened this issue Apr 4, 2024 · 3 comments
Labels
Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling

Comments

@One-Nose
Copy link

One-Nose commented Apr 4, 2024

Bug description

# pylint: disable=missing-module-docstring
# pylint: disable=missing-class-docstring
# pylint: disable=missing-function-docstring

from __future__ import annotations

from typing import NamedTuple


class Vec3D(NamedTuple):
    x: int
    y: int
    z: int

    def inc(self) -> Vec3D:
        return Vec3D(a + 1 for a in self)

Configuration

No response

Command used

pylint test.py

Pylint output

************* Module test
test.py:16:36: E1133: Non-iterable value self is used in an iterating context (not-an-iterable)

Expected behavior

Should not produce error.

Pylint version

pylint 3.1.0
astroid 3.1.0
Python 3.12.0 (tags/v3.12.0:0fb18b0, Oct  2 2023, 13:03:39) [MSC v.1935 64 bit (AMD64)]

OS / Environment

No response

Additional dependencies

No response

@One-Nose One-Nose added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Apr 4, 2024
@One-Nose
Copy link
Author

One-Nose commented Apr 4, 2024

This was already reported in #2568 as a problem with all typing generics and was closed because it couldn't be reproduced. However, I encountered this error specifically with NamedTuple (as also described in #2568 (comment)).

Note that iter(self) still works as expected.

@One-Nose
Copy link
Author

One-Nose commented Apr 4, 2024

Update: This appears to be a problem with all of NamedTuple's attributes, including self._replace, self._asdict, etc., and it's not a problem with the inheritance either.

@One-Nose
Copy link
Author

One-Nose commented Apr 4, 2024

Nevermind, appears to be a duplicate of #7891.

@One-Nose One-Nose closed this as completed Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling
Projects
None yet
Development

No branches or pull requests

1 participant