-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
/
Copy pathdeprecated.jl
1653 lines (1398 loc) · 71.7 KB
/
deprecated.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# This file is a part of Julia. License is MIT: https://julialang.org/license
# Deprecated functions and objects
#
# Please add new deprecations at the bottom of the file.
# A function deprecated in a release will be removed in the next one.
# Please also add a reference to the pull request which introduced the
# deprecation.
#
# For simple cases where a direct replacement is available, use @deprecate:
# the first argument is the signature of the deprecated method, the second one
# is the call which replaces it. Remove the definition of the deprecated method
# and unexport it, as @deprecate takes care of calling the replacement
# and of exporting the function.
#
# For more complex cases, move the body of the deprecated method in this file,
# and call depwarn() directly from inside it. The symbol depwarn() expects is
# the name of the function, which is used to ensure that the deprecation warning
# is only printed the first time for each call place.
macro deprecate(old, new, ex=true)
meta = Expr(:meta, :noinline)
@gensym oldmtname
if isa(old, Symbol)
oldname = Expr(:quote, old)
newname = Expr(:quote, new)
Expr(:toplevel,
ex ? Expr(:export, esc(old)) : nothing,
:(function $(esc(old))(args...)
$meta
depwarn($"`$old` is deprecated, use `$new` instead.", $oldmtname)
$(esc(new))(args...)
end),
:(const $oldmtname = Core.Typeof($(esc(old))).name.mt.name))
elseif isa(old, Expr) && (old.head == :call || old.head == :where)
remove_linenums!(new)
oldcall = sprint(show_unquoted, old)
newcall = sprint(show_unquoted, new)
# if old.head is a :where, step down one level to the :call to avoid code duplication below
callexpr = old.head == :call ? old : old.args[1]
if callexpr.head == :call
if isa(callexpr.args[1], Symbol)
oldsym = callexpr.args[1]::Symbol
elseif isa(callexpr.args[1], Expr) && callexpr.args[1].head == :curly
oldsym = callexpr.args[1].args[1]::Symbol
else
error("invalid usage of @deprecate")
end
else
error("invalid usage of @deprecate")
end
Expr(:toplevel,
ex ? Expr(:export, esc(oldsym)) : nothing,
:($(esc(old)) = begin
$meta
depwarn($"`$oldcall` is deprecated, use `$newcall` instead.", $oldmtname)
$(esc(new))
end),
:(const $oldmtname = Core.Typeof($(esc(oldsym))).name.mt.name))
else
error("invalid usage of @deprecate")
end
end
function depwarn(msg, funcsym)
opts = JLOptions()
if opts.depwarn == 2
throw(ErrorException(msg))
end
deplevel = opts.depwarn == 1 ? CoreLogging.Warn : CoreLogging.BelowMinLevel
@logmsg(
deplevel,
msg,
_module=begin
bt = backtrace()
frame, caller = firstcaller(bt, funcsym)
# TODO: Is it reasonable to attribute callers without linfo to Core?
caller.linfo isa Core.MethodInstance ? caller.linfo.def.module : Core
end,
_file=String(caller.file),
_line=caller.line,
_id=(frame,funcsym),
_group=:depwarn,
caller=caller,
maxlog=funcsym === nothing ? nothing : 1
)
nothing
end
firstcaller(bt::Vector, ::Nothing) = Ptr{Cvoid}(0), StackTraces.UNKNOWN
firstcaller(bt::Vector, funcsym::Symbol) = firstcaller(bt, (funcsym,))
function firstcaller(bt::Vector, funcsyms)
# Identify the calling line
found = false
lkup = StackTraces.UNKNOWN
found_frame = Ptr{Cvoid}(0)
for frame in bt
lkups = StackTraces.lookup(frame)
for outer lkup in lkups
if lkup == StackTraces.UNKNOWN || lkup.from_c
continue
end
if found
found_frame = frame
@goto found
end
found = lkup.func in funcsyms
# look for constructor type name
if !found && lkup.linfo isa Core.MethodInstance
li = lkup.linfo
ft = ccall(:jl_first_argument_datatype, Any, (Any,), li.def.sig)
if isa(ft,DataType) && ft.name === Type.body.name
ft = unwrap_unionall(ft.parameters[1])
found = (isa(ft,DataType) && ft.name.name in funcsyms)
end
end
end
end
return found_frame, StackTraces.UNKNOWN
@label found
return found_frame, lkup
end
deprecate(m::Module, s::Symbol, flag=1) = ccall(:jl_deprecate_binding, Cvoid, (Any, Any, Cint), m, s, flag)
macro deprecate_binding(old, new, export_old=true, dep_message=:nothing, constant=true)
dep_message === :nothing && (dep_message = ", use $new instead.")
return Expr(:toplevel,
export_old ? Expr(:export, esc(old)) : nothing,
Expr(:const, Expr(:(=), esc(Symbol(string("_dep_message_",old))), esc(dep_message))),
constant ? Expr(:const, Expr(:(=), esc(old), esc(new))) : Expr(:(=), esc(old), esc(new)),
Expr(:call, :deprecate, __module__, Expr(:quote, old)))
end
macro deprecate_stdlib(old, mod, export_old=true, newname=old)
rename = old === newname ? "" : " as `$newname`"
dep_message = """: it has been moved to the standard library package `$mod`$rename.
Add `using $mod` to your imports."""
new = GlobalRef(Base.root_module(Base, mod), newname)
return Expr(:toplevel,
export_old ? Expr(:export, esc(old)) : nothing,
Expr(:const, Expr(:(=), esc(Symbol(string("_dep_message_",old))), esc(dep_message))),
Expr(:const, Expr(:(=), esc(old), esc(new))),
Expr(:call, :deprecate, __module__, Expr(:quote, old)))
end
macro deprecate_moved(old, new, export_old=true)
eold = esc(old)
emsg = string(old, " has been moved to the package ", new, ".jl.\n",
"Run `Pkg.add(\"", new, "\")` to install it, restart Julia,\n",
"and then run `using ", new, "` to load it.")
return Expr(:toplevel,
:($eold(args...; kwargs...) = error($emsg)),
export_old ? Expr(:export, eold) : nothing,
Expr(:call, :deprecate, __module__, Expr(:quote, old), 2))
end
# BEGIN 0.6 deprecations
# removing the .op deprecations breaks a few things. TODO: fix
# deprecations for uses of old dot operators (.* etc) as objects, rather than
# just calling them infix.
for op in (:(!=), :≠, :+, :-, :*, :/, :÷, :%, :<, :(<=), :≤, :(==), :>, :>=, :≥, :\, :^, ://, :>>, :<<)
dotop = Symbol('.', op)
# define as const dotop = (a,b) -> ...
# to work around syntax deprecation for dotop(a,b) = ...
@eval const $dotop = (a,b) -> begin
depwarn(string($(string(dotop)), " is no longer a function object, use `broadcast(",$op,", ...)` instead."),
$(QuoteNode(dotop)))
broadcast($op, a, b)
end
@eval export $dotop
end
# Deprecate promote_eltype_op (#19814, #19937)
_promote_eltype_op(::Any) = Any
_promote_eltype_op(op, A) = (@_inline_meta; promote_op(op, eltype(A)))
_promote_eltype_op(op, A, B) = (@_inline_meta; promote_op(op, eltype(A), eltype(B)))
_promote_eltype_op(op, A, B, C, D...) = (@_inline_meta; _promote_eltype_op(op, eltype(A), _promote_eltype_op(op, B, C, D...)))
@inline function promote_eltype_op(args...)
depwarn("""
`promote_eltype_op` is deprecated and should not be used.
See https://github.com/JuliaLang/julia/issues/19669.""",
:promote_eltype_op)
_promote_eltype_op(args...)
end
# END 0.6 deprecations
# BEGIN 0.7 deprecations
# TODO: remove warning for using `_` in parse_input_line in base/client.jl
@deprecate issubtype (<:)
@deprecate union() Set()
# 12807
start(::Union{Process, ProcessChain}) = 1
done(::Union{Process, ProcessChain}, i::Int) = (i == 3)
next(p::Union{Process, ProcessChain}, i::Int) = (getindex(p, i), i + 1)
@noinline function getindex(p::Union{Process, ProcessChain}, i::Int)
depwarn("`open(cmd)` now returns only a Process<:IO object.", :getindex)
return i == 1 ? getfield(p, p.openstream) : p
end
# also remove all support machinery in src for current_module when removing this deprecation
# and make Base.include an error
_current_module() = ccall(:jl_get_current_module, Ref{Module}, ())
@noinline function binding_module(s::Symbol)
depwarn("`binding_module(symbol)` is deprecated, use `binding_module(module, symbol)` instead.", :binding_module)
return binding_module(_current_module(), s)
end
export expand
@noinline function expand(@nospecialize(x))
depwarn("`expand(x)` is deprecated, use `Meta.lower(module, x)` instead.", :expand)
return Meta.lower(_current_module(), x)
end
@noinline function macroexpand(@nospecialize(x))
depwarn("`macroexpand(x)` is deprecated, use `macroexpand(module, x)` instead.", :macroexpand)
return macroexpand(_current_module(), x)
end
@noinline function isconst(s::Symbol)
depwarn("`isconst(symbol)` is deprecated, use `isconst(module, symbol)` instead.", :isconst)
return isconst(_current_module(), s)
end
@noinline function include_string(txt::AbstractString, fname::AbstractString)
depwarn("`include_string(string, fname)` is deprecated, use `include_string(module, string, fname)` instead.", :include_string)
return include_string(_current_module(), txt, fname)
end
@noinline function include_string(txt::AbstractString)
depwarn("`include_string(string)` is deprecated, use `include_string(module, string)` instead.", :include_string)
return include_string(_current_module(), txt, "string")
end
"""
current_module() -> Module
Get the *dynamically* current `Module`, which is the `Module` code is currently being read
from. In general, this is not the same as the module containing the call to this function.
DEPRECATED: use @__MODULE__ instead
"""
@noinline function current_module()
depwarn("`current_module()` is deprecated, use `@__MODULE__` instead.", :current_module)
return _current_module()
end
export current_module
@deprecate_binding colon (:)
module Operators
for op in [:!, :(!=), :(!==), :%, :&, :*, :+, :-, :/, ://, :<, :<:, :<<, :(<=),
:<|, :(==), :(===), :>, :>:, :(>=), :>>, :>>>, :\, :^,
:adjoint, :getindex, :hcat, :hvcat, :setindex!, :transpose, :vcat,
:xor, :|, :|>, :~, :×, :÷, :∈, :∉, :∋, :∌, :∘, :√, :∛, :∩, :∪, :≠, :≤,
:≥, :⊆, :⊈, :⊊, :⊻, :⋅]
if isdefined(Base, op)
@eval Base.@deprecate_binding $op Base.$op
end
end
Base.@deprecate_binding colon (:)
end
export Operators
# PR #21956
# This mimics the structure as it was defined in Base to avoid directly breaking code
# that assumes this structure
module DFT
for f in [:bfft, :bfft!, :brfft, :dct, :dct!, :fft, :fft!, :fftshift, :idct, :idct!,
:ifft, :ifft!, :ifftshift, :irfft, :plan_bfft, :plan_bfft!, :plan_brfft,
:plan_dct, :plan_dct!, :plan_fft, :plan_fft!, :plan_idct, :plan_idct!,
:plan_ifft, :plan_ifft!, :plan_irfft, :plan_rfft, :rfft]
pkg = endswith(String(f), "shift") ? "AbstractFFTs" : "FFTW"
@eval Base.@deprecate_moved $f $pkg
end
module FFTW
for f in [:r2r, :r2r!, :plan_r2r, :plan_r2r!]
@eval Base.@deprecate_moved $f "FFTW"
end
end
Base.deprecate(DFT, :FFTW, 2)
export FFTW
end
using .DFT
for f in filter(s -> isexported(DFT, s), names(DFT, all = true))
@eval export $f
end
module DSP
for f in [:conv, :conv2, :deconv, :filt, :filt!, :xcorr]
@eval Base.@deprecate_moved $f "DSP"
end
end
deprecate(Base, :DSP, 2)
using .DSP
export conv, conv2, deconv, filt, filt!, xcorr
# PR #21709
@deprecate cov(x::AbstractVector, corrected::Bool) cov(x, corrected=corrected)
@deprecate cov(x::AbstractMatrix, vardim::Int, corrected::Bool) cov(x, dims=vardim, corrected=corrected)
@deprecate cov(X::AbstractVector, Y::AbstractVector, corrected::Bool) cov(X, Y, corrected=corrected)
@deprecate cov(X::AbstractVecOrMat, Y::AbstractVecOrMat, vardim::Int, corrected::Bool) cov(X, Y, dims=vardim, corrected=corrected)
# PR #22325
# TODO: when this replace is removed from deprecated.jl:
# 1) rename the function replace_new from strings/util.jl to replace
# 2) update the replace(s::AbstractString, pat, f) method, below replace_new
# (see instructions there)
function replace(s::AbstractString, pat, f, n::Integer)
if n <= 0
depwarn(string("`replace(s, pat, r, count)` with `count <= 0` is deprecated, use ",
"`replace(s, pat=>r, count=typemax(Int))` or `replace(s, pat=>r)` instead."),
:replace)
replace(s, pat=>f)
else
depwarn(string("`replace(s, pat, r, count)` is deprecated, use ",
"`replace(s, pat=>r, count=count)`"),
:replace)
replace(String(s), pat=>f, count=n)
end
end
@deprecate replace(s::AbstractString, pat, f) replace(s, pat=>f)
# PR #22475
@deprecate ntuple(f, ::Type{Val{N}}) where {N} ntuple(f, Val(N))
@deprecate fill_to_length(t, val, ::Type{Val{N}}) where {N} fill_to_length(t, val, Val(N)) false
@deprecate literal_pow(a, b, ::Type{Val{N}}) where {N} literal_pow(a, b, Val(N)) false
@eval IteratorsMD @deprecate split(t, V::Type{Val{n}}) where {n} split(t, Val(n)) false
@deprecate cat(::Type{Val{N}}, A::AbstractArray...) where {N} cat(Val(N), A...)
@deprecate cat_t(::Type{Val{N}}, ::Type{T}, A, B) where {N,T} cat_t(Val(N), T, A, B) false
@deprecate reshape(A::AbstractArray, ::Type{Val{N}}) where {N} reshape(A, Val(N))
@deprecate read(s::IO, x::Ref) read!(s, x)
@deprecate read(s::IO, t::Type, d1::Int, dims::Int...) read!(s, Array{t}(undef, d1, dims...))
@deprecate read(s::IO, t::Type, d1::Integer, dims::Integer...) read!(s, Array{t}(undef, d1, dims...))
@deprecate read(s::IO, t::Type, dims::Dims) read!(s, Array{t}(undef, dims))
function CartesianIndices(start::CartesianIndex{N}, stop::CartesianIndex{N}) where N
inds = map((f,l)->f:l, start.I, stop.I)
depwarn("the internal representation of CartesianIndices has changed, use `CartesianIndices($inds)` (or other more appropriate AbstractUnitRange type) instead.", :CartesianIndices)
CartesianIndices(inds)
end
# PR #20005
function InexactError()
depwarn("InexactError now supports arguments, use `InexactError(funcname::Symbol, ::Type, value)` instead.", :InexactError)
InexactError(:none, Any, nothing)
end
# PR #22751
function DomainError()
depwarn("DomainError now supports arguments, use `DomainError(value)` or `DomainError(value, msg)` instead.", :DomainError)
DomainError(nothing)
end
# PR #22761
function OverflowError()
depwarn("OverflowError now supports a message string, use `OverflowError(msg)` instead.", :OverflowError)
OverflowError("")
end
@deprecate fieldnames(v) fieldnames(typeof(v))
# nfields(::Type) deprecation in builtins.c: update nfields tfunc in compiler/tfuncs.jl when it is removed.
# also replace `_nfields` with `nfields` in summarysize.c when this is removed.
# ::ANY is deprecated in src/method.c
# also remove all instances of `jl_ANY_flag` in src/
# issue #13079
# in julia-parser.scm:
# move prec-bitshift after prec-rational
# remove parse-with-chains-warn and bitshift-warn
# update precedence table in doc/src/manual/mathematical-operations.md
# PR #22182
@deprecate is_apple Sys.isapple
@deprecate is_bsd Sys.isbsd
@deprecate is_linux Sys.islinux
@deprecate is_unix Sys.isunix
@deprecate is_windows Sys.iswindows
@deprecate read(cmd::AbstractCmd, stdin::Redirectable) read(pipeline(stdin, cmd))
@deprecate readstring(cmd::AbstractCmd, stdin::Redirectable) readstring(pipeline(stdin, cmd))
@deprecate eachline(cmd::AbstractCmd, stdin; kw...) eachline(pipeline(stdin, cmd), kw...)
@deprecate showall(x) show(x)
@deprecate showall(io, x) show(IOContext(io, :limit => false), x)
@deprecate_binding AbstractIOBuffer GenericIOBuffer false
@deprecate String(io::GenericIOBuffer) String(take!(copy(io)))
@deprecate readstring(s::IO) read(s, String)
@deprecate readstring(filename::AbstractString) read(filename, String)
@deprecate readstring(cmd::AbstractCmd) read(cmd, String)
# issue #11310
# remove "parametric method syntax" deprecation in julia-syntax.scm
@deprecate momenttype(::Type{T}) where {T} typeof((zero(T)*zero(T) + zero(T)*zero(T))/2) false
# issue #6466
# `write` on non-isbits arrays is deprecated in io.jl.
# PR #23187
@deprecate cpad(s, n::Integer, p=" ") rpad(lpad(s, div(n+textwidth(s), 2), p), n, p) false
# PR #22088
function hex2num(s::AbstractString)
depwarn("`hex2num(s)` is deprecated. Use `reinterpret(Float64, parse(UInt64, s, base = 16))` instead.", :hex2num)
if length(s) <= 4
return reinterpret(Float16, parse(UInt16, s, base = 16))
end
if length(s) <= 8
return reinterpret(Float32, parse(UInt32, s, base = 16))
end
return reinterpret(Float64, parse(UInt64, s, base = 16))
end
export hex2num
@deprecate num2hex(x::Union{Float16,Float32,Float64}) string(reinterpret(Unsigned, x), base = 16, pad = sizeof(x)*2)
@deprecate num2hex(n::Integer) string(n, base = 16, pad = sizeof(n)*2)
# PR #22742: change in isapprox semantics
@deprecate rtoldefault(x,y) rtoldefault(x,y,0) false
# PR #23235
@deprecate ctranspose adjoint
@deprecate ctranspose! adjoint!
function convert(::Union{Type{Vector{UInt8}}, Type{Array{UInt8}}}, s::AbstractString)
depwarn("Strings can no longer be `convert`ed to byte arrays. Use `unsafe_wrap` or `codeunits` instead.", :Type)
unsafe_wrap(Vector{UInt8}, String(s))
end
function (::Type{Vector{UInt8}})(s::String)
depwarn("Vector{UInt8}(s::String) will copy data in the future. To avoid copying, use `unsafe_wrap` or `codeunits` instead.", :Type)
unsafe_wrap(Vector{UInt8}, s)
end
function (::Type{Array{UInt8}})(s::String)
depwarn("Array{UInt8}(s::String) will copy data in the future. To avoid copying, use `unsafe_wrap` or `codeunits` instead.", :Type)
unsafe_wrap(Vector{UInt8}, s)
end
@deprecate convert(::Type{Vector{Char}}, s::AbstractString) Vector{Char}(s)
@deprecate convert(::Type{Symbol}, s::AbstractString) Symbol(s)
@deprecate convert(::Type{String}, s::Symbol) String(s)
@deprecate convert(::Type{String}, v::Vector{UInt8}) String(v)
@deprecate convert(::Type{S}, g::Unicode.GraphemeIterator) where {S<:AbstractString} convert(S, g.s)
@deprecate convert(::Type{String}, v::AbstractVector{Char}) String(v)
@deprecate convert(::Type{Libc.FILE}, s::IO) Libc.FILE(s)
@deprecate convert(::Type{VersionNumber}, v::Integer) VersionNumber(v)
@deprecate convert(::Type{VersionNumber}, v::Tuple) VersionNumber(v)
@deprecate convert(::Type{VersionNumber}, v::AbstractString) VersionNumber(v)
@deprecate (convert(::Type{Integer}, x::Enum{T}) where {T<:Integer}) Integer(x)
@deprecate (convert(::Type{T}, x::Enum{T2}) where {T<:Integer,T2<:Integer}) T(x)
function (::Type{T})(arg) where {T}
if applicable(convert, T, arg)
sig = which(convert, (Type{T}, typeof(arg))).sig
if sig == (Tuple{typeof(convert),Type{S},Number} where S<:Number) ||
sig == (Tuple{typeof(convert),Type{S},AbstractArray} where S<:AbstractArray)
# matches a catch-all converter; will stack overflow
throw(MethodError(T, (arg,)))
end
# if `convert` call would not work, just let the method error happen
depwarn("Constructors no longer fall back to `convert`. A constructor `$T(::$(typeof(arg)))` should be defined instead.", :Type)
end
convert(T, arg)::T
end
# related items to remove in: abstractarray.jl, dates/periods.jl, compiler.jl
# also remove all uses of is_default_method
@deprecate convert(::Type{UInt128}, u::UUID) UInt128(u)
@deprecate convert(::Type{UUID}, s::AbstractString) UUID(s)
# Issue #19923
@deprecate ror circshift
@deprecate ror! circshift!
@deprecate rol(B, i) circshift(B, -i)
@deprecate rol!(dest, src, i) circshift!(dest, src, -i)
@deprecate rol!(B, i) circshift!(B, -i)
# issue #5148, PR #23259
# warning for `const` on locals should be changed to an error in julia-syntax.scm
# issue #22789
# remove code for `importall` in src/
# issue #17886
# deprecations for filter[!] with 2-arg functions are in abstractdict.jl
# PR #23066
@deprecate cfunction(f, r, a::Tuple) cfunction(f, r, Tuple{a...})
@noinline function cfunction(f, r, a)
@nospecialize(f, r, a)
depwarn("The function `cfunction` is now written as a macro `@cfunction`.", :cfunction)
return ccall(:jl_function_ptr, Ptr{Cvoid}, (Any, Any, Any), f, r, a)
end
export cfunction
# PR 23341
@eval GMP @deprecate gmp_version() version() false
@eval GMP @Base.deprecate_binding GMP_VERSION VERSION false
@eval GMP @deprecate gmp_bits_per_limb() bits_per_limb() false
@eval GMP @Base.deprecate_binding GMP_BITS_PER_LIMB BITS_PER_LIMB false
@eval MPFR @deprecate get_version() version() false
# PR #23427
@deprecate_binding e ℯ true ", use ℯ (\\euler) or `Base.MathConstants.e`"
@deprecate_binding eu ℯ true ", use ℯ (\\euler) or `Base.MathConstants.e`"
@deprecate_binding γ MathConstants.γ
@deprecate_binding eulergamma MathConstants.eulergamma
@deprecate_binding catalan MathConstants.catalan
@deprecate_binding φ MathConstants.φ
@deprecate_binding golden MathConstants.golden
# PR #23271
# TODO: rename Base._IOContext to IOContext when this deprecation is deleted
function IOContext(io::IO; kws...)
if isempty(kws) # Issue #25638
_IOContext(io)
else
depwarn("`IOContext(io, k=v, ...)` is deprecated, use `IOContext(io, :k => v, ...)` instead.", :IOContext)
IOContext(io, (k=>v for (k, v) in pairs(kws))...)
end
end
@deprecate IOContext(io::IO, key, value) IOContext(io, key=>value)
# PR #23485
export countnz
function countnz(x)
depwarn("`countnz(x)` is deprecated, use either `count(!iszero, x)` or `count(t -> t != 0, x)` instead.", :countnz)
return count(t -> t != 0, x)
end
# issue #14470
# TODO: More deprecations must be removed in src/cgutils.cpp:emit_array_nd_index()
# TODO: Re-enable the disabled tests marked PLI
# On the Julia side, this definition will gracefully supercede the new behavior (already coded)
@inline function checkbounds_indices(::Type{Bool}, IA::Tuple{Any,Vararg{Any}}, ::Tuple{})
any(x->unsafe_length(x)==0, IA) && return false
any(x->unsafe_length(x)!=1, IA) && return _depwarn_for_trailing_indices(IA)
return true
end
function _depwarn_for_trailing_indices(n::Integer) # Called by the C boundscheck
depwarn("omitting indices for non-singleton trailing dimensions is deprecated. Add `1`s as trailing indices or use `reshape(A, Val($n))` to make the dimensionality of the array match the number of indices.", (:getindex, :setindex!, :view))
true
end
function _depwarn_for_trailing_indices(t::Tuple)
depwarn("omitting indices for non-singleton trailing dimensions is deprecated. Add `$(join(map(first, t),','))` as trailing indices or use `reshape` to make the dimensionality of the array match the number of indices.", (:getindex, :setindex!, :view))
true
end
# issue #22791
@deprecate select partialsort
@deprecate select! partialsort!
@deprecate selectperm partialsortperm
@deprecate selectperm! partialsortperm!
# `initialized` keyword arg to `sort` is deprecated in sort.jl
@deprecate promote_noncircular promote false
import .Iterators.enumerate
@deprecate enumerate(i::IndexLinear, A::AbstractArray) pairs(i, A)
@deprecate enumerate(i::IndexCartesian, A::AbstractArray) pairs(i, A)
@deprecate_binding Range AbstractRange
# issue #5794
@deprecate map(f, d::T) where {T<:AbstractDict} T( f(p) for p in pairs(d) )
# issue #26359 - map over sets
@deprecate map(f, s::AbstractSet) Set( f(v) for v in s )
# issue #17086
@deprecate isleaftype isconcretetype
@deprecate isabstract isabstracttype
# PR #22932
@deprecate +(a::Number, b::AbstractArray) a .+ b
@deprecate +(a::AbstractArray, b::Number) a .+ b
@deprecate -(a::Number, b::AbstractArray) a .- b
@deprecate -(a::AbstractArray, b::Number) a .- b
@deprecate(ind2sub(dims::NTuple{N,Integer}, idx::CartesianIndex{N}) where N, Tuple(idx))
@deprecate contains(eq::Function, itr, x) any(y->eq(y,x), itr)
# PR #23690
# `SSHCredential` and `UserPasswordCredential` constructors using `prompt_if_incorrect`
# are deprecated in stdlib/LibGit2/types.jl.
# deprecate ones/zeros methods accepting an array as first argument
function ones(a::AbstractArray, ::Type{T}, dims::Tuple) where {T}
depwarn(string("`ones(a::AbstractArray, ::Type{T}, dims::Tuple) where T` is ",
"deprecated, use `fill!(similar(a, T, dims), 1)` instead, or ",
"`fill!(similar(a, T, dims), one(T))` where necessary."), :ones)
return fill!(similar(a, T, dims), one(T))
end
function ones(a::AbstractArray, ::Type{T}, dims...) where {T}
depwarn(string("`ones(a::AbstractArray, ::Type{T}, dims...) where T` is ",
"deprecated, use `fill!(similar(a, T, dims...), 1)` instead, or ",
"`fill!(similar(a, T, dims...), one(T))` where necessary."), :ones)
return fill!(similar(a, T, dims...), one(T))
end
function ones(a::AbstractArray, ::Type{T}) where {T}
depwarn(string("`ones(a::AbstractArray, ::Type{T}) where T` is deprecated, ",
"use `fill!(similar(a, T), 1)` instead, or `fill!(similar(a, T), one(T))` ",
"where necessary."), :ones)
return fill!(similar(a, T), one(T))
end
function ones(a::AbstractArray)
depwarn(string("`ones(a::AbstractArray)` is deprecated, consider ",
"`fill(1, size(a))`, `fill!(copy(a), 1)`, or `fill!(similar(a), 1)`. Where ",
"necessary, use `fill!(similar(a), one(eltype(a)))`."), :ones)
return fill!(similar(a), one(eltype(a)))
end
function zeros(a::AbstractArray, ::Type{T}, dims::Tuple) where {T}
depwarn(string("`zeros(a::AbstractArray, ::Type{T}, dims::Tuple) where T` is ",
"deprecated, use `fill!(similar(a, T, dims), 0)` instead, or ",
"`fill!(similar(a, T, dims), zero(T))` where necessary."), :zeros)
return fill!(similar(a, T, dims), zero(T))
end
function zeros(a::AbstractArray, ::Type{T}, dims...) where {T}
depwarn(string("`zeros(a::AbstractArray, ::Type{T}, dims...) where T` is ",
"deprecated, use `fill!(similar(a, T, dims...), 0)` instead, or ",
"`fill!(similar(a, T, dims...), zero(T))` where necessary."), :zeros)
return fill!(similar(a, T, dims...), zero(T))
end
function zeros(a::AbstractArray, ::Type{T}) where {T}
depwarn(string("`zeros(a::AbstractArray, ::Type{T}) where T` is deprecated, ",
"use `fill!(similar(a, T), 0)` instead, or `fill!(similar(a, T), zero(T))` ",
"where necessary."), :zeros)
return fill!(similar(a, T), zero(T))
end
function zeros(a::AbstractArray)
depwarn(string("`zeros(a::AbstractArray)` is deprecated, consider `zero(a)`, ",
"`fill(0, size(a))`, `fill!(copy(a), 0)`, or ",
"`fill!(similar(a), 0)`. Where necessary, use ",
"`fill!(similar(a), zero(eltype(a)))`."), :zeros)
return fill!(similar(a), zero(eltype(a)))
end
export tic, toq, toc
function tic()
depwarn("`tic()` is deprecated, use `@time`, `@elapsed`, or calls to `time_ns()` instead.", :tic)
t0 = time_ns()
task_local_storage(:TIMERS, (t0, get(task_local_storage(), :TIMERS, ())))
return t0
end
function _toq()
t1 = time_ns()
timers = get(task_local_storage(), :TIMERS, ())
if timers === ()
error("`toc()` without `tic()`")
end
t0 = timers[1]::UInt64
task_local_storage(:TIMERS, timers[2])
(t1-t0)/1e9
end
function toq()
depwarn("`toq()` is deprecated, use `@elapsed` or calls to `time_ns()` instead.", :toq)
return _toq()
end
function toc()
depwarn("`toc()` is deprecated, use `@time`, `@elapsed`, or calls to `time_ns()` instead.", :toc)
t = _toq()
println("elapsed time: ", t, " seconds")
return t
end
# A[I...] .= with scalar indices should modify the element at A[I...]
function Broadcast.dotview(A::AbstractArray, args::Number...)
depwarn("the behavior of `A[I...] .= X` with scalar indices will change in the future. Use `A[I...] = X` instead.", :broadcast!)
view(A, args...)
end
Broadcast.dotview(A::AbstractArray{<:AbstractArray}, args::Integer...) = getindex(A, args...)
# Upon removing deprecations, also enable the @testset "scalar .=" in test/broadcast.jl
# indexing with A[true] will throw an argument error in the future
function to_index(i::Bool)
depwarn("indexing with Bool values is deprecated. Convert the index to an integer first with `Int(i)`.", (:getindex, :setindex!, :view))
convert(Int,i)::Int
end
# After deprecation is removed, enable the @testset "indexing by Bool values" in test/arrayops.jl
# Also un-comment the new definition in base/indices.jl
# Broadcast no longer defaults to treating its arguments as scalar (#)
@noinline function Broadcast.broadcastable(x)
depwarn("""
broadcast will default to iterating over its arguments in the future. Wrap arguments of
type `x::$(typeof(x))` with `Ref(x)` to ensure they broadcast as "scalar" elements.
""", (:broadcast, :broadcast!))
return Ref{typeof(x)}(x)
end
@eval Base.Broadcast Base.@deprecate_binding Scalar DefaultArrayStyle{0} false
# After deprecation is removed, enable the fallback broadcastable definitions in base/broadcast.jl
# deprecate BitArray{...}(shape...) constructors to BitArray{...}(undef, shape...) equivalents
@deprecate BitArray{N}(dims::Vararg{Int,N}) where {N} BitArray{N}(undef, dims)
@deprecate BitArray(dims::NTuple{N,Int}) where {N} BitArray(undef, dims...)
@deprecate BitArray(dims::Integer...) BitArray(undef, dims)
## deprecate full
export full
# full no-op fallback
function full(A::AbstractArray)
depwarn(string(
"The no-op `full(A::AbstractArray)` fallback has been deprecated, and no more ",
"specific `full` method for $(typeof(A)) exists. Furthermore, `full` in general ",
"has been deprecated.\n\n",
"To replace `full(A)`, as appropriate consider dismabiguating with a concrete ",
"array constructor (e.g. `Array(A)`), with an abstract array constructor (e.g.`AbstractArray(A)`), ",
"instead `convert`ing to an array type (e.g `convert(Array, A)`, `convert(AbstractArray, A)`), ",
"or using another such operation that addresses your specific use case."), :full)
return A
end
# issue #20816
@deprecate strwidth textwidth
@deprecate charwidth textwidth
@deprecate find(x::Number) findall(!iszero, x)
@deprecate findnext(A, v, i::Integer) coalesce(findnext(isequal(v), A, i), 0)
@deprecate findfirst(A, v) coalesce(findfirst(isequal(v), A), 0)
@deprecate findprev(A, v, i::Integer) coalesce(findprev(isequal(v), A, i), 0)
@deprecate findlast(A, v) coalesce(findlast(isequal(v), A), 0)
# to fix ambiguities introduced by deprecations
findnext(pred::Function, A, i::Integer) = invoke(findnext, Tuple{Function, Any, Any}, pred, A, i)
findprev(pred::Function, A, i::Integer) = invoke(findprev, Tuple{Function, Any, Any}, pred, A, i)
# also remove deprecation warnings in find* functions in array.jl, sparse/sparsematrix.jl,
# and sparse/sparsevector.jl.
# issue #22849
@deprecate reinterpret(::Type{T}, a::Array{S}, dims::NTuple{N,Int}) where {T, S, N} reshape(reinterpret(T, vec(a)), dims)
@deprecate reinterpret(::Type{T}, a::ReinterpretArray{S}, dims::NTuple{N,Int}) where {T, S, N} reshape(reinterpret(T, vec(a)), dims)
# issue #24006
@deprecate linearindices(s::AbstractString) eachindex(s)
# deprecate Array(shape...)-like constructors to Array(undef, shape...) equivalents
# --> former primitive constructors
@deprecate Array{T,1}(m::Int) where {T} Array{T,1}(undef, m)
@deprecate Array{T,2}(m::Int, n::Int) where {T} Array{T,2}(undef, m, n)
@deprecate Array{T,3}(m::Int, n::Int, o::Int) where {T} Array{T,3}(undef, m, n, o)
@deprecate Array{T,N}(d::Vararg{Int,N}) where {T,N} Array{T,N}(undef, d)
@deprecate Array{T,N}(d::NTuple{N,Int}) where {T,N} Array{T,N}(undef, d)
@deprecate Array{T}(m::Int) where {T} Array{T}(undef, m)
@deprecate Array{T}(m::Int, n::Int) where {T} Array{T}(undef, m, n)
@deprecate Array{T}(m::Int, n::Int, o::Int) where {T} Array{T}(undef, m, n, o)
@deprecate Array{T}(d::NTuple{N,Int}) where {T,N} Array{T}(undef, d)
# --> former convenience constructors
@deprecate Vector{T}(m::Integer) where {T} Vector{T}(undef, m)
@deprecate Matrix{T}(m::Integer, n::Integer) where {T} Matrix{T}(undef, m, n)
@deprecate Array{T}(m::Integer) where {T} Array{T}(undef, m)
@deprecate Array{T}(m::Integer, n::Integer) where {T} Array{T}(undef, m, n)
@deprecate Array{T}(m::Integer, n::Integer, o::Integer) where {T} Array{T}(undef, m, n, o)
@deprecate Array{T}(d::Integer...) where {T} Array{T}(undef, d)
@deprecate Vector(m::Integer) Vector(undef, m)
@deprecate Matrix(m::Integer, n::Integer) Matrix(undef, m, n)
# deprecate IntSet to BitSet
@deprecate_binding IntSet BitSet
# Issue 24219
@deprecate float(x::AbstractString) parse(Float64, x)
@deprecate float(a::AbstractArray{<:AbstractString}) parse.(Float64, a)
# deprecate bits to bitstring (#24263, #24281)
@deprecate bits bitstring
# issue #24167
@deprecate EnvHash EnvDict
# issue #24349
@deprecate parse(str::AbstractString; kwargs...) Meta.parse(str; kwargs...)
@deprecate parse(str::AbstractString, pos::Int, ; kwargs...) Meta.parse(str, pos; kwargs...)
@deprecate_binding ParseError Meta.ParseError
# issue #20899
# TODO: delete JULIA_HOME deprecation in src/init.c
# cumsum and cumprod have deprecations in multidimensional.jl
# when the message is removed, the `dims` keyword argument should become required.
# issue #16307
@deprecate finalizer(o, f::Function) finalizer(f, o)
# This misses other callables but they are very rare in the wild
@deprecate finalizer(o, f::Ptr{Cvoid}) finalizer(f, o)
# Avoid ambiguity, can remove when deprecations are removed:
# This is almost certainly going to be a silent failure for code that is not updated.
finalizer(f::Ptr{Cvoid}, o::Ptr{Cvoid}) = invoke(finalizer, Tuple{Ptr{Cvoid}, Any}, f, o)
finalizer(f::Ptr{Cvoid}, o::Function) = invoke(finalizer, Tuple{Ptr{Cvoid}, Any}, f, o)
# Broadcast extension API (#23939)
@eval Broadcast begin
Base.@deprecate_binding containertype combine_styles false
Base.@deprecate_binding _containertype BroadcastStyle false
Base.@deprecate_binding promote_containertype BroadcastStyle false
Base.@deprecate_binding broadcast_c! broadcast! false ", `broadcast_c!(f, ::Type, ::Type, C, As...)` should become `broadcast!(f, C, As...)` (see the manual chapter Interfaces)"
Base.@deprecate_binding broadcast_c broadcast false ", `broadcast_c(f, ::Type{C}, As...)` should become `broadcast(f, C, nothing, nothing, As...))` (see the manual chapter Interfaces)"
Base.@deprecate_binding broadcast_t broadcast false ", `broadcast_t(f, ::Type{ElType}, shape, iter, As...)` should become `broadcast(f, Broadcast.DefaultArrayStyle{N}(), ElType, shape, As...))` (see the manual chapter Interfaces)"
end
### deprecations for lazier, less jazzy linalg transition in the next several blocks ###
# TODOs re. .' deprecation
# (1) remove .' deprecation from src/julia-syntax.scm around line 2346
# (2) remove .' documentation from base/docs/basedocs.jl around line 255
# (3) remove .'-involving code from base/show.jl around line 1277
# (4) remove .'-involving test from test/deprecation_exec.jl around line 178
# (5) remove .'-related code from src/ast.scm and src/julia-parser.scm
# A[ct]_(mul|ldiv|rdiv)_B[ct][!] methods from base/operators.jl, to deprecate
@deprecate Ac_ldiv_Bt(a,b) (\)(adjoint(a), transpose(b))
@deprecate At_ldiv_Bt(a,b) (\)(transpose(a), transpose(b))
@deprecate A_ldiv_Bt(a,b) (\)(a, transpose(b))
@deprecate At_ldiv_B(a,b) (\)(transpose(a), b)
@deprecate Ac_ldiv_Bc(a,b) (\)(adjoint(a), adjoint(b))
@deprecate A_ldiv_Bc(a,b) (\)(a, adjoint(b))
@deprecate Ac_ldiv_B(a,b) (\)(adjoint(a), b)
@deprecate At_rdiv_Bt(a,b) (/)(transpose(a), transpose(b))
@deprecate A_rdiv_Bt(a,b) (/)(a, transpose(b))
@deprecate At_rdiv_B(a,b) (/)(transpose(a), b)
@deprecate Ac_rdiv_Bc(a,b) (/)(adjoint(a), adjoint(b))
@deprecate A_rdiv_Bc(a,b) (/)(a, adjoint(b))
@deprecate Ac_rdiv_B(a,b) (/)(adjoint(a), b)
@deprecate At_mul_Bt(a,b) (*)(transpose(a), transpose(b))
@deprecate A_mul_Bt(a,b) (*)(a, transpose(b))
@deprecate At_mul_B(a,b) (*)(transpose(a), b)
@deprecate Ac_mul_Bc(a,b) (*)(adjoint(a), adjoint(b))
@deprecate A_mul_Bc(a,b) (*)(a, adjoint(b))
@deprecate Ac_mul_B(a,b) (*)(adjoint(a), b)
# issue #24822
@deprecate_binding Display AbstractDisplay
# 24595
@deprecate falses(A::AbstractArray) falses(size(A))
@deprecate trues(A::AbstractArray) trues(size(A))
# issue #24794
@deprecate linspace(start, stop) range(start, stop=stop, length=50)
@deprecate logspace(start, stop) exp10.(range(start, stop=stop, length=50))
# 24490 - warnings and messages
const log_info_to = Dict{Tuple{Union{Module,Nothing},Union{Symbol,Nothing}},IO}()
const log_warn_to = Dict{Tuple{Union{Module,Nothing},Union{Symbol,Nothing}},IO}()
const log_error_to = Dict{Tuple{Union{Module,Nothing},Union{Symbol,Nothing}},IO}()
function _redirect(io::IO, log_to::Dict, sf::StackTraces.StackFrame)
(sf.linfo isa Core.MethodInstance) || return io
mod = sf.linfo.def
isa(mod, Method) && (mod = mod.module)
fun = sf.func
if haskey(log_to, (mod,fun))
return log_to[(mod,fun)]
elseif haskey(log_to, (mod,nothing))
return log_to[(mod,nothing)]
elseif haskey(log_to, (nothing,nothing))
return log_to[(nothing,nothing)]
else
return io
end
end
function _redirect(io::IO, log_to::Dict, fun::Symbol)
clos = string("#",fun,"#")
kw = string("kw##",fun)
local sf
break_next_frame = false
for trace in backtrace()
stack::Vector{StackFrame} = StackTraces.lookup(trace)
filter!(frame -> !frame.from_c, stack)
for frame in stack
(frame.linfo isa Core.MethodInstance) || continue
sf = frame
break_next_frame && (@goto skip)
mod = frame.linfo.def
isa(mod, Method) && (mod = mod.module)
mod === Base || continue
sff = string(frame.func)
if frame.func == fun || startswith(sff, clos) || startswith(sff, kw)
break_next_frame = true
end
end
end
@label skip
_redirect(io, log_to, sf)
end
@inline function redirect(io::IO, log_to::Dict, arg::Union{Symbol,StackTraces.StackFrame})
if isempty(log_to)
return io
else
if length(log_to)==1 && haskey(log_to,(nothing,nothing))
return log_to[(nothing,nothing)]
else
return _redirect(io, log_to, arg)
end
end
end
"""
logging(io [, m [, f]][; kind=:all])
logging([; kind=:all])
Stream output of informational, warning, and/or error messages to `io`,
overriding what was otherwise specified. Optionally, divert stream only for
module `m`, or specifically function `f` within `m`. `kind` can be `:all` (the
default), `:info`, `:warn`, or `:error`. See `Base.log_{info,warn,error}_to`
for the current set of redirections. Call `logging` with no arguments (or just
the `kind`) to reset everything.
"""
function logging(io::IO, m::Union{Module,Nothing}=nothing, f::Union{Symbol,Nothing}=nothing;
kind::Symbol=:all)
depwarn("""`logging()` is deprecated, use `with_logger` instead to capture
messages from `Base`.""", :logging)
(kind==:all || kind==:info) && (log_info_to[(m,f)] = io)
(kind==:all || kind==:warn) && (log_warn_to[(m,f)] = io)
(kind==:all || kind==:error) && (log_error_to[(m,f)] = io)
nothing
end
function logging(; kind::Symbol=:all)
depwarn("""`logging()` is deprecated, use `with_logger` instead to capture
messages from `Base`.""", :logging)
(kind==:all || kind==:info) && empty!(log_info_to)
(kind==:all || kind==:warn) && empty!(log_warn_to)
(kind==:all || kind==:error) && empty!(log_error_to)
nothing
end
"""
info([io, ] msg..., [prefix="INFO: "])
Display an informational message.
Argument `msg` is a string describing the information to be displayed.
The `prefix` keyword argument can be used to override the default
prepending of `msg`.
# Examples
```jldoctest
julia> info("hello world")
INFO: hello world
julia> info("hello world"; prefix="MY INFO: ")
MY INFO: hello world
```
See also [`logging`](@ref).
"""
function info(io::IO, msg...; prefix="INFO: ")
depwarn("`info()` is deprecated, use `@info` instead.", :info)
buf = IOBuffer()
iob = redirect(IOContext(buf, io), log_info_to, :info)
printstyled(iob, prefix; bold=true, color=info_color())
printstyled(iob, chomp(string(msg...)), '\n', color=info_color())
print(io, String(take!(buf)))
return
end
info(msg...; prefix="INFO: ") = info(stderr, msg..., prefix=prefix)
# print a warning only once
const have_warned = Set()
warn_once(io::IO, msg...) = warn(io, msg..., once=true)
warn_once(msg...) = warn(stderr, msg..., once=true)
"""
warn([io, ] msg..., [prefix="WARNING: ", once=false, key=nothing, bt=nothing, filename=nothing, lineno::Int=0])
Display a warning. Argument `msg` is a string describing the warning to be
displayed. Set `once` to true and specify a `key` to only display `msg` the
first time `warn` is called. If `bt` is not `nothing` a backtrace is displayed.
If `filename` is not `nothing` both it and `lineno` are displayed.
See also [`logging`](@ref).
"""
function warn(io::IO, msg...;
prefix="WARNING: ", once=false, key=nothing, bt=nothing,
filename=nothing, lineno::Int=0)
depwarn("`warn()` is deprecated, use `@warn` instead.", :warn)
str = chomp(string(msg...))
if once
if key === nothing
key = str