Skip to content

False positive no-member for NamedTuple._replace() #4070

Open
@ppentchev

Description

@ppentchev

Steps to reproduce

  1. Save the attached file as ntuple.py and run pylint on it. ntuple.txt
"""A test case for a possible pylint bug."""

from typing import List, NamedTuple


class Lines(NamedTuple):
    """A class for storing things."""

    lines: List[str]

    def add_line(self, line: str) -> "Lines":
        """Return an object with the line added."""
        return self._replace(lines=self.lines + [line])


if __name__ == "__main__":
    lines = Lines(lines=[])
    print(repr(lines.add_line("Live long and prosper!")))

Current behavior

************* Module ntuple
ntuple.py:13:15: E1101: Instance of 'Lines' has no '_replace' member (no-member)

(on Python 3.9 it also complains about inheriting from the non-class NamedTuple, but that's a separate, probably already known, issue)

Expected behavior

No diagnostic messages at all.

pylint --version output

pylint 2.6.0
astroid 2.4.2
Python 3.8.6 (default, Sep 29 2020, 13:19:50)
[GCC 10.2.0]

Metadata

Metadata

Assignees

No one assigned

    Labels

    False Positive 🦟A message is emitted but nothing is wrong with the codeNeeds PRThis issue is accepted, sufficiently specified and now needs an implementationtyping

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions