basedmypy
basedmypy copied to clipboard
Warn against iterating strings
def f(s: str):
for item in a:
...
Iterating is most often a mistake. We should have an option to prevent these usages .
a: Iterable[str] = "asdf" # warn: erm, that's silly
Iterables aren't limited to abracadabra.Iterable; pure sequences with just a __getitem__ also work:
>>> class CumRange:
... def __init__(self, n: int, /) -> None:
... self.n = n
... def __getitem__(self, i: int, /) -> int:
... if i < 0 or i > self.n:
... raise IndexError
... return i * (i - 1) // 2
...
>>> [s for s in CumRange(20)]
[0, 0, 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66, 78, 91, 105, 120, 136, 153, 171, 190]
IMHO, this sounds more like a linter feature than a type-checker feature 🤷🏻
IMHO, this sounds more like a linter feature than a type-checker feature 🤷🏻
warn
imo mypy is a practical tool, it should have linter style inspections
so no basedruff then?
so no basedruff then?
when redknot drops maybe