Improve several stdlib setdefault
methods
#9612
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
MutableMapping.setdefault
. It's okay to specify a value for thedefault
parameter and still have this overload match, as long as the value passed for this parameter isNone
. Adjustcollections.OrderedDict.setdefault
andweakref.WeakKeyDictionary.setdefault
to match. Add @JelleZijlstra's test cases from Improve type for setdefault() #6941 (comment), to make sure that the method is still working as expected.ChainMap.setdefault
in sync withMutableMapping.setdefault
. At runtime, it is directly inherited fromMutableMapping.setdefault
. (We don't do that in the stub because we pretendMutableMapping.setdefault
has positional-only parameters so thatdict
can inherit fromMutableMapping
without having totype: ignore
thesetdefault
method.)= ...
fromweakref.WeakValueDictionary.setdefault
. This has got a default value ofNone
at runtime, but it will always error out if you don't specify a value for thedefault
parameter. (This is because you can't create a weak reference toNone
.) It will serve users better if we specify in the stub that you have to provide a value for thedefault
parameter.Refs #9608.