File tree Expand file tree Collapse file tree 3 files changed +15
-2
lines changed Expand file tree Collapse file tree 3 files changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,10 @@ Changelog
11
11
Python 2 specific handling will be removed at some point.
12
12
* Linux wheels are now provided in `musllinux ` and `manylinux2014 ` variants.
13
13
14
+ * Fixed ``__index__ `` to fallback to ``int `` if the wrapped object doesn't have an ``__index__ `` method.
15
+ This prevents situations where code using a proxy would otherwise likely just call ``int `` had the object
16
+ not have an ``__index__ `` method.
17
+
14
18
1.6.0 (2021-03-22)
15
19
------------------
16
20
Original file line number Diff line number Diff line change @@ -233,7 +233,13 @@ def __ror__(self, other):
233
233
__float__ = make_proxy_method (float )
234
234
__oct__ = make_proxy_method (oct )
235
235
__hex__ = make_proxy_method (hex )
236
- __index__ = make_proxy_method (operator .index )
236
+
237
+ def __index__ (self ):
238
+ if hasattr (self .__wrapped__ , '__index__' ):
239
+ return operator .index (self .__wrapped__ )
240
+ else :
241
+ return int (self .__wrapped__ )
242
+
237
243
__len__ = make_proxy_method (len )
238
244
__contains__ = make_proxy_method (operator .contains )
239
245
__getitem__ = make_proxy_method (operator .getitem )
Original file line number Diff line number Diff line change @@ -392,7 +392,10 @@ def __hex__(self):
392
392
return hex (self .__wrapped__ )
393
393
394
394
def __index__ (self ):
395
- return operator .index (self .__wrapped__ )
395
+ if hasattr (self .__wrapped__ , '__index__' ):
396
+ return operator .index (self .__wrapped__ )
397
+ else :
398
+ return int (self .__wrapped__ )
396
399
397
400
def __len__ (self ):
398
401
return len (self .__wrapped__ )
You can’t perform that action at this time.
0 commit comments