Skip to content
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

Remove the _Unit factory, and make it a class method. #131

Merged
merged 1 commit into from
Jan 17, 2019

Conversation

pelson
Copy link
Member

@pelson pelson commented Jan 17, 2019

There is a somewhat bizarre _Unit factory function that is there to allow construction of a unit if we already have the Udunits handle, and don't need to go through full __init__.

Unfortunately, this factory is hiding the fact that it is an optimisation, and should IMO be much more explicit about the fact. The problem of how well concealed the _Unit vs Unit is highlighted by the existing implementation, which is being addressed in #125. In this PR, I fix this by not short-circuiting __init__ when we don't need to.

This then is an alternative to #125.

@@ -1509,15 +1513,16 @@ def _op_common(self, other, op_func):
raise ValueError("Cannot %s a 'no-unit'." % op_label)

if self.is_unknown() or other.is_unknown():
result = _Unit(_CATEGORY_UNKNOWN, None)
result = Unit(_UNKNOWN_UNIT_STRING)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the alternative to #125. Really, let's avoid encoding the meaning of UNKNOWN unit in multiple places, and let the constructor (__init__) deal with it.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.01%) to 88.263% when pulling 4d65147 on pelson:_Unit_remove into 502d014 on SciTools:master.

@pelson pelson requested a review from bjlittle January 17, 2019 10:12
@bjlittle bjlittle self-assigned this Jan 17, 2019
@bjlittle bjlittle merged commit 1836f32 into SciTools:master Jan 17, 2019
@pelson pelson deleted the _Unit_remove branch February 2, 2019 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants