Conversation
|
Diff from mypy_primer, showing the effect of this PR on open source code: xarray (https://github.com/pydata/xarray)
+ xarray/core/dataset.py:1068: error: Signature of "copy" incompatible with supertype "Mapping" [override]
+ xarray/core/dataset.py:1068: note: Superclass:
+ xarray/core/dataset.py:1068: note: def copy(self) -> MutableMapping[Any, Any]
+ xarray/core/dataset.py:1068: note: Subclass:
+ xarray/core/dataset.py:1068: note: def copy(self, deep: bool = ..., data: Optional[Mapping[Any, Any]] = ...) -> Dataset
bidict (https://github.com/jab/bidict)
+ bidict/_base.py: note: In member "copy" of class "BidictBase":
+ bidict/_base.py:471:5: error: Return type "BidictBase[KT, VT]" of "copy" incompatible with return type "MutableMapping[KT, VT]" in supertype "Mapping" [override]
urllib3 (https://github.com/urllib3/urllib3)
+ src/urllib3/_request_methods.py:96: error: Unused "type: ignore" comment
+ src/urllib3/connectionpool.py:689: error: Unused "type: ignore" comment
+ src/urllib3/connectionpool.py:690: error: Unused "type: ignore" comment
arviz (https://github.com/arviz-devs/arviz)
+ arviz/data/inference_data.py:1708: error: Return type "InferenceData" of "copy" incompatible with return type "MutableMapping[str, Dataset]" in supertype "Mapping"
- doc/sphinxext/gallery_generator.py:370: error: Call to untyped function "create_thumbnail" in typed context
- doc/sphinxext/gallery_generator.py:375: note: (Skipping most remaining errors due to unresolved imports or missing stubs; fix these first)
+ doc/sphinxext/gallery_generator.py:370: note: (Skipping most remaining errors due to unresolved imports or missing stubs; fix these first)
|
|
The only error that appears as the result of this change (excluding the primer) seems to be tied to the same piece of code: Lines 1209 to 1211 in f40747f typeshed/stdlib/typing_extensions.pyi Lines 63 to 68 in f40747f This seems to be because |
|
|
|
That's... strange then. Isn't This sounds similar to #7153 where |
|
As @srittau said, there is no You can suggest adding it to CPython first, but it may be difficult because the ABC doesn't provide a way to create an instance of an arbitrary concrete Mapping. |
This is close to how It might help to compare this to |
The
copymethod is missing fromMapping, which is supposedly to be an immutable representation of a dictionary. Since simple shallow copy operation doesn't modify anything, it belongs inMappinginstead ofMutableMapping. This PR adds this missing method. Using thecopymethod avoidsfrom copy import copyimports for creating a quick copy of the original dictionary. The return type is aMutableMappingsince this method is usually used to create a local mutable copy to be passed somewhere, but if immutability needs to be preserved, one can still assign it to aMappingvariable type or use a cast.I ran into this while trying to deal with
TypedDictnot being compatible withDict[str, Any](per python/mypy#4976) and converting a JSON-saving function to accept a mapping, which is then modified before saving.