-
Notifications
You must be signed in to change notification settings - Fork 112
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
don't warn for identical units when resolving symbols from u"..." #98
don't warn for identical units when resolving symbols from u"..." #98
Conversation
*Before:* ``` julia> using Unitful julia> module UnitfulTest import Unitful using Unitful: @Unit, s @Unit twoseconds "twoseconds" TwoSeconds 2s false Unitful.register(UnitfulTest) end UnitfulTest julia> uconvert(u"s", 1*u"twoseconds") WARNING: Symbol s was found in multiple registered unit modules. We will use the one from UnitfulTest. 2//1 s ``` *After:* ``` julia> using Unitful julia> module UnitfulTest import Unitful using Unitful: @Unit, s @Unit twoseconds "twoseconds" TwoSeconds 2s false Unitful.register(UnitfulTest) end UnitfulTest julia> uconvert(u"s", 1*u"twoseconds") 2//1 s julia> module UnitfulTest2 import Unitful using Unitful: @Unit @Unit s "weird" Weird 1Unitful.m false Unitful.register(UnitfulTest2) end UnitfulTest2 julia> uconvert(u"s", 1*u"twoseconds") WARNING: Symbol s was found in multiple registered unit modules. We will use the one from UnitfulTest. 2//1 s ```
I updated your PR to address the issue you pointed out. Do you want to take a look and see if you agree with the changes? (btw, your example didn't quite work as advertised, the last warning should say P.S. It occurred to me that currently |
I think in my implementation, if there were multiple units, the one that is selected was essentially random and I wouldn't have been surprised to see it change after restarting Julia. I had a comment to that effect. I realize I broke some of the tests you had written by returning Anyway I'm happy with the changes you've made as well. Looks good to me! |
Codecov Report
@@ Coverage Diff @@
## master #98 +/- ##
=======================================
Coverage 88.29% 88.29%
=======================================
Files 10 10
Lines 641 641
=======================================
Hits 566 566
Misses 75 75
Continue to review full report at Codecov.
|
I'll just make a separate commit that changes the macro behavior to return |
This is just a quick patch I whipped up to try and address #94. Basically, if two units have the same hash, we will no longer warn about finding two copies of the same unit. We also check that these symbols are actually units before warning (I think just having a symbol named "s" was enough to get the warning).
Unfortunately there is a drawback to the approach I've used here. Because Dicts are unordered, I think there's no longer any guarantee about which unit is selected in the event that there are in fact multiple units with the same name.
Before:
After: