8000 gh-94499 Add test for private name mangling in class pattern matching by da-woods · Pull Request #94500 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-94499 Add test for private name mangling in class pattern matching #94500

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 4 commits into from
Jul 13, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add test for private name mangling in class pattern matching
The current status quo is that private attribute names are not
mangled when a class is matched. I've added a test to
document/legimize this behaviour.
  • Loading branch information
da-woods committed Jul 13, 2022
commit 39b2acd253256377dee07841d1143b7dc64849f1
15 changes: 15 additions & 0 deletions Lib/test/test_patma.py
Original file line number Diff line number Diff line change
Expand Up @@ -2654,6 +2654,21 @@ def get(key, default=None):

self.assertEqual(y, 'bar')

def test_patma_249(self):
class C:
pass
class Outer:
def f(self, x):
match x:
# looks up __attr, not _C__attr or _Outer__attr
case C(__attr=y):
return y
c = C()
setattr(c, "__attr", 1)
setattr(c, "_Outer__attr", 2)
setattr(c, "_C__attr", 3)
self.assertEqual(Outer().f(c), 1)


class TestSyntaxErrors(unittest.TestCase):

Expand Down
0