summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorda-woods <dw-git@d-woods.co.uk>2022-07-13 16:13:10 (GMT)
committerGitHub <noreply@github.com>2022-07-13 16:13:10 (GMT)
commit8d7089f0a016f905fa7ae04ae1bdb9b14c6aeef6 (patch)
tree5bb2fcab84da8ded7f7b1f683c840638c6b47344
parent4a6bb30eb600e3b18f4a84c1be922c07758c613f (diff)
downloadcpython-8d7089f0a016f905fa7ae04ae1bdb9b14c6aeef6.zip
cpython-8d7089f0a016f905fa7ae04ae1bdb9b14c6aeef6.tar.gz
cpython-8d7089f0a016f905fa7ae04ae1bdb9b14c6aeef6.tar.bz2
gh-94499 Add test for private name mangling in class pattern matching (#94500)
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. Co-authored-by: Brandt Bucher <brandtbucher@gmail.com>
-rw-r--r--Lib/test/test_patma.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/Lib/test/test_patma.py b/Lib/test/test_patma.py
index db198f7..0ed5407 100644
--- a/Lib/test/test_patma.py
+++ b/Lib/test/test_patma.py
@@ -2654,6 +2654,20 @@ class TestPatma(unittest.TestCase):
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):