New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Converting a constant to a Quantity breaks __repr__ #3537
Conversation
mhvk
commented
Feb 23, 2015
The problem here (and perhaps also with #3538) is that
|
OK, the now attached fixes to |
ping @embray since he wrote a lot of the constants code |
@@ -159,10 +159,10 @@ def name(self): | |||
return self._name | |||
|
|||
@lazyproperty | |||
def unit(self): | |||
def _unit(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we are privatizing a public property here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, not quite so bad: since Constant
subclasses from Quantity
, it still has the unit
property (which just returns _unit
, i.e., this thing here). I had to make sure, though, that _unit
was a Unit
instance, which is what this lazyproperty
takes care of.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see. Makes sense, then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not entirely sure I follow though. Why do we need the property at all if this is also handled by Quantity
now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I am the one who misunderstood: Constants
are intialised with units passed in as a string. My impression was that this unit could not be parsed immediately since some units depend on constants. Is this true? I thought this was the reason they were passed through Unit
only later, using lazyproperty
. The change I made was to rename the string-based unit from _unit
to _unit_string
, so that both _unit
and unit
can return Unit
objects (since it was a problem for Quantity
if _unit
was a string rather than a Unit
instance).
Just to explain: part of the logic of changing |
Just so I'm clear here, is the default here going to be equivalent to |
@embray - if one passes through |
Okay. I guess that's fine--most of the time if someone where doing |
@embray - indeed, the issue was triggered by |
Sounds like for the most part there's no further issue here so I'll go ahead and merge. |
Converting a constant to a Quantity breaks __repr__
Converting a constant to a Quantity breaks __repr__