This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author steven.daprano
Recipients ojob, steven.daprano
Date 2021-09-29.15:56:10
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1632930970.09.0.203977779052.issue45323@roundup.psfhosted.org>
In-reply-to
Content
If you are working in the interactive interpreter, you may be running into a conflict with the "magic" variable `_` which the interactive interpreter creates to hold the result of the last evaluated statement.

So when you evaluate `x`, and that returns the string "robert", it also gets assigned to `_`. But you can't easily delete `_` because it lives in the builtin namespace, not the global namespace.

This happens with anything, not just match statements:


>>> x = "spam eggs"
>>> x
'spam eggs'
>>> _
'spam eggs'
>>> del _  # Not a global, can't delete it!
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name '_' is not defined


So I think the weird behaviour with _ that you have stumbled over is a red herring.

However, it does seem to me that *perhaps* the assignment to x shouldn't be occurring at all. So that may be a bug in the match statement?
History
Date User Action Args
2021-09-29 15:56:10steven.dapranosetrecipients: + steven.daprano, ojob
2021-09-29 15:56:10steven.dapranosetmessageid: <1632930970.09.0.203977779052.issue45323@roundup.psfhosted.org>
2021-09-29 15:56:10steven.dapranolinkissue45323 messages
2021-09-29 15:56:10steven.dapranocreate