You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Docs: note requirement to normalise unicode identifiers passed to globals() and locals() #86846
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=Nonecreated_at=<Date2020-12-19.00:27:18.270>labels= ['3.8', 'type-bug', '3.7', '3.9', 'expert-unicode']
title='unicode identifiers not accessible or assignable through globals()'updated_at=<Date2021-01-20.10:46:27.879>user='https://github.com/outofculture'
Yes, it's clear when I read https://www.python.org/dev/peps/pep-3131/ that the normalization is going to happen. Is it also worth adding a note in the documentation for globals() and locals()? That's the first place I looked to try to find out what was wrong.
Activity
outofculture commentedon Dec 19, 2020
This behavior is best described by the code below:
Testing was done on linux and windows, variously using 3.6.12, 3.7.6, 3.8.6 and 3.9.0+.
outofculture commentedon Dec 19, 2020
Oh, I just gave a cursory using
locals(), and the same misbehavior is present.A workaround, for anyone needing to assign or access unicode globals, is to use
exec, e.g.exec("µmeow = 1e-6", globals()).stevendaprano commentedon Dec 19, 2020
I'm pretty sure this is not a bug, but is working as designed.
The interpreter normalises unicode identifiers, but key lookup in the dict does not.
Sorry, I don't have time right now to give a more detailed answer, but there are two distinct mu characters:
and my prediction is that the identifier is normalised to the first, the actual Greek mu, but you are looking up the second, the micro sign.
(I'll be able to give a longer response in a couple of hours, if still needed.)
outofculture commentedon Dec 19, 2020
Ah! So then the proper code for me would be e.g.:
Yes, it's clear when I read https://www.python.org/dev/peps/pep-3131/ that the normalization is going to happen. Is it also worth adding a note in the documentation for
globals()andlocals()? That's the first place I looked to try to find out what was wrong.ericvsmith commentedon Dec 20, 2020
I think documenting this with globals() and locals() is a good idea. That's the place this is most likely to trip someone up.
3 remaining items
ncoghlan commentedon Aug 1, 2024
Updated issue title and labels to reflect the previous discussion.
encukou commentedon Nov 26, 2025
Documented as a note in https://docs.python.org/3.15/reference/lexical_analysis.html#non-ascii-characters-in-names
I think that's the proper place, as that where Python does the normalization.
globals()itself is perfectly fine with non-normalized keys:Let's reopen if someone disagrees.