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.

classification
Title: Unicode function arguments aren't preserved
Type: behavior Stage: resolved
Components: Unicode Versions: Python 3.6
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: eric.smith, ezio.melotti, mcleonard, steven.daprano, vstinner
Priority: normal Keywords:

Created on 2018-05-20 21:51 by mcleonard, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
Screen Shot 2018-05-20 at 2.32.05 PM.png mcleonard, 2018-05-20 21:51 Image showing behavior
Messages (4)
msg317201 - (view) Author: Mat Leonard (mcleonard) * Date: 2018-05-20 21:51
Unicode symbols used as function arguments aren't preserved in the variable names available from .__code__.co_varnames. Example shown below.

def func(ϵ, α, γ, ϕ):
    pass

varnames = func.__code__.co_varnames
print(varnames)
print('ϵ' == varnames[0])
print('α' == varnames[1])
print('γ' == varnames[2])
print('ϕ' == varnames[3])

>> ('ε', 'α', 'γ', 'φ')
>> False
>> True
>> True
>> False

I wrote some code dependent on using function arguments obtained from .__code__.co_varnames in a dictionary. Since the unicode arguments aren't preserved from defining the function and .__code__.co_varnames, the lookup in the dictionary fails.

Looks like same thing happens with the inspect module (maybe .__code__.co_varnames comes from inspect)

inspect.signature(func)
>> <Signature (ε, α, γ, φ)>
msg317202 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2018-05-20 21:59
I think you're seeing identifier normalization. See this SO question for a description of the issue: https://stackoverflow.com/questions/34097193/identifier-normalization-why-is-the-micro-sign-converted-into-the-greek-letter
msg317203 - (view) Author: Mat Leonard (mcleonard) * Date: 2018-05-20 22:28
Ah great, then I just need to do something
like unicodedata.normalize('NFKC', 'Ω'). Thanks!

On Sun, May 20, 2018 at 2:59 PM Eric V. Smith <report@bugs.python.org>
wrote:

>
> Eric V. Smith <eric@trueblade.com> added the comment:
>
> I think you're seeing identifier normalization. See this SO question for a
> description of the issue:
> https://stackoverflow.com/questions/34097193/identifier-normalization-why-is-the-micro-sign-converted-into-the-greek-letter
>
> ----------
> nosy: +eric.smith
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <https://bugs.python.org/issue33588>
> _______________________________________
>
msg317206 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2018-05-20 23:07
This does seem to be a normalisation issue:

py> unicodedata.normalize('NFKC', 'ϵαγϕ') == ''.join(func.__code__.co_varnames)
True

so I'm closing this as not a bug.

Mike, thank you for copying and pasting the relevant text into the bug report, but for future reference, there is no need to duplicate that information with a redundant screen shots of text for bug report. (Unless you are reporting a specifically visual bug e.g. a display problem with the turtle module.) The content of screen shots cannot be searched for, or copied and pasted, and they make it difficult for the blind and visually impaired who use screen readers.
History
Date User Action Args
2022-04-11 14:59:00adminsetgithub: 77769
2018-05-20 23:07:28steven.dapranosetstatus: open -> closed

nosy: + steven.daprano
messages: + msg317206

resolution: not a bug
stage: resolved
2018-05-20 22:28:09mcleonardsetmessages: + msg317203
2018-05-20 21:59:49eric.smithsetnosy: + eric.smith
messages: + msg317202
2018-05-20 21:51:51mcleonardcreate