dsc / bunch

A Bunch is a Python dictionary that provides attribute-style access (a la JavaScript objects).
http://github.com/dsc/bunch
MIT License
482 stars 177 forks source link

Bunch is completely broken when using unicode strings #10

Open bjorkegeek opened 11 years ago

bjorkegeek commented 11 years ago

Test using dictionary:

>>> d={}
>>> d[u'r\xf6k']="smoke"
>>> u'r\xf6k' in d
True
>>> print repr(d)
{u'r\xf6k': 'smoke'}

Test using bunch:

>>> b=Bunch()
>>> b[u'r\xf6k']="smoke"
>>> u'r\xf6k' in b
False
>>> print repr(b)
Traceback (most recent call last):
  File "", line 1, in 
UnicodeEncodeError: 'ascii' codec can't encode character u'\xf6' in position 7: ordinal not in range(128)
mikenerone commented 10 years ago

A couple of observations:

  1. The proposed patch breaks some functionality, such as the ability to change the value of an existing actual attribute on the object (more likely to be an issue with subclasses of Bunch).
  2. At a glance, it looks like the unicode breakage is only in __repr__(), so is cosmetic.

In any case, it looks to me like this project might not be maintained anymore.

dsc commented 2 weeks ago

I'll add these as a test.