pylint-dev / pylint

It's not just a linter that annoys you!
https://pylint.readthedocs.io/en/latest/
GNU General Public License v2.0
5.3k stars 1.13k forks source link

Setting attribute of typing.NamedTuple is not detected #2858

Open ramkumarhn opened 5 years ago

ramkumarhn commented 5 years ago

Steps to reproduce

from typing import NamedTuple

class Car(NamedTuple):
    color: str
    mileage: float
    automatic: bool

car1 = Car('red', 3812.3, True)
car1.mileage = 12

Current behavior

Currently, at runtime the below exception is thrown. car1.mileage = 12 AttributeError: can't set attribute

Expected behavior

This error should be flagged

pylint --version output

pylint 2.3.1 astroid 2.2.5 Python 3.7.2 (default, Jan 13 2019, 12:50:01) [Clang 10.0.0 (clang-1000.11.45.5)]

PCManticore commented 5 years ago

Thanks @ramkumarhn We should add a rule for this as well.