GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||
GeezerVison is showing github.com — Fix annotations for `builtins.reversed.__new__` by jorenham · Pull Request #11646 · python/typeshed Conversation
|
|
It seems that mypy has problems with the first overload, but I'm not sure why. Everything seems correct to me and pyright seems to agree. For now, I would suggest to split this PR in two, one PR for the second overload and a separate PR for the first one. This should allow us to get part of the changes into typeshed soon, and will make it easier to debug the mypy problem. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
@srittau I have tried many different approaches, but none of them seem to be accepted by mypy. As you said, pyright has no problem with this. I can't draw any other conclusions than this being a mypy bug, and it's easy to reproduce: https://mypy-play.net/?mypy=latest&python=3.12&gist=0c754a7826a80f50ced671c26d891950&flags=strict The expected behavior can be illustrated by pyright, which works as expected and doesn't require the I wasn't able to find anything on https://typing.readthedocs.io/ that would restrict the type of the return value from a (non-meta) class' |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I've marked this PR as deferred for now due to the mypy bug. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@srittau I don't quite follow. Currently, all typecheckers will reject a This PR makes it so that (presumably) only mypy will incorrectly reject it, due to a bug. But the new tests that I included only fail because of mypy's bug. So I don't see how deferring this would be any better than mergin this. I believe it's reasonable to ignore mypy's false negatives, since they're directly caused by a known bug. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
The mypy primer output above shows the real-world impact this change has on a selected number of packages. Each green line is a new mypy warning. As you can see, this change unfortunately leads to an excessive amount of new errors. As far as I understand, many |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@srittau ah ok I see. I blindly assumed that "green is good" for some reason 🤷🏻 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
According to the updated typing spec, it is indeed allowed for |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Note that the same was attempted in #13269 so the discussion there may apply here as well. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
At the moment, this doesn't look promising. Unless someone has another good idea, I suggest we close this PR – at least for now. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Yea, not much movement on the mypy front unfortunately... Maybe it could help to avoid duplicate PR's if we keep this open? It's also fine to close it if you want, though; whatever floats for boat 🤷🏻. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I see that it's already marked as deferred. I've also marked it as draft, just so it doesn't stand out as much in the open PRs list. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I also rebased onto |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Mypy python/mypy#21441 appear to fix the blocker. Once that makes it into a release, this can be revisited. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
python/mypy#21441 was fixed in mypy 2.2.0 :) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
those blank lines were inserted by pre-commit for some reason 🤷 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Diff from mypy_primer, showing the effect of this PR on open source code: comtypes (https://github.com/enthought/comtypes) - comtypes/server/register.py:226: error: Incompatible types in assignment (expression has type "Iterator[tuple[int, str]]", variable has type "list[tuple[int, str]]") [assignment] + comtypes/server/register.py:226: error: Incompatible types in assignment (expression has type "reversed[tuple[int, str]]", variable has type "list[tuple[int, str]]") [assignment] discord.py (https://github.com/Rapptz/discord.py) - discord/abc.py:1815: error: Incompatible types in assignment (expression has type "Iterator[MessagePin]", variable has type "list[MessagePin]") [assignment] + discord/abc.py:1815: error: Incompatible types in assignment (expression has type "reversed[MessagePin]", variable has type "list[MessagePin]") [assignment] pytest (https://github.com/pytest-dev/pytest) + src/_pytest/monkeypatch.py:417: error: Unused "type: ignore" comment [unused-ignore] + src/_pytest/monkeypatch.py:422: error: Unused "type: ignore" comment [unused-ignore] jinja (https://github.com/pallets/jinja) + src/jinja2/utils.py:570: error: Returning Any from function declared to return "Iterator[Any]" [no-any-return] |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
incorrect annotations forbuiltins.reversed
There was an error while loading. Please reload this page.