[issue23091] unpacked keyword arguments are not unicode normalized

2014-12-19 Thread S. Andrew Sheppard

S. Andrew Sheppard added the comment:

Fair enough.  For future reference by anyone coming across this issue, here's a 
simplified version of the workaround I used:

from unicodedata import normalize
def normalize_keys(data):
return {
normalize('NFKC', key): value
for key, value in data.items()
}

def test(μ):
print(μ)

>>> test(**normalize_keys({'µ': "test4"}))
test4

--

___
Python tracker 
<http://bugs.python.org/issue23091>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue23091] unpacked keyword arguments are not unicode normalized

2014-12-19 Thread S. Andrew Sheppard

S. Andrew Sheppard added the comment:

Here's a simple namedtuple example for good measure.

from collections import namedtuple
Test = namedtuple("Test", [chr(181)])

>>> Test(**{chr(956): "test1"})
Test(µ='test1')

>>> Test(**{chr(181): "test1"})
Traceback (most recent call last):
  File "", line 1, in 
TypeError: __new__() got an unexpected keyword argument 'µ'

--

___
Python tracker 
<http://bugs.python.org/issue23091>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue23091] unpacked keyword arguments are not unicode normalized

2014-12-19 Thread S. Andrew Sheppard

New submission from S. Andrew Sheppard:

I came across unexpected behavior working with unpacking keyword arguments in 
Python 3.  It appears to be related to the automatic normalization of unicode 
characters to NFKC (PEP 3131), which converts e.g. MICRO SIGN to GREEK SMALL 
LETTER MU.  This conversion is applied to regular keyword arguments but not 
when unpacking arguments via **.

This issue arose while I was working with some automatically generated 
namedtuple classes, but I was able to reproduce it with a simple function:

def test(μ):
print(μ)

>>> test(µ="test1") # chr(181)
test1

>>> test(μ="test2") # chr(956)
test2

>>> test(**{'μ': "test3"}) # chr(956)
test3

>>> test(**{'µ': "test4"}) # chr(181)

Traceback (most recent call last):
  File "", line 1, in 
TypeError: test() got an unexpected keyword argument 'µ'


I can obviously work around this, but wanted to bring it up in case it's a bug. 
 My naive expectation would be that unpacked ** keys should be treated exactly 
like normal keyword arguments.

--
components: Unicode
messages: 232956
nosy: ezio.melotti, haypo, sheppard
priority: normal
severity: normal
status: open
title: unpacked keyword arguments are not unicode normalized
versions: Python 3.4

___
Python tracker 
<http://bugs.python.org/issue23091>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com