Skip to content

Commit 0911c3a

Browse files
LilithHafnervchuravy
authored andcommitted
Make ScopedValues.get a method of Base.get
1 parent 22134ca commit 0911c3a

File tree

4 files changed

+12
-13
lines changed

4 files changed

+12
-13
lines changed

base/logging/logging.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ LogState(logger) = LogState(LogLevel(_invoked_min_enabled_level(logger)), logger
515515
const CURRENT_LOGSTATE = ScopedValue{LogState}()
516516

517517
function current_logstate()
518-
maybe = @inline Base.ScopedValues.get(CURRENT_LOGSTATE)
518+
maybe = @inline get(CURRENT_LOGSTATE)
519519
return something(maybe, _global_logstate)::LogState
520520
end
521521

base/mpfr.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ Base.copyto!(fd::BigFloatData, limbs) = copyto!(getfield(fd, :d), offset_p_limbs
238238

239239
include("rawbigfloats.jl")
240240

241-
rounding_raw(::Type{BigFloat}) = something(Base.ScopedValues.get(CURRENT_ROUNDING_MODE), ROUNDING_MODE[])
241+
rounding_raw(::Type{BigFloat}) = something(get(CURRENT_ROUNDING_MODE), ROUNDING_MODE[])
242242
setrounding_raw(::Type{BigFloat}, r::MPFRRoundingMode) = ROUNDING_MODE[]=r
243243
function setrounding_raw(f::Function, ::Type{BigFloat}, r::MPFRRoundingMode)
244244
Base.ScopedValues.@with(CURRENT_ROUNDING_MODE => r, f())
@@ -1039,7 +1039,7 @@ _convert_precision_from_base(precision::Integer, base::Integer) =
10391039
base == 2 ? precision : ceil(Int, precision * log2(base))
10401040

10411041
_precision_with_base_2(::Type{BigFloat}) =
1042-
Int(something(Base.ScopedValues.get(CURRENT_PRECISION), DEFAULT_PRECISION[])) # default precision of the type BigFloat itself
1042+
Int(something(get(CURRENT_PRECISION), DEFAULT_PRECISION[])) # default precision of the type BigFloat itself
10431043

10441044
"""
10451045
setprecision([T=BigFloat,] precision::Int; base=2)

base/scopedvalues.jl

+8-9
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
module ScopedValues
44

55
export ScopedValue, with, @with
6-
public get
76

87
"""
98
ScopedValue(x)
@@ -57,7 +56,7 @@ Base.eltype(::ScopedValue{T}) where {T} = T
5756
5857
Test whether a `ScopedValue` has an assigned value.
5958
60-
See also: [`ScopedValues.with`](@ref), [`ScopedValues.@with`](@ref), [`ScopedValues.get`](@ref).
59+
See also: [`ScopedValues.with`](@ref), [`ScopedValues.@with`](@ref), [`get`](@ref).
6160
6261
# Examples
6362
```jldoctest
@@ -141,24 +140,24 @@ julia> using Base.ScopedValues
141140
142141
julia> a = ScopedValue(42); b = ScopedValue{Int}();
143142
144-
julia> ScopedValues.get(a)
143+
julia> get(a)
145144
Some(42)
146145
147-
julia> isnothing(ScopedValues.get(b))
146+
julia> isnothing(get(b))
148147
true
149148
```
150149
"""
151-
function get(val::ScopedValue{T}) where {T}
150+
function Base.get(val::ScopedValue{T}) where {T}
152151
scope = Core.current_scope()::Union{Scope, Nothing}
153152
if scope === nothing
154153
val.has_default && return Some{T}(val.default)
155154
return nothing
156155
end
157156
scope = scope::Scope
158157
if val.has_default
159-
return Some{T}(Base.get(scope.values, val, val.default)::T)
158+
return Some{T}(get(scope.values, val, val.default)::T)
160159
else
161-
v = Base.get(scope.values, val, novalue)
160+
v = get(scope.values, val, novalue)
162161
v === novalue || return Some{T}(v::T)
163162
end
164163
return nothing
@@ -191,7 +190,7 @@ new dynamic scope with `var` set to `val`. `val` will be converted to type `T`.
191190
`@with var=>val expr` is equivalent to `with(var=>val) do expr end`, but `@with`
192191
avoids creating a closure.
193192
194-
See also: [`ScopedValues.with`](@ref), [`ScopedValues.ScopedValue`](@ref), [`ScopedValues.get`](@ref).
193+
See also: [`ScopedValues.with`](@ref), [`ScopedValues.ScopedValue`](@ref), [`get`](@ref).
195194
196195
# Examples
197196
```jldoctest
@@ -231,7 +230,7 @@ end
231230
Execute `f` in a new dynamic scope with `var` set to `val`. `val` will be converted
232231
to type `T`.
233232
234-
See also: [`ScopedValues.@with`](@ref), [`ScopedValues.ScopedValue`](@ref), [`ScopedValues.get`](@ref).
233+
See also: [`ScopedValues.@with`](@ref), [`ScopedValues.ScopedValue`](@ref), [`get`](@ref).
235234
236235
# Examples
237236
```jldoctest

doc/src/base/scopedvalues.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ Base.ScopedValues.ScopedValue
297297
Base.ScopedValues.with
298298
Base.ScopedValues.@with
299299
Base.isassigned(::Base.ScopedValues.ScopedValue)
300-
Base.ScopedValues.get
300+
Base.get(::Base.ScopedValues.ScopedValue)
301301
```
302302

303303
## Implementation notes and performance

0 commit comments

Comments
 (0)