GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Docs: note requirement to normalise unicode identifiers passed to globals() and locals() · Issue #86846 · python/cpython

Docs: note requirement to normalise unicode identifiers passed to globals() and locals() #86846

New issue
Copy link
New issue
Copy link
Closed
#140464
Closed
Docs: note requirement to normalise unicode identifiers passed to globals() and locals()#86846
#140464
Copy link
Labels
docsDocumentation in the Doc dirDocumentation in the Doc dirtopic-unicode

Description

outofculture
mannequin
opened on Dec 19, 2020
Issue body actions
BPO 42680
Nosy @ericvsmith, @ezio-melotti, @stevendaprano, @outofculture

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 = None
closed_at = None
created_at = <Date 2020-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 = <Date 2021-01-20.10:46:27.879>
user = 'https://github.com/outofculture'

bugs.python.org fields:

activity = <Date 2021-01-20.10:46:27.879>
actor = 'vstinner'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Unicode']
creation = <Date 2020-12-19.00:27:18.270>
creator = 'outofculture'
dependencies = []
files = []
hgrepos = []
issue_num = 42680
keywords = []
message_count = 5.0
messages = ['383336', '383338', '383340', '383348', '383462']
nosy_count = 4.0
nosy_names = ['eric.smith', 'ezio.melotti', 'steven.daprano', 'outofculture']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue42680'
versions = ['Python 3.6', 'Python 3.7', 'Python 3.8', 'Python 3.9']

Activity

Next
  1. outofculture commented on Dec 19, 2020

    @outofculture
    outofculturemannequin
    on Dec 19, 2020
    MannequinAuthor
    More actions

    This behavior is best described by the code below:

    >>> meow = 1
    >>> 'meow' in globals()
    True
    >>> µmeow = 1e-6
    >>> 'µmeow' in globals()
    False
    >>> globals()['woof'] = 1
    >>> woof
    1
    >>> globals()['µwoof'] = 1e-6
    >>> µwoof
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    NameError: name 'μwoof' is not defined
    >>> import sys
    >>> sys.getdefaultencoding()
    'utf-8'
    >>> [(k, bytes(k, 'utf-8')) for k in globals()]
    ..., ('μmeow', b'\xce\xbcmeow'), ('µwoof', b'\xc2\xb5woof')]
    >>> 'µ'.encode('utf-8')
    b'\xc2\xb5'
    

    Testing was done on linux and windows, variously using 3.6.12, 3.7.6, 3.8.6 and 3.9.0+.

  2. outofculture
    added
    3.7 (EOL)end of lifeend of life
    3.8 (EOL)end of lifeend of life
    3.9 (EOL)end of lifeend of life
    topic-unicode
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Dec 19, 2020
  3. outofculture commented on Dec 19, 2020

    @outofculture
    outofculturemannequin
    on Dec 19, 2020
    MannequinAuthor
    More actions

    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()).

  4. stevendaprano commented on Dec 19, 2020

    @stevendaprano
    stevendaprano
    on Dec 19, 2020
    Member
    More actions

    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:

    μ U+03BC
    µ U+00B5
    

    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.)

  5. outofculture commented on Dec 19, 2020

    @outofculture
    outofculturemannequin
    on Dec 19, 2020
    MannequinAuthor
    More actions

    Ah! So then the proper code for me would be e.g.:

    >>> globals()[unicodedata.normalize("NFKC", "µmeow")]
    1e-06
    

    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.

  6. ericvsmith commented on Dec 20, 2020

    @ericvsmith
    ericvsmith
    on Dec 20, 2020
    Member
    More actions

    I think documenting this with globals() and locals() is a good idea. That's the place this is most likely to trip someone up.

  7. 3 remaining items

  8. ncoghlan
    added
    docsDocumentation in the Doc dirDocumentation in the Doc dir
    3.13only security fixesonly security fixes
    3.14bugs and security fixesbugs and security fixes
    and removed
    3.9 (EOL)end of lifeend of life
    3.8 (EOL)end of lifeend of life
    3.7 (EOL)end of lifeend of life
    on Aug 1, 2024
  9. ncoghlan commented on Aug 1, 2024

    @ncoghlan
    ncoghlan
    on Aug 1, 2024
    Contributor
    More actions

    Updated issue title and labels to reflect the previous discussion.

  10. StanFromIreland
    marked Unicode is normalised after keywords are checked for #77886 as a duplicate of this issue on Sep 26, 2025
  11. StanFromIreland
    removed
    3.13only security fixesonly security fixes
    3.14bugs and security fixesbugs and security fixes
    on Sep 26, 2025
  12. github-project-automation
    added this to docs issueson Sep 26, 2025
  13. github-project-automation
    moved this to Todo in docs issueson Sep 26, 2025
  14. StanFromIreland
    linked a pull request that will close this issuegh-135676: Simplify docs on lexing names #140464on Oct 22, 2025
  15. encukou
    closed this as completedin #140464on Nov 26, 2025
  16. encukou commented on Nov 26, 2025

    @encukou
    encukou
    on Nov 26, 2025
    Member
    More actions

    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:

    >>> fix = False
    >>> globals()['fix']
    False
    >>> globals()['fix'] = True
    >>> globals()['fix']
    True
    

    Let's reopen if someone disagrees.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dirDocumentation in the Doc dirtopic-unicode

    Projects

    • docs issues
      Status
      Todo
      Show more project fields

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.