-
Notifications
You must be signed in to change notification settings - Fork 5
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
Alias fix up #53
Alias fix up #53
Conversation
Surprisingly subtle. Pint's API features once again showing some of their, arguably, less desirable side. |
@crdanielbusch @JGuetschow might be of interest for you too as you have to deal with pint sometimes too |
self.define("yr = 1 * year") | ||
self.define("a = 1 * year = annum") |
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.
Very subtle change. It wasn't obvious to me straight away that 'everything on the right is an aliases for the first thing on the left'
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.
This is quite annoying if you need to use string comparisons later (e.g. because you're passing to Fortran).
I don't understand the use-case (don't you have to convert to something explicitly anyway if you need a specific unit string?), but the functionality works as advertised and doesn't seem to break anything.
Bit hard to explain. Let me try again. We pass stuff from Python to Fortran. In Fortran, there is no pint, so we just carry the units round as plain strings. To check that the units are as expected, we just do a basic string comparison. When pint magically converts "yr" to "a", our Fortran-side string comparisons break because they're expecting "yr" but getting "a". We could just change all our Fortran to expect "a", but this magical change feels wrong so I'm trying this instead. |
But couldn't you run |
In some cases, but in this case no (can explain on a call one day if you want to dig in further, I'm going to merge as is now though because the change is minor as you say). |
Turns out that we had accidentally assigned "yr" to be an alias for "a". This meant we had the following behaviour
This is quite annoying if you need to use string comparisons later (e.g. because you're passing to Fortran).
This PR fixes this so that if you pass in "yr", it stays as yr i.e. you get