Uh oh!
There was an error while loading. Please reload this page.
make the default positional-or-keyword in Mapping.get and MutableMapping.pop - #6694
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Akuli
commented
Dec 26, 2021
I can't reproduce the mypy_primer errors locally. For example, with |
Akuli
commented
Dec 26, 2021
Nevermind. I think the mypy_primer run for my first broken commit finished after the one for the fixed commit. |
This comment has been minimized.
This comment has been minimized.
JelleZijlstra
commented
Dec 26, 2021
I don't think this is the right solution. dict is by far the most common MutableMapping, so if you can't do something on dict, you shouldn't be able to do it on MutableMapping. The errors in the mypy issue should instead be fixed with a more precise type for |
AlexWaygood
commented
Dec 26, 2021
I disagree. The whole point of the mixin methods in |
Akuli
commented
Dec 26, 2021
I wish there was a way to say "subclasses get this, but it's not a part of the interface that the ABC represents". |
I see a couple ways to solve this:
|
AlexWaygood
commented
Dec 26, 2021
Option 2 works for stubs defined inside the typeshed project, but doesn't work for your Average Joe creating his own (type-checked) custom mapping type for an application script. Joe's going to be pretty confused when he gets spurious "can't pass a keyword argument to I vote for Option 1. |
sobolevn
commented
Dec 26, 2021
It would be just amazing to fix |
Akuli
commented
Dec 26, 2021
I think CPython developers would say "it has worked for a long time", and do nothing about it. https://bugs.python.org/issue29935 |
JelleZijlstra
commented
Jan 22, 2022
Here's another option:
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
Akuli
commented
Jan 22, 2022
I believe that's what this PR does. |
JelleZijlstra
commented
Jan 22, 2022
So it does, I should have checked. |
Fixespython/mypy#11831
I don't think it makes sense for
defaultto be positional-only inMapping.getandMutableMapping.pop, because classes that inherit from them without overridinggetorpop(such asos.environ) can be called with a keyword argumentdefault="lol", and people actually want to do that.