-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Protocols #3132
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
Protocols #3132
Changes from 1 commit
884481d
c19b6d4
83c1579
b01f5b0
16901fc
c8c1247
f430c65
beea7d2
260237a
5414eaf
7f8a514
92b71a2
83085c7
27b8570
41179c2
5171844
db123a3
31bf16c
03b5d72
65a8546
2768d76
93beb75
5135fd9
fdeb89b
1fbcb4a
d012e38
801770d
a625f37
fb6b1ad
adb68eb
b9a0b2d
969f76f
2e5de3e
1daaf8d
2b6d198
937c629
e8e6661
8e6306f
3f2d707
a82413d
957c76d
8cf08ec
e0083d9
c9629da
affec0c
01948dd
78a62eb
0ae409a
cb27279
5452227
798954a
9db4e51
7d2327a
88d4fed
d9187e2
3ee1c53
85082d5
2733e1a
232428f
4c04e0b
e81a3f9
b4ca6f0
b063767
79d8e30
480b977
483f163
70c3ae0
509113a
0cb0985
9f554b6
70463a5
78f2011
473a2d2
8dfe8ea
f7e55fa
06a1680
204ec82
985d1f7
8d2e199
f0471c1
4dfa3e1
6d05060
759409f
83501ff
166b6da
d25bcfc
d652a69
addac40
803ce1e
1c9f6f9
3c0411c
491b31f
98f0180
0f55718
513c759
36f3d6d
05b70ab
561856e
228f621
0716b59
9cd4e29
eb06c55
59aeed2
73d2d69
ee18dde
34d1cd1
fbbd169
3acd19e
22ad771
4f2391e
359a43b
eacff5f
afe1291
1858ed9
057a871
28c1b9d
ad2bcaa
8af7248
9ca98b2
0cb13b7
fd06408
969a64b
e9cbba8
e93f839
9292971
4c3f4e2
e71dff0
d195964
318bb70
3d8782f
6e1100c
5bfa3b2
82f01b7
c7304bd
58e6b36
eefe881
96a04ae
b1c4d37
8b6006c
f76349b
c3bfe2b
e2f4f5d
91fe9fd
aaea344
27c3e36
cfa539d
713db0c
40d635f
19073e5
50d98c0
9411255
f1c915e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
from abc import abstractmethod | ||
|
||
from typing import ( | ||
Any, TypeVar, List, Tuple, cast, Set, Dict, Union, Optional | ||
Any, TypeVar, List, Tuple, cast, Set, Dict, Union, Optional, ClassVar | ||
) | ||
|
||
import mypy.strconv | ||
|
@@ -1925,6 +1925,16 @@ class is generic then it will be a type constructor of higher kind. | |
runtime_protocol = False # Does this protocol support isinstance checks? | ||
abstract_attributes = None # type: List[str] | ||
protocol_members = None # type: List[str] | ||
|
||
# These represent global structural subtype matrices. | ||
# If concurrent/parallel type checking will be added in future, | ||
# then there should be one matrix per thread/process to avoid false negatives | ||
# during the type checking phase. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extend this comment explaining why we use |
||
assuming = [] # type: ClassVar[List[Tuple[Instance, Instance]]] | ||
assuming_proper = [] # type: ClassVar[List[Tuple[Instance, Instance]]] | ||
# Ditto for temporary stack of recursive constraint inference. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Explain what goes into the stack and why we need it. |
||
inferring = [] # type: ClassVar[List[TypeInfo]] | ||
|
||
# Classes inheriting from Enum shadow their true members with a __getattr__, so we | ||
# have to treat them as a special case. | ||
is_enum = False | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ | |
from mypy import messages, sametypes | ||
from mypy.nodes import ( | ||
CONTRAVARIANT, COVARIANT, FuncBase, Var, Decorator, OverloadedFuncDef, | ||
ARG_POS, ARG_OPT, ARG_NAMED, ARG_NAMED_OPT, ARG_STAR, ARG_STAR2, | ||
ARG_POS, ARG_OPT, ARG_NAMED, ARG_NAMED_OPT, ARG_STAR, ARG_STAR2, TypeInfo | ||
) | ||
from mypy.maptype import map_instance_to_supertype | ||
from mypy.expandtype import expand_type_by_instance | ||
|
@@ -287,18 +287,14 @@ def visit_type_type(self, left: TypeType) -> bool: | |
return False | ||
|
||
|
||
ASSUMING = [] # type: List[Tuple[Instance, Instance]] | ||
ASSUMING_PROPER = [] # type: List[Tuple[Instance, Instance]] | ||
|
||
|
||
def is_protocol_implementation(left: Instance, right: Instance, allow_any: bool = True) -> bool: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about changing |
||
assert right.type.is_protocol | ||
is_compat = None # type: Callable[[Type, Type], bool] | ||
if allow_any: | ||
is_compat = is_subtype | ||
else: | ||
is_compat = is_proper_subtype | ||
assuming = ASSUMING if allow_any else ASSUMING_PROPER | ||
assuming = TypeInfo.assuming if allow_any else TypeInfo.assuming_proper | ||
for (l, r) in reversed(assuming): | ||
if sametypes.is_same_type(l, left) and sametypes.is_same_type(r, right): | ||
return True | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add comment. Some edge cases to discuss: What about inherited protocol members? What about members defined in
object
?