-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Use Callable[..., Any] instead of Callable[..., object] in unittest #8399
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
If this approach seems reasonable, I'll work on fixing the |
Thanks for the PR. I'd like to know what other maintainers think here, but I'm somewhat unhappy with this change tbh, and I'd like to sink some time into trying to fix the mypy bug before we go ahead with something like this. The fault is really with mypy here, not typeshed. Morally, the more correct type in basically all of these cases is |
This comment has been minimized.
This comment has been minimized.
I would prefer not merging this. This specific find-replace also makes me uneasy; there are definitely places where I spent a little bit of time trying to fix the mypy issue, you can see my attempt and list of other things that didn't work out of the box at python/mypy#13221 All the listed things fixed the issue, but caused other regressions and I didn't spend that much time trying to figure everything out. PR should at least be useful in terms of pointers to the relevant code. |
I made the blanket change because users will inevitably run into the same bug on other APIs leading to more confusion, PRs, and overall more wasted time. Ideally mypy would fix the issue but in the meantime this kind of workaround seems appropriate to give users a better experience. That said, I'm happy to only change the unittest methods for now and leave the rest up to you. |
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
Updated to only change unittest (and the DocTestCase subclass of TestCase). Ready for another look. |
Marking this as deferred for now, in case we're able to find a good mypy fix in the next several days :-) |
I am opposed to merging this. If there isn't a fix for mypy until the next release, I suggest that mypy ships a patched version of typeshed. |
This may have been true before but I don't think it is anymore now that this PR only changes unittest. My understanding is that there's no typing difference between using Could we merge this PR or just close it if it will never be accepted? |
I am fine with merging this, since none of us has yet managed to find a mypy fix, and given that this now only changes the unittest functions. |
What makes unittest special here? |
Well, the ones in unittest have caused a known problem for somebody. That hasn't been shown for any of the other stdlib functions. |
I'm still opposed to this. At this point I don't think we should regress our stubs due to type checker bugs that can be worked around with "# type: ignore". (Unless it's something really fundamental.) |
I completely understand this perspective! |
I would be more open to this if we had some process that would ensure that we restore the "correct" stubs once the bug is fixed in mypy. And by process I don't mean "someone needs to remember to do this". :) |
Can you explain how this would be a regression? IIUC Any and object are functionally identical here. |
It's not a functional regression in this particular case, but stylistic one. We invested effort in streamlining callable annotations to use |
Reintroducing But, I can see it both ways, and agree that the "fault" ultimately lies with mypy here. |
I don't think we'll be merging this — @srittau opposes it, and I don't think any other maintainers are going to come forward to argue in favour of it. Sorry @ShaneHarvey — thanks for the PR anyway. |
No worries. Thanks for the quick responses! |
One idea I have is to merge this and just create the reverting PR already, marking it as "deferred". This would mean that there's less chance we forget if mypy fixes the bug. @AlexWaygood Do you think this would be a good idea? |
I like that idea! We tend to go through open PRs on a fairly regular basis, so I think it would serve as an effective reminder. |
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
Merged! PR to revert is here: #8779. Thanks for your patience @ShaneHarvey :) |
This is a follow up to resolve #8372 by using
Callable[..., Any]
instead ofCallable[..., object]
in all apis. This is needed to workaround the mypy bug: python/mypy#13220Note I made these changes with this command:
Edit: Updated to only change unittest.TestCase (and the DocTestCase subclass).