Skip to content

Commit e071b61

Browse files
committed
Remove method unit(::Any), and move unit(::Type{Any}) for docstring purposes
Also changed the exception type thrown by unit(::Type{Any}) to ArgumentError, and changed the error description to be more helpful.
1 parent b43536b commit e071b61

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/utils.jl

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -139,25 +139,25 @@ julia> unit(1.0) == NoUnits
139139
true
140140
```
141141
"""
142-
143-
"""
144-
This is shown if a user has not defined units for their quantity type.
145-
"""
146-
const MISSING_UNIT_DEFINITION_MESSAGE =
147-
"""
148-
You tried calling unit on an object that has none defined.
149-
Not everything has (or should have) units.
150-
If your type should have units, define a method of unit on them.
151-
"""
152-
153-
@inline unit(x::Any) = throw( DomainError( x, MISSING_UNIT_DEFINITION_MESSAGE ) )
154-
@inline unit(x::Type{Any}) = throw( DomainError( x, MISSING_UNIT_DEFINITION_MESSAGE ) )
155142
@inline unit(x::Number) = NoUnits
156143
@inline unit(x::Type{T}) where {T <: Number} = NoUnits
157144
@inline unit(x::Type{Union{Missing, T}}) where T = unit(T)
158145
@inline unit(x::Type{Missing}) = missing
159146
@inline unit(x::Missing) = missing
160147

148+
"""
149+
unit(::Type{Any})
150+
151+
This method is here to prevent infinite recursion and to provide a helpful error message in case it occurs.
152+
"""
153+
@inline unit(x::Type{Any}) = throw( ArgumentError(
154+
"""
155+
The method unit(Any) was called, but this method has no meaningful result.
156+
The call may be due to calling unit(eltype(…)) on a container,
157+
since eltype has a generic fallback method that returns Any.
158+
"""
159+
) )
160+
161161
"""
162162
absoluteunit(::Units)
163163
absoluteunit(::Quantity)

0 commit comments

Comments
 (0)