Summary
The following code results in an invalid-method-override error on the __iter__ method:
from __future__ import annotations
from collections.abc import Iterator
class MyStr(str):
def __iter__(self) -> Iterator[str]:
raise NotImplementedError
https://play.ty.dev/a0d43982-dd9a-4f49-bdbf-8d75d867a595
mypy / pyright do not report an error; pyrefly does report a similar error.
This seems to happen due to the fact that str.__iter__ is defined as an overload (with a LiteralString). Re-defining the overload clears the error:
from __future__ import annotations
from typing import LiteralString, overload
from collections.abc import Iterator
class MyStr(str):
@overload
def __iter__(self: LiteralString) -> Iterator[LiteralString]: ...
@overload
def __iter__(self) -> Iterator[str]: ...
def __iter__(self) -> Iterator[str]:
raise NotImplementedError
But this seems something that shouldn't be necessary.
Version
ty 0.0.13
Summary
The following code results in an
invalid-method-overrideerror on the__iter__method:https://play.ty.dev/a0d43982-dd9a-4f49-bdbf-8d75d867a595
mypy / pyright do not report an error; pyrefly does report a similar error.
This seems to happen due to the fact that
str.__iter__is defined as an overload (with aLiteralString). Re-defining the overload clears the error:But this seems something that shouldn't be necessary.
Version
ty 0.0.13