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

Unit message helper #377

Merged
merged 4 commits into from
Mar 30, 2017
Merged

Unit message helper #377

merged 4 commits into from
Mar 30, 2017

Conversation

dopplershift
Copy link
Member

@dopplershift dopplershift commented Mar 30, 2017

This adds a decorator that allows us to decorate functions with the dimensionality of arguments (as positional or keyword arguments):

  • Decorated arguments need to be passed with appropriate dimensionality (will catch missing units)
  • Undecorated arguments pass through
  • Dimensionless arguments can be dimensionless or just not have units

Sane handling of positional and keyword arguments relies on function signature arguments added to the inspect module in Python >= 3.3. Thus this isn't available on Python 2.7, and at run time this is a no-op there.

Closes #175.

Some units (like inHg) have a problem with the fractional exponent and
then being converted to dimensionless. Instead, manually ensure this
before taking the power.
This can be used to decorate calculation functions, providing checking
of the dimensionality of paramters and raising helpful messages when
improper arguments are provided. This requires function signature
support from Python >= 3.3. On Python 2.7, this decorator is a no-op at
runtime, but provides no checking.

Pint has its own `check` decorator, but unfortunately this doesn't
provide very helpful error messages.
This should only be applying where it's not going to break API.
@dopplershift dopplershift added Area: Calc Pertains to calculations Type: Enhancement Enhancement to existing functionality labels Mar 30, 2017
@dopplershift
Copy link
Member Author

Well, the "quality" checkers all hate this for stupid reasons. Ignore those.

Copy link
Contributor

@jrleeman jrleeman left a comment

Choose a reason for hiding this comment

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

Assuming all the tests pass, I'll merge if you're ready. It looks good and I think you hit all of the relevant calculations.

@dopplershift
Copy link
Member Author

It's ready, but travis seems to be having issues 😭

@jrleeman
Copy link
Contributor

Of course....

@dopplershift
Copy link
Member Author

Looks like we're good to go here.

@jrleeman jrleeman merged commit 3c3ba3a into Unidata:master Mar 30, 2017
@dopplershift dopplershift deleted the unit-helper branch March 30, 2017 23:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Calc Pertains to calculations Type: Enhancement Enhancement to existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants