Unicode string not accepted as parameter to modification

Bug #525991 reported by Jon Black
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
python-quantities
Fix Committed
High
Darren Dale

Bug Description

I tried to pass the unit type during a conversion as a unicode string...

q = pq.Quantity([10,], u"kg")
q.units = u"kg"

...and got the following error for both lines...

TypeError: units must be a quantity, string, or dimensionality, got <type 'unicode'>

I would expect this to work. Firstly, because unicode is a string with a certain encoding (utf-8), and secondly because to me u"kg" and "kg" represent the same symbol.

Related branches

Revision history for this message
Jon Black (juan-black) wrote :

I noticed that you can set unicode in the markup:

from quantities import markup
markup.config.use_unicode = True # or False

This had no affect; I still got the same error message.

Revision history for this message
Darren Dale (dsdale24) wrote :

Setting unicode in markup only effects the presentation of units when you ask for a string representation str(my_quantity). That is a feature, not a bug.

Concerning the original report, this is fixed in the trunk. When specifying units with a string, that string needs to be valid python. So it is ok to use u"ohm", but not "Ω". This limitation should be lifted once quantities is available for python-3.

Changed in python-quantities:
assignee: nobody → Darren Dale (dsdale24)
importance: Undecided → High
milestone: none → 0.8.0
status: New → Fix Committed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.