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 all commits
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
14 changes: 14 additions & 0 deletions Lib/test/test_patma.py
Original file line number Diff line number Diff line change
Expand Up @@ -2654,6 +2654,20 @@ def get(key, default=None):

self.assertEqual(y, 'bar')

def test_patma_249(self):
class C:
__attr = "eggs" # mangled to _C__attr
_Outer__attr = "bacon"
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", "spam") # setattr is needed because we're in a class scope
self.assertEqual(Outer().f(c), "spam")


class TestSyntaxErrors(unittest.TestCase):

Expand Down