| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
Diff from mypy_primer, showing the effect of this PR on open source code: spark (https://github.com/apache/spark)
+ python/pyspark/pandas/base.py:1663: error: Unused "type: ignore" comment [unused-ignore]
pytest (https://github.com/pytest-dev/pytest)
+ src/_pytest/monkeypatch.py:402: error: Unused "type: ignore" comment [unused-ignore]
+ src/_pytest/monkeypatch.py:407: error: Unused "type: ignore" comment [unused-ignore]
|
Sorry, something went wrong.
|
I don't think this really does what we'd want because mypy doesn't handle __new__ methods that return something other than a subclass of the type, and the new branch of the overload returns reversed[T] as far as mypy is concerned. It's a tough spot to be in. We can expand what reversed will accept in it's constructor, but without mypy support it's only going to result in reversed[T]. If the actual return type is too divergent from that, that's an issue. I'll check out the mypy-primer hits though to see what's going on and if they're actually being cleared in a reasonable way. Related: python/mypy#15182 |
Sorry, something went wrong.
|
That said this does work as expected in pyright. |
Sorry, something went wrong.
|
|
||
| class reversed(Generic[_T]): | ||
| @overload | ||
| def __new__(cls, sequence: Reversible[_T], /) -> Iterator[_T]: ... # type: ignore[misc] |
There was a problem hiding this comment.
I don't think we even need this overload. The second overload should include this one.
Sorry, something went wrong.
|
We could also use some test cases for this. |
Sorry, something went wrong.
|
I don't think we can do this without mypy support, whether that's python/mypy#15182 or special-casing for reversed. For example, it's true that we don't need the first overload, but without that, and with the current state of mypy, we would get reversed(list[int]) -> reversed[list[int]] from mypy. Right now, the unpacking in __new__(cls, sequence: Reversible[_T], /) -> Iterator[_T] means we get reversed[int] from mypy. We could, with more safety, expand this to accept __reversed__ -> Iterable[T], but it's not ideal because mypy will still incorrectly infer reversed[T], which is a full iterator. So I don't really think it's worth worrying about test cases; this is busted and we shouldn't do it right now. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
A bit experimental.
related to #13218 and #11645