Skip to content

Commit 81d4317

Browse files
kamahenmsullivan
authored andcommitted
Refactor "magic" method constants so that there are no dups (#4838)
This has been hand-checked to verify that MAGIC_METHODS is the same (the other constants have only been moved within the file)
1 parent 6b05cb7 commit 81d4317

File tree

1 file changed

+7
-47
lines changed

1 file changed

+7
-47
lines changed

mypy/sharedparse.py

Lines changed: 7 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -3,83 +3,39 @@
33
"""Shared logic between our three mypy parser files."""
44

55

6-
MAGIC_METHODS = {
6+
_NON_BINARY_MAGIC_METHODS = {
77
"__abs__",
8-
"__add__",
9-
"__and__",
108
"__call__",
11-
"__cmp__",
129
"__complex__",
1310
"__contains__",
1411
"__del__",
1512
"__delattr__",
1613
"__delitem__",
17-
"__divmod__",
18-
"__div__",
1914
"__enter__",
2015
"__exit__",
21-
"__eq__",
22-
"__floordiv__",
2316
"__float__",
24-
"__ge__",
2517
"__getattr__",
2618
"__getattribute__",
2719
"__getitem__",
28-
"__gt__",
2920
"__hex__",
30-
"__iadd__",
31-
"__iand__",
32-
"__idiv__",
33-
"__ifloordiv__",
34-
"__ilshift__",
35-
"__imod__",
36-
"__imul__",
3721
"__init__",
3822
"__init_subclass__",
3923
"__int__",
4024
"__invert__",
41-
"__ior__",
42-
"__ipow__",
43-
"__irshift__",
44-
"__isub__",
4525
"__iter__",
46-
"__ixor__",
47-
"__le__",
4826
"__len__",
4927
"__long__",
50-
"__lshift__",
51-
"__lt__",
52-
"__mod__",
53-
"__mul__",
54-
"__ne__",
5528
"__neg__",
5629
"__new__",
5730
"__nonzero__",
5831
"__oct__",
59-
"__or__",
6032
"__pos__",
61-
"__pow__",
62-
"__radd__",
63-
"__rand__",
64-
"__rdiv__",
6533
"__repr__",
6634
"__reversed__",
67-
"__rfloordiv__",
68-
"__rlshift__",
69-
"__rmod__",
70-
"__rmul__",
71-
"__ror__",
72-
"__rpow__",
73-
"__rrshift__",
74-
"__rshift__",
75-
"__rsub__",
76-
"__rxor__",
7735
"__setattr__",
7836
"__setitem__",
7937
"__str__",
80-
"__sub__",
8138
"__unicode__",
82-
"__xor__",
8339
}
8440

8541
MAGIC_METHODS_ALLOWING_KWARGS = {
@@ -89,8 +45,6 @@
8945
"__call__",
9046
}
9147

92-
MAGIC_METHODS_POS_ARGS_ONLY = MAGIC_METHODS - MAGIC_METHODS_ALLOWING_KWARGS
93-
9448
BINARY_MAGIC_METHODS = {
9549
"__add__",
9650
"__and__",
@@ -138,6 +92,12 @@
13892
"__xor__",
13993
}
14094

95+
assert not (_NON_BINARY_MAGIC_METHODS & BINARY_MAGIC_METHODS)
96+
97+
MAGIC_METHODS = _NON_BINARY_MAGIC_METHODS | BINARY_MAGIC_METHODS
98+
99+
MAGIC_METHODS_POS_ARGS_ONLY = MAGIC_METHODS - MAGIC_METHODS_ALLOWING_KWARGS
100+
141101

142102
def special_function_elide_names(name: str) -> bool:
143103
return name in MAGIC_METHODS_POS_ARGS_ONLY

0 commit comments

Comments
 (0)