mirror of
https://github.com/python/cpython.git
synced 2025-08-01 07:33:08 +00:00
#2592: delegate nb_index and the floor/truediv slots in weakref.proxy.
This commit is contained in:
parent
112aa50329
commit
88659b0ab2
3 changed files with 35 additions and 1 deletions
|
@ -3,6 +3,7 @@ import sys
|
|||
import unittest
|
||||
import UserList
|
||||
import weakref
|
||||
import operator
|
||||
|
||||
from test import test_support
|
||||
|
||||
|
@ -187,6 +188,26 @@ class ReferencesTestCase(TestBase):
|
|||
self.assertEqual(L3[:5], p3[:5])
|
||||
self.assertEqual(L3[2:5], p3[2:5])
|
||||
|
||||
def test_proxy_index(self):
|
||||
class C:
|
||||
def __index__(self):
|
||||
return 10
|
||||
o = C()
|
||||
p = weakref.proxy(o)
|
||||
self.assertEqual(operator.index(p), 10)
|
||||
|
||||
def test_proxy_div(self):
|
||||
class C:
|
||||
def __floordiv__(self, other):
|
||||
return 42
|
||||
def __ifloordiv__(self, other):
|
||||
return 21
|
||||
o = C()
|
||||
p = weakref.proxy(o)
|
||||
self.assertEqual(p // 5, 42)
|
||||
p //= 5
|
||||
self.assertEqual(p, 21)
|
||||
|
||||
# The PyWeakref_* C API is documented as allowing either NULL or
|
||||
# None as the value for the callback, where either means "no
|
||||
# callback". The "no callback" ref and proxy objects are supposed
|
||||
|
@ -1059,7 +1080,7 @@ class WeakKeyDictionaryTestCase(mapping_tests.BasicTestMappingProtocol):
|
|||
def _reference(self):
|
||||
return self.__ref.copy()
|
||||
|
||||
libreftest = """ Doctest for examples in the library reference: libweakref.tex
|
||||
libreftest = """ Doctest for examples in the library reference: weakref.rst
|
||||
|
||||
>>> import weakref
|
||||
>>> class Dict(dict):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue