engineering_notation icon indicating copy to clipboard operation
engineering_notation copied to clipboard

EngUnit doesn't handle __init__ from other EngUnits properly

Open SMMB-DEV opened this issue 10 months ago • 0 comments

Suppose I want to divide a voltage by a resistance and give it the unit A.

V = EngUnit(5, unit='V')
R = EngUnit(1.2, unit='Ω')
I = V / R
I.unit = 'A'

If I instead do this:

I = EngUnit(V / R, unit='A')

when I try to print I, I get an exception saying "'EngNumber' object has no attribute 'number'".

EngUnit has an eng_num member of type EngNumber. If the value passed to EngUnit.__init__() isn't a string, it tries to create an EngNumber direcly from value. Inside EngNumber.__init__(), value has to be one of str, int, float, EngNumber or numpy.integer and since the value here is none of those (EngUnit), it doesn't create the number member of EngNumber.

SMMB-DEV avatar Feb 27 '25 11:02 SMMB-DEV