mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
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>
This commit is contained in:
parent
4a6bb30eb6
commit
8d7089f0a0
1 changed files with 14 additions and 0 deletions
|
@ -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):
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue