JuliaPhysics / JuliaPhysics/Unitful.jl

Namespacing confusion: `uparse("myMeter")` example from docs gives ArgumentError

Open
#435 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
Julia
Stars
675
Forks
124
Avg merge
3h 38m
Merged PRs (30d)
1

Description

```julia
using Unitful
module MyUnits; using Unitful; @unit myMeter "m" MyMeter 1u"m" false; end
Unitful.register(MyUnits);
u"myMeter" # works

julia> uparse("myMeter")
ERROR: ArgumentError: Symbol `myMeter` was found in the globally registered unit module Main.MyUnits
but was not in the provided list of unit modules Unitful.

(Consider `using Main.MyUnits` in your module if you are using `@u_str`?)
Stacktrace:
[1] lookup_units(unitmods::Vector{Module}, sym::Symbol)
@ Unitful ~\.julia\packages\Unitful\PcVKX\src\user.jl:575
[2] lookup_units
@ ~\.julia\packages\Unitful\PcVKX\src\user.jl:593 [inlined]
[3] uparse(str::String; unit_context::Module)
@ Unitful ~\.julia\packages\Unitful\PcVKX\src\user.jl:536
[4] uparse(str::String)
@ Unitful ~\.julia\packages\Unitful\PcVKX\src\user.jl:535
[5] top-level scope
@ REPL[31]:1
using Main.MyUnits
uparse("myMeter") # still fails
```

```julia
using Unitful
Unitful.register(@__MODULE__);
@unit U "U" U 1u"μmol/60s" true
1u"U"
uparse("U") # fails
ERROR: ArgumentError: Symbol `U` was found in the globally registered unit module Mainbut was not in the provided list of unit modules Unitful.

(Consider `using Main` in your module if you are using `@u_str`?)
using Main
uparse("U") # still fails
```
There may be a problem with `uparse` or I am not understanding namespacing. It is confusing to me why neither examples can be copy pasted to REPL

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.