Skip to content

Commit 378e102

Browse files
Merge pull request #25056 from fredrikekre/fe/stdlib-printf
at-[s]printf to Printf stdlib
2 parents f5dab58 + 8ab6f01 commit 378e102

File tree

28 files changed

+118
-55
lines changed

28 files changed

+118
-55
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,8 @@ Deprecated or removed
781781
* The functions `eigs` and `svds` have been moved to the `IterativeEigensolvers` standard
782782
library module ([#24714]).
783783

784+
* `@printf` and `@sprintf` have been moved to the `Printf` standard library ([#23929],[#25056]).
785+
784786
* `isnumber` has been deprecated in favor of `isnumeric`, `is_assigned_char`
785787
in favor of `isassigned` and `normalize_string` in favor of `normalize`, all three
786788
in the new `Unicode` standard library module ([#25021]).

base/deprecated.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,6 +1315,9 @@ export conv, conv2, deconv, filt, filt!, xcorr
13151315
@deprecate_moved eigs "IterativeEigensolvers" true true
13161316
@deprecate_moved svds "IterativeEigensolvers" true true
13171317

1318+
@eval @deprecate_moved $(Symbol("@printf")) "Printf" true true
1319+
@eval @deprecate_moved $(Symbol("@sprintf")) "Printf" true true
1320+
13181321
# PR #21709
13191322
@deprecate cov(x::AbstractVector, corrected::Bool) cov(x, corrected=corrected)
13201323
@deprecate cov(x::AbstractMatrix, vardim::Int, corrected::Bool) cov(x, vardim, corrected=corrected)

base/exports.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,8 +1173,6 @@ export
11731173

11741174
# output
11751175
@show,
1176-
@printf,
1177-
@sprintf,
11781176

11791177
# profiling
11801178
@time,

base/interactiveutil.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,20 +245,20 @@ function _show_cpuinfo(io::IO, info::Sys.CPUinfo, header::Bool=true, prefix::Abs
245245
println(io, info.model, ": ")
246246
print(io, " "^length(prefix))
247247
if tck > 0
248-
@printf(io, " %5s %9s %9s %9s %9s %9s\n",
248+
Printf.@printf(io, " %5s %9s %9s %9s %9s %9s\n",
249249
"speed", "user", "nice", "sys", "idle", "irq")
250250
else
251-
@printf(io, " %5s %9s %9s %9s %9s %9s ticks\n",
251+
Printf.@printf(io, " %5s %9s %9s %9s %9s %9s ticks\n",
252252
"speed", "user", "nice", "sys", "idle", "irq")
253253
end
254254
end
255255
print(io, prefix)
256256
if tck > 0
257-
@printf(io, "%5d MHz %9d s %9d s %9d s %9d s %9d s",
257+
Printf.@printf(io, "%5d MHz %9d s %9d s %9d s %9d s %9d s",
258258
info.speed, info.cpu_times!user / tck, info.cpu_times!nice / tck,
259259
info.cpu_times!sys / tck, info.cpu_times!idle / tck, info.cpu_times!irq / tck)
260260
else
261-
@printf(io, "%5d MHz %9d %9d %9d %9d %9d ticks",
261+
Printf.@printf(io, "%5d MHz %9d %9d %9d %9d %9d ticks",
262262
info.speed, info.cpu_times!user, info.cpu_times!nice,
263263
info.cpu_times!sys, info.cpu_times!idle, info.cpu_times!irq)
264264
end

base/libgit2/libgit2.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module LibGit2
77

88
import Base: ==
99
using Base: coalesce, notnothing
10+
using Base.Printf.@printf
1011

1112
export with, GitRepo, GitConfig
1213

base/pkg/entry.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import ..Reqs, ..Read, ..Query, ..Resolve, ..Cache, ..Write, ..Dir
77
using ...LibGit2
88
import ...Pkg.PkgError
99
using ..Types
10+
using Base.Printf.@printf
1011

1112
macro recover(ex)
1213
quote

base/printf.jl

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
module Printf
44
using Base: Grisu, GMP
55
using Base.Unicode: lowercase, textwidth, isupper
6-
export @printf, @sprintf
76

87
### printf formatter generation ###
98
const SmallFloatingPoint = Union{Float64,Float32,Float16}
@@ -1193,27 +1192,6 @@ function _printf(macroname, io, fmt, args)
11931192
Expr(:let, Expr(:block), blk)
11941193
end
11951194

1196-
"""
1197-
@printf([io::IOStream], "%Fmt", args...)
1198-
1199-
Print `args` using C `printf` style format specification string, with some caveats:
1200-
`Inf` and `NaN` are printed consistently as `Inf` and `NaN` for flags `%a`, `%A`,
1201-
`%e`, `%E`, `%f`, `%F`, `%g`, and `%G`. Furthermore, if a floating point number is
1202-
equally close to the numeric values of two possible output strings, the output
1203-
string further away from zero is chosen.
1204-
1205-
Optionally, an `IOStream`
1206-
may be passed as the first argument to redirect output.
1207-
1208-
# Examples
1209-
```jldoctest
1210-
julia> @printf("%f %F %f %F\\n", Inf, Inf, NaN, NaN)
1211-
Inf Inf NaN NaN\n
1212-
1213-
julia> @printf "%.0f %.1f %f\\n" 0.5 0.025 -0.0078125
1214-
1 0.0 -0.007813
1215-
```
1216-
"""
12171195
macro printf(args...)
12181196
isempty(args) && throw(ArgumentError("@printf: called with no arguments"))
12191197
if isa(args[1], AbstractString) || is_str_expr(args[1])
@@ -1225,19 +1203,6 @@ macro printf(args...)
12251203
end
12261204
end
12271205

1228-
"""
1229-
@sprintf("%Fmt", args...)
1230-
1231-
Return `@printf` formatted output as string.
1232-
1233-
# Examples
1234-
```jldoctest
1235-
julia> s = @sprintf "this is a %s %15.1f" "test" 34.567;
1236-
1237-
julia> println(s)
1238-
this is a test 34.6
1239-
```
1240-
"""
12411206
macro sprintf(args...)
12421207
isempty(args) && throw(ArgumentError("@sprintf: called with zero arguments"))
12431208
isa(args[1], AbstractString) || is_str_expr(args[1]) ||

base/stacktraces.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module StackTraces
88

99
import Base: hash, ==, show
1010
import Base.Serializer: serialize, deserialize
11+
using Base.Printf.@printf
1112

1213
export StackTrace, StackFrame, stacktrace, catch_stacktrace
1314

base/sysimg.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ import .Random: rand, rand!
368368

369369
# (s)printf macros
370370
include("printf.jl")
371-
using .Printf
371+
# import .Printf
372372

373373
# metaprogramming
374374
include("meta.jl")
@@ -495,6 +495,7 @@ Base.require(:SuiteSparse)
495495
Base.require(:Test)
496496
Base.require(:Unicode)
497497
Base.require(:Distributed)
498+
Base.require(:Printf)
498499

499500
@eval Base begin
500501
@deprecate_binding Test root_module(:Test) true ", run `using Test` instead"

base/util.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,28 +99,28 @@ end
9999
function format_bytes(bytes)
100100
bytes, mb = prettyprint_getunits(bytes, length(_mem_units), Int64(1024))
101101
if mb == 1
102-
@sprintf("%d %s%s", bytes, _mem_units[mb], bytes==1 ? "" : "s")
102+
Printf.@sprintf("%d %s%s", bytes, _mem_units[mb], bytes==1 ? "" : "s")
103103
else
104-
@sprintf("%.3f %s", bytes, _mem_units[mb])
104+
Printf.@sprintf("%.3f %s", bytes, _mem_units[mb])
105105
end
106106
end
107107

108108
function time_print(elapsedtime, bytes, gctime, allocs)
109-
@printf("%10.6f seconds", elapsedtime/1e9)
109+
Printf.@printf("%10.6f seconds", elapsedtime/1e9)
110110
if bytes != 0 || allocs != 0
111111
allocs, ma = prettyprint_getunits(allocs, length(_cnt_units), Int64(1000))
112112
if ma == 1
113-
@printf(" (%d%s allocation%s: ", allocs, _cnt_units[ma], allocs==1 ? "" : "s")
113+
Printf.@printf(" (%d%s allocation%s: ", allocs, _cnt_units[ma], allocs==1 ? "" : "s")
114114
else
115-
@printf(" (%.2f%s allocations: ", allocs, _cnt_units[ma])
115+
Printf.@printf(" (%.2f%s allocations: ", allocs, _cnt_units[ma])
116116
end
117117
print(format_bytes(bytes))
118118
if gctime > 0
119-
@printf(", %.2f%% gc time", 100*gctime/elapsedtime)
119+
Printf.@printf(", %.2f%% gc time", 100*gctime/elapsedtime)
120120
end
121121
print(")")
122122
elseif gctime > 0
123-
@printf(", %.2f%% gc time", 100*gctime/elapsedtime)
123+
Printf.@printf(", %.2f%% gc time", 100*gctime/elapsedtime)
124124
end
125125
println()
126126
end

0 commit comments

Comments
 (0)