Skip to content

Commit d1d9fd9

Browse files
Implement test for __getitem__ attribute fallback
1 parent 4a5e6c9 commit d1d9fd9

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Lib/test/test_descr.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6261,5 +6261,23 @@ class IntSubclass(int):
62616261
weakref_descriptor.__get__(IntSubclass(), IntSubclass)
62626262

62636263

6264+
class TestGetItemAttributeFallback(unittest.TestCase):
6265+
6266+
def test_attribute_fallback_for_configview(self):
6267+
class ConfigView:
6268+
def __init__(self, target):
6269+
self.target = target
6270+
6271+
def __getattr__(self, name):
6272+
return getattr(self.target, name)
6273+
6274+
class Config:
6275+
def __getitem__(self, key):
6276+
return ("view", key)
6277+
6278+
cfg = ConfigView(Config())
6279+
self.assertEqual(cfg["x"], ("view", "x"))
6280+
6281+
62646282
if __name__ == "__main__":
62656283
unittest.main()

0 commit comments

Comments
 (0)