Description
Bug description
# pylint: disable=missing-module-docstring,missing-class-docstring,invalid-name,too-few-public-methods,missing-function-docstring
from typing import reveal_type, NoReturn
from functools import cached_property
class cached_property_readonly[T](cached_property[T]):
def __set__(self, instance: object, val: T) -> NoReturn:
raise AttributeError("BAD")
class ice_weasels:
@cached_property
def harf(self) -> list[int]:
return [1, 2, 3]
@cached_property_readonly
def blah(self) -> list[int]:
return [1, 2, 3]
d = ice_weasels()
reveal_type(d.harf) # mypy reports list[int]
reveal_type(d.blah) # mypy reports list[int]
for _ in d.harf: # No complaints from mypy or pylint
pass
for _ in d.blah: # No complaints from mypy, but pylint gives not-an-iterable
pass
# If the cached_property_readonly class is not Generic over T and inheriting from
# cached_property[T], then mypy reports the revealed type of blah as Any.
Configuration
Command used
pylint test.py
Pylint output
************* Module test
test.py:26:9: E1133: Non-iterable value d.blah is used in an iterating context (not-an-iterable)
Expected behavior
No errors
Pylint version
pylint 3.3.7
astroid 3.3.10
Python 3.12.9 (main, Mar 18 2025, 03:28:39) [GCC 12.2.0]
(but I have reproduced on Python 3.10 and 3.13 as well)
OS / Environment
docker.io/python:3.12 x86_64 image
https://mypy-play.net/?mypy=latest&python=3.12&gist=00a0d22bec726e12655bc2ea85c8de5d