Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

gh-120906: Support arbitrary hashable keys in FrameLocalsProxy #122309

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jul 30, 2024
Prev Previous commit
Next Next commit
Apply test suggestions from code review
Co-authored-by: Alyssa Coghlan <ncoghlan@gmail.com>
  • Loading branch information
encukou and ncoghlan authored Jul 27, 2024
commit 4bba239465c4ca27f0c062aca20b00a1434ca4b5
22 changes: 12 additions & 10 deletions 22 Lib/test/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,19 +448,21 @@ def f(obj):
proxy = sys._getframe().f_locals
proxy[obj] = 2
return (
proxy.keys() == ['obj', 'x', 'proxy'],
proxy == {'obj': 'x', 'x': 2, 'proxy': proxy},
list(proxy.keys()),
dict(proxy),
proxy
)

for obj in StringSubclass('x'), ImpostorX():
with self.subTest(cls=type(obj).__name__):

assertion1, assertion2, proxy = f(obj)
self.assertEqual(proxy.keys(), ['obj', 'x', 'proxy'])
self.assertEqual(proxy, {'obj': 'x', 'x': 2, 'proxy': proxy})
self.assertTrue(assertion1)
self.assertTrue(assertion2)
keys_snapshot, proxy_snapshot, proxy = f(obj)
expected_keys = ['obj', 'x', 'proxy']
expected_dict = {'obj': 'x', 'x': 2, 'proxy': proxy}
self.assertEqual(proxy.keys(), expected_keys)
self.assertEqual(proxy, expected_dict)
self.assertEqual(keys_snapshot, expected_keys)
self.assertEqual(proxy_snapshot, expected_dict)

def test_proxy_key_unhashables(self):
class StringSubclass(str):
Expand Down Expand Up @@ -488,7 +490,7 @@ def _f():
return _f()
type2test = _f

@unittest.skipIf(True, 'Unlike a mapping: empty proxy != empty proxy')
@unittest.skipIf(True, 'Locals proxies for different frames never compare as equal')
def test_constructor(self):
pass

Expand Down Expand Up @@ -527,7 +529,7 @@ def test_getitem(self):
def test_update(self):
pass

# proxy.copy rerourns a regular dict
# proxy.copy returns a regular dict
def test_copy(self):
d = self._full_mapping({1:1, 2:2, 3:3})
self.assertEqual(d.copy(), {1:1, 2:2, 3:3})
Expand All @@ -537,7 +539,7 @@ def test_copy(self):

self.assertIsInstance(d.copy(), dict)

@unittest.skipIf(True, 'Unlike a mapping: empty proxy != empty proxy')
@unittest.skipIf(True, 'Locals proxies for different frames never compare as equal')
def test_eq(self):
pass

Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.