File tree Expand file tree Collapse file tree 2 files changed +59
-21
lines changed Expand file tree Collapse file tree 2 files changed +59
-21
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
12
12
### Changed
13
13
* Updated dozens of type annotations in the compiler to satisfy MyPy 1.11 (#910 )
14
14
* Update the ` StreamReader ` methods to stop using the term "token" to refer to individual UTF-8 characters (#915 )
15
+ * Update the list of Python dunder methods which are allowed to be implemented for all ` deftype* ` and ` reify* ` types (#943 )
15
16
16
17
### Fixed
17
18
* Fix a bug where ` . ` characters were not allowed in keyword names (#899 )
Original file line number Diff line number Diff line change @@ -86,91 +86,113 @@ def is_abstract(tp: Type) -> bool:
86
86
)
87
87
88
88
89
- # Trimmed list of __dunder__ methods generated by using this command:
89
+ # Trimmed list of __dunder__ methods generated by using this shell command:
90
90
#
91
- # find "$(poetry env info -p)/lib/python3.6" \
92
- # -name '*.py' \
93
- # -exec egrep \
94
- # -oh '__[A-Za-z_][A-Za-z_0-9]*__' '{}' \; \
95
- # | sort | uniq
91
+ # curl https://raw.githubusercontent.com/python/cpython/main/Doc/reference/datamodel.rst \
92
+ # | egrep -oh '__[a-z_][A-Za-z_0-9]*__' \
93
+ # | sort \
94
+ # | uniq
95
+ #
96
+ # Running the above command will yield a list of dunders from the Python 'Data Model'
97
+ # documentation page, but many of those matches will be false positives. Many hits
98
+ # are object properties (such as __doc__ and __name__) and others are not dunders
99
+ # at all (such as the unfortunately named __future__ module).
100
+ #
101
+ # Unfortunately we can't introspect this list from Python itself, so it's going to be
102
+ # a moving target as the data model changes over time.
103
+ #
104
+ # Note that some Python standard library modules and packages define their own dunder
105
+ # methods which are not documented in the data model documentation which are included
106
+ # in separate sets below.
96
107
OBJECT_DUNDER_METHODS = frozenset (
97
108
{
98
109
"__abs__" ,
99
110
"__add__" ,
100
111
"__aenter__" ,
101
112
"__aexit__" ,
102
113
"__aiter__" ,
114
+ "__and__" ,
115
+ "__anext__" ,
103
116
"__await__" ,
117
+ "__bool__" ,
118
+ "__buffer__" ,
104
119
"__bytes__" ,
105
120
"__call__" ,
121
+ "__ceil__" ,
122
+ "__class_getitem__" ,
106
123
"__complex__" ,
107
124
"__contains__" ,
108
125
"__del__" ,
109
126
"__delattr__" ,
127
+ "__delete__" ,
110
128
"__delitem__" ,
111
- "__delslice__" ,
112
129
"__dict__" ,
113
130
"__dir__" ,
114
- "__div__" ,
115
131
"__divmod__" ,
116
132
"__enter__" ,
117
133
"__eq__" ,
118
134
"__exit__" ,
119
135
"__float__" ,
136
+ "__floor__" ,
120
137
"__floordiv__" ,
138
+ "__format__" ,
121
139
"__ge__" ,
140
+ "__get__" ,
122
141
"__getattr__" ,
123
142
"__getattribute__" ,
124
143
"__getitem__" ,
125
- "__getslice__" ,
126
- "__getstate__" ,
127
144
"__gt__" ,
128
145
"__hash__" ,
129
146
"__iadd__" ,
130
147
"__iand__" ,
131
- "__idiv__" ,
132
148
"__ifloordiv__" ,
133
149
"__ilshift__" ,
134
150
"__imatmul__" ,
135
151
"__imod__" ,
136
152
"__imul__" ,
153
+ "__index__" ,
137
154
"__init__" ,
155
+ "__init_subclass__" ,
138
156
"__instancecheck__" ,
139
157
"__int__" ,
140
158
"__invert__" ,
141
159
"__ior__" ,
142
160
"__ipow__" ,
161
+ "__irshift__" ,
143
162
"__isub__" ,
144
163
"__iter__" ,
145
164
"__itruediv__" ,
146
165
"__ixor__" ,
147
166
"__le__" ,
148
167
"__len__" ,
168
+ "__length_hint__" ,
149
169
"__lshift__" ,
170
+ "__lt__" ,
171
+ "__match_args__" ,
150
172
"__matmul__" ,
173
+ "__missing__" ,
151
174
"__mod__" ,
175
+ "__mro_entries__" ,
152
176
"__mul__" ,
153
177
"__ne__" ,
154
178
"__neg__" ,
155
- "__next__" ,
156
179
"__new__" ,
157
- "__not__" ,
180
+ "__next__" ,
181
+ "__or__" ,
158
182
"__pos__" ,
159
183
"__pow__" ,
184
+ "__prepare__" ,
160
185
"__radd__" ,
161
186
"__rand__" ,
162
- "__rcmp__" ,
163
- "__rdiv__" ,
164
187
"__rdivmod__" ,
165
- "__reduce__" ,
166
- "__reduce_ex__" ,
188
+ "__release_buffer__" ,
167
189
"__repr__" ,
190
+ "__reversed__" ,
168
191
"__rfloordiv__" ,
169
192
"__rlshift__" ,
170
193
"__rmatmul__" ,
171
194
"__rmod__" ,
172
195
"__rmul__" ,
173
- "__rne__" ,
174
196
"__ror__" ,
175
197
"__round__" ,
176
198
"__rpow__" ,
@@ -179,17 +201,32 @@ def is_abstract(tp: Type) -> bool:
179
201
"__rsub__" ,
180
202
"__rtruediv__" ,
181
203
"__rxor__" ,
204
+ "__set__" ,
205
+ "__set_name__" ,
182
206
"__setattr__" ,
183
207
"__setitem__" ,
184
- "__setslice__ " ,
185
- "__setstate__ " ,
208
+ "__sizeof__ " ,
209
+ "__slots__ " ,
186
210
"__str__" ,
187
211
"__sub__" ,
188
212
"__subclasscheck__" ,
189
- "__subclasshook__" ,
190
213
"__truediv__" ,
214
+ "__trunc__" ,
191
215
"__xor__" ,
192
216
}
217
+ |
218
+ # Support for ABCs
219
+ {"__subclasshook__" }
220
+ |
221
+ # Support for pickling
222
+ {
223
+ "__getnewargs_ex__" ,
224
+ "__getnewargs__" ,
225
+ "__getstate__" ,
226
+ "__reduce__" ,
227
+ "__reduce_ex__" ,
228
+ "__setstate__" ,
229
+ }
193
230
)
194
231
195
232
You can’t perform that action at this time.
0 commit comments