Revision f8f86d24-2e33-43eb-b27a-6ce3ef018e74 - Stack Overflow

Python 3.8 supports using a limited set of non-ASCII unicode characters in identifiers. So, it seemts that it is valid to use 𝚺 as a character in an identifier.

However, something is wrong...

**Problem**

 def f(𝚺):
 print(f'{𝚺=}')
 
 f(1)
 f(𝚺=2)
 f(**{'𝚺': 3})

First two calls are fine, but the third fails:

 𝚺=1
 𝚺=2
 Traceback (most recent call last):
 File "sigma.py", line 24, in <module>
 f(**{'𝚺': 3})
 TypeError: f() got an unexpected keyword argument '𝚺'


**Analysis**

Let's see what is actually going on:

 def f2(**kw):
 for name, value in kw.items():
 print(f'{name}={value} {ord(name)=}')
 f2(𝚺=2)
 f2(**{'𝚺': 3})

It prints:

 Σ=2 ord(name)=931
 𝚺=3 ord(name)=120506

I called it with 𝚺 both times, but it was changed to the very similar *simpler* Σ in the first call.

It seems that an argument named 𝚺 is implicitly renamed to Σ and in every call to the function, argument 𝚺 is also implicitly renamed to Σ, except if it is passed as `**kwargs`.

**The Questions**

Is this a bug? It does not look like it is accidental. Is it documented? Is there a set of *true* characters and a list of *alias* characters available somewhere?


AltStyle によって変換されたページ (->オリジナル) /