Structural pattern matching and mangling private names

For this code: class C: def f(self, x): match x: case D(__something=y): return y It appears that the name "__something" isn't mangled. Under most other circumstances I'd expect this to be mangled to "_C__something". Is this: * intentional, * accidental, but how that it's done it's the defined behaviour, * or a defect? It doesn't seem like it's explicitly tested for in test_patma.py either way. Thanks David

I don't remember this topic ever being discussed, but still I wouldn't expect that __something to be mangled, given that it refers to an attribute of an instance of D. I might expect that in a "case D(something=__y)" you get the mangling for __y, but I'm not sure what the implementation does now and I'm writing from my phone On Wed, 15 Jun 2022, 20:12 , <dw-git@d-woods.co.uk> wrote:

If you want any kind of traction on this I recommend filing an opinionated issue on this (explaining why the current behavior is wrong). On Wed, Jun 15, 2022 at 1:25 PM <dw-git@d-woods.co.uk> wrote:
-- --Guido van Rossum (python.org/~guido) *Pronouns: he/him **(why is my pronoun here?)* <http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-c...>

Guido van Rossum wrote:
If you want any kind of traction on this I recommend filing an opinionated issue on this (explaining why the current behavior is wrong).
Thanks - I'm asking from the point of view of trying to reimplement it. I don't actually have a strong opinion on whether the current behaviour is wrong - I'd just like to know if I should match it. From that point of view I've deviated from your advice slightly and created a PR instead to add a test for the current behaviour (https://github.com/python/cpython/pull/94500). Hopefully that'll either fix it is "intended" or stir up a different decision. I'm happy with either outcome. David

Having thought about it some more, I agree with Daniel Moisset that the current behavior is correct -- in D(__foo=bar), __foo is a keyword arg position and those don't get mangled. Anyway, anything mangled would get mangled according to the containing class (in your example, C), not according to the class appearing in the call. Using the called class for mangling would set a dangerous precedent. So there's your answer -- the current behavior is as it should be. I'll look into the patch with that in mind. On Fri, Jul 1, 2022 at 10:54 AM <dw-git@d-woods.co.uk> wrote:
-- --Guido van Rossum (python.org/~guido) *Pronouns: he/him **(why is my pronoun here?)* <http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-c...>

I don't remember this topic ever being discussed, but still I wouldn't expect that __something to be mangled, given that it refers to an attribute of an instance of D. I might expect that in a "case D(something=__y)" you get the mangling for __y, but I'm not sure what the implementation does now and I'm writing from my phone On Wed, 15 Jun 2022, 20:12 , <dw-git@d-woods.co.uk> wrote:

If you want any kind of traction on this I recommend filing an opinionated issue on this (explaining why the current behavior is wrong). On Wed, Jun 15, 2022 at 1:25 PM <dw-git@d-woods.co.uk> wrote:
-- --Guido van Rossum (python.org/~guido) *Pronouns: he/him **(why is my pronoun here?)* <http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-c...>

Guido van Rossum wrote:
If you want any kind of traction on this I recommend filing an opinionated issue on this (explaining why the current behavior is wrong).
Thanks - I'm asking from the point of view of trying to reimplement it. I don't actually have a strong opinion on whether the current behaviour is wrong - I'd just like to know if I should match it. From that point of view I've deviated from your advice slightly and created a PR instead to add a test for the current behaviour (https://github.com/python/cpython/pull/94500). Hopefully that'll either fix it is "intended" or stir up a different decision. I'm happy with either outcome. David

Having thought about it some more, I agree with Daniel Moisset that the current behavior is correct -- in D(__foo=bar), __foo is a keyword arg position and those don't get mangled. Anyway, anything mangled would get mangled according to the containing class (in your example, C), not according to the class appearing in the call. Using the called class for mangling would set a dangerous precedent. So there's your answer -- the current behavior is as it should be. I'll look into the patch with that in mind. On Fri, Jul 1, 2022 at 10:54 AM <dw-git@d-woods.co.uk> wrote:
-- --Guido van Rossum (python.org/~guido) *Pronouns: he/him **(why is my pronoun here?)* <http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-c...>
participants (3)
-
Daniel Moisset
-
dw-git@d-woods.co.uk
-
Guido van Rossum