Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 60a3d7f

Browse filesBrowse files
committed
refine
1 parent d4e9f90 commit 60a3d7f
Copy full SHA for 60a3d7f

2 files changed

+16-6Lines changed: 16 additions & 6 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎mypy/stubtest.py‎

Copy file name to clipboardExpand all lines: mypy/stubtest.py
+11-2Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1898,8 +1898,17 @@ def is_expected_dunder(name: str, *, stub: nodes.TypeInfo, existing_stub_names:
18981898
if name == "__ge__" and {"__gt__", "__eq__"}.issubset(existing_stub_names):
18991899
return True
19001900

1901-
return (name in ("__or__", "__ror__", "__ior__") and stub.has_base("typing.Mapping")) or (
1902-
name in ("__mul__", "__rmul__", "__imul__") and stub.has_base("typing.Sequence")
1901+
if (name in ("__or__", "__ror__") and stub.has_base("typing.Mapping")) or (
1902+
name in ("__mul__", "__rmul__") and stub.has_base("typing.Sequence")
1903+
):
1904+
return True
1905+
1906+
# In-place syntax such as `*=` and `|=` can work with immutable types (for example,
1907+
# tuples or frozensets), but generally delegates to the non-in-place dunder in
1908+
# these cases. The in-place dunders themselves are generally only defined for
1909+
# mutable types.
1910+
return (name == "__ior__" and stub.has_base("typing.MutableMapping")) or (
1911+
name == "__imul__" and stub.has_base("typing.MutableSequence")
19031912
)
19041913

19051914

Collapse file

‎mypy/test/teststubtest.py‎

Copy file name to clipboardExpand all lines: mypy/test/teststubtest.py
+5-4Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class Coroutine(Generic[_T_co, _S, _R]): ...
8181
class Iterable(Generic[_T_co]): ...
8282
class Iterator(Iterable[_T_co]): ...
8383
class Mapping(Generic[_K, _V]): ...
84+
class MutableMapping(Mapping[_K, _V]): ...
8485
class Match(Generic[AnyStr]): ...
8586
class Sequence(Iterable[_T_co]): ...
8687
class Tuple(Sequence[_T_co]): ...
@@ -1981,14 +1982,14 @@ class MappingOr:
19811982
)
19821983
yield Case(
19831984
stub="""
1984-
from typing import Mapping
1985-
class MappingIor(Mapping[str, int]): ...
1985+
from typing import MutableMapping
1986+
class MutableMappingIor(MutableMapping[str, int]): ...
19861987
""",
19871988
runtime="""
1988-
class MappingIor:
1989+
class MutableMappingIor:
19891990
__ior__ = dict.__ior__
19901991
""",
1991-
error="MappingIor.__ior__",
1992+
error="MutableMappingIor.__ior__",
19921993
)
19931994
yield Case(
19941995
stub="""

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.