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
1111 Python 2 specific handling will be removed at some point.
1212 * Linux wheels are now provided in `musllinux ` and `manylinux2014 ` variants.
1313
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+
14181.6.0 (2021-03-22)
1519------------------
1620
Original file line number Diff line number Diff line change @@ -233,7 +233,13 @@ def __ror__(self, other):
233233 __float__ = make_proxy_method (float )
234234 __oct__ = make_proxy_method (oct )
235235 __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+
237243 __len__ = make_proxy_method (len )
238244 __contains__ = make_proxy_method (operator .contains )
239245 __getitem__ = make_proxy_method (operator .getitem )
Original file line number Diff line number Diff line change @@ -392,7 +392,10 @@ def __hex__(self):
392392 return hex (self .__wrapped__ )
393393
394394 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__ )
396399
397400 def __len__ (self ):
398401 return len (self .__wrapped__ )
You can’t perform that action at this time.
0 commit comments