Skip to content

Commit

Permalink
Deprecate DevNull, STDIN, STDOUT, and STDERR to lowercase (#25959)
Browse files Browse the repository at this point in the history
* Adjust some uses of std(in|out|err) as a variable name

This includes bumping the Documenter requirement to 0.13.2, which
contains similar changes for usages of these names as variables
  • Loading branch information
ararslan authored and JeffBezanson committed Feb 23, 2018
1 parent 88a6b40 commit 446085a
Show file tree
Hide file tree
Showing 97 changed files with 445 additions and 431 deletions.
2 changes: 1 addition & 1 deletion DISTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ for result in eachrow(results)
end
```

This will write color-coded lines to STDOUT.
This will write color-coded lines to `stdout`.
All lines in red must be investigated as they signify potential breakages caused by the
backport version.
Lines in yellow should be looked into since it means a package ran on one version but
Expand Down
5 changes: 4 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,9 @@ Deprecated or removed
* The fallback method `^(x, p::Integer)` is deprecated. If your type relied on this definition,
add a method such as `^(x::MyType, p::Integer) = Base.power_by_squaring(x, p)` ([#23332]).

* `DevNull`, `STDIN`, `STDOUT`, and `STDERR` have been renamed to `devnull`, `stdin`, `stdout`,
and `stderr`, respectively ([#25786]).

* `wait` and `fetch` on `Task` now resemble the interface of `Future`

Command-line option changes
Expand Down Expand Up @@ -1369,4 +1372,4 @@ Command-line option changes
[#25990]: https://github.com/JuliaLang/julia/issues/25990
[#25998]: https://github.com/JuliaLang/julia/issues/25998
[#26009]: https://github.com/JuliaLang/julia/issues/26009
[#26071]: https://github.com/JuliaLang/julia/issues/26071
[#26071]: https://github.com/JuliaLang/julia/issues/26071
10 changes: 5 additions & 5 deletions base/boot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,8 @@ atdoc!(λ) = global atdoc = λ
abstract type IO end
struct CoreSTDOUT <: IO end
struct CoreSTDERR <: IO end
const STDOUT = CoreSTDOUT()
const STDERR = CoreSTDERR()
const stdout = CoreSTDOUT()
const stderr = CoreSTDERR()
io_pointer(::CoreSTDOUT) = Intrinsics.pointerref(Intrinsics.cglobal(:jl_uv_stdout, Ptr{Cvoid}), 1, 1)
io_pointer(::CoreSTDERR) = Intrinsics.pointerref(Intrinsics.cglobal(:jl_uv_stderr, Ptr{Cvoid}), 1, 1)

Expand All @@ -455,9 +455,9 @@ print(io::IO, @nospecialize(x), @nospecialize a...) = (print(io, x); print(io, a
println(io::IO) = (write(io, 0x0a); nothing) # 0x0a = '\n'
println(io::IO, @nospecialize x...) = (print(io, x...); println(io))

show(@nospecialize a) = show(STDOUT, a)
print(@nospecialize a...) = print(STDOUT, a...)
println(@nospecialize a...) = println(STDOUT, a...)
show(@nospecialize a) = show(stdout, a)
print(@nospecialize a...) = print(stdout, a...)
println(@nospecialize a...) = println(stdout, a...)

struct GeneratedFunctionStub
gen
Expand Down
22 changes: 11 additions & 11 deletions base/client.jl
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ function display_error(io::IO, er, bt)
showerror(IOContext(io, :limit => true), er, bt)
println(io)
end
display_error(er, bt) = display_error(STDERR, er, bt)
display_error(er, bt) = display_error(stderr, er, bt)
display_error(er) = display_error(er, [])

function eval_user_input(@nospecialize(ast), show_value::Bool)
Expand All @@ -189,7 +189,7 @@ function eval_user_input(@nospecialize(ast), show_value::Bool)
try
invokelatest(display, value)
catch err
println(STDERR, "Evaluation succeeded, but an error occurred while showing value of type ", typeof(value), ":")
println(stderr, "Evaluation succeeded, but an error occurred while showing value of type ", typeof(value), ":")
rethrow(err)
end
println()
Expand All @@ -198,17 +198,17 @@ function eval_user_input(@nospecialize(ast), show_value::Bool)
break
catch err
if errcount > 0
println(STDERR, "SYSTEM: show(lasterr) caused an error")
println(stderr, "SYSTEM: show(lasterr) caused an error")
end
errcount, lasterr = errcount+1, err
if errcount > 2
println(STDERR, "WARNING: it is likely that something important is broken, and Julia will not be able to continue normally")
println(stderr, "WARNING: it is likely that something important is broken, and Julia will not be able to continue normally")
break
end
bt = catch_backtrace()
end
end
isa(STDIN, TTY) && println()
isa(stdin, TTY) && println()
nothing
end

Expand Down Expand Up @@ -333,7 +333,7 @@ function exec_options(opts)
end
repl |= is_interactive
if repl
interactiveinput = isa(STDIN, TTY)
interactiveinput = isa(stdin, TTY)
if interactiveinput
global is_interactive = true
banner = (opts.banner != 0) # --banner!=no
Expand Down Expand Up @@ -374,8 +374,8 @@ function __atreplinit(repl)
try
f(repl)
catch err
showerror(STDERR, err)
println(STDERR)
showerror(stderr, err)
println(stderr)
end
end
end
Expand All @@ -390,7 +390,7 @@ function run_main_repl(interactive::Bool, quiet::Bool, banner::Bool, history_fil
if interactive && isassigned(REPL_MODULE_REF)
invokelatest(REPL_MODULE_REF[]) do REPL
term_env = get(ENV, "TERM", @static Sys.iswindows() ? "" : "dumb")
term = REPL.Terminals.TTYTerminal(term_env, STDIN, STDOUT, STDERR)
term = REPL.Terminals.TTYTerminal(term_env, stdin, stdout, stderr)
color_set || (global have_color = REPL.Terminals.hascolor(term))
banner && REPL.banner(term, term)
if term.term_type == "dumb"
Expand All @@ -412,7 +412,7 @@ function run_main_repl(interactive::Bool, quiet::Bool, banner::Bool, history_fil
@warn "REPL provider not available: using basic fallback"
end
banner && Base.banner()
let input = STDIN
let input = stdin
if isa(input, File) || isa(input, IOStream)
# for files, we can slurp in the whole thing at once
ex = parse_input_line(read(input, String))
Expand All @@ -430,7 +430,7 @@ function run_main_repl(interactive::Bool, quiet::Bool, banner::Bool, history_fil
while isopen(input) || !eof(input)
if interactive
print("julia> ")
flush(STDOUT)
flush(stdout)
end
eval_user_input(parse_input_line(input), true)
end
Expand Down
8 changes: 4 additions & 4 deletions base/clipboard.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

if Sys.isapple()
function clipboard(x)
open(pipeline(`pbcopy`, stderr=STDERR), "w") do io
open(pipeline(`pbcopy`, stderr=stderr), "w") do io
print(io, x)
end
end
Expand All @@ -28,7 +28,7 @@ elseif Sys.islinux() || Sys.KERNEL === :FreeBSD
global _clipboardcmd
_clipboardcmd !== nothing && return _clipboardcmd
for cmd in (:xclip, :xsel)
success(pipeline(`which $cmd`, DevNull)) && return _clipboardcmd = cmd
success(pipeline(`which $cmd`, devnull)) && return _clipboardcmd = cmd
end
pkgs = @static if Sys.islinux()
"xsel or xclip"
Expand All @@ -43,7 +43,7 @@ elseif Sys.islinux() || Sys.KERNEL === :FreeBSD
if cmd === nothing
error("unexpected clipboard command: $c")
end
open(pipeline(cmd, stderr=STDERR), "w") do io
open(pipeline(cmd, stderr=stderr), "w") do io
print(io, x)
end
end
Expand All @@ -53,7 +53,7 @@ elseif Sys.islinux() || Sys.KERNEL === :FreeBSD
if cmd === nothing
error("unexpected clipboard command: $c")
end
read(pipeline(cmd, stderr=STDERR), String)
read(pipeline(cmd, stderr=stderr), String)
end

elseif Sys.iswindows()
Expand Down
2 changes: 1 addition & 1 deletion base/compiler/bootstrap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ let fs = Any[typeinf_ext, typeinf, typeinf_edge, pure_eval_call],
x = T_IFUNC[i]
push!(fs, x[3])
else
println(STDERR, "WARNING: tfunc missing for ", reinterpret(IntrinsicFunction, Int32(i)))
println(stderr, "WARNING: tfunc missing for ", reinterpret(IntrinsicFunction, Int32(i)))
end
end
for f in fs
Expand Down
2 changes: 1 addition & 1 deletion base/compiler/compiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ getfield(getfield(Main, :Core), :eval)(getfield(Main, :Core), :(baremodule Compi

using Core.Intrinsics, Core.IR

import Core: print, println, show, write, unsafe_write, STDOUT, STDERR,
import Core: print, println, show, write, unsafe_write, stdout, stderr,
_apply, svec, apply_type, Builtin, IntrinsicFunction, MethodInstance

const getproperty = getfield
Expand Down
2 changes: 1 addition & 1 deletion base/compiler/optimize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3733,7 +3733,7 @@ macro check_ast(ctx, ex)
println("Code:")
println(ctx.sv.src)
println("Value Info Map:")
show_info(STDOUT, ctx.infomap, ctx)
show_info(stdout, ctx.infomap, ctx)
ccall(:abort, Union{}, ())
end
end
Expand Down
4 changes: 2 additions & 2 deletions base/compiler/validation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ function validate_code_in_debug_mode(linfo::MethodInstance, src::CodeInfo, kind:
if !isempty(errors)
for e in errors
if linfo.def isa Method
println(STDERR, "WARNING: Encountered invalid ", kind, " code for method ",
println(stderr, "WARNING: Encountered invalid ", kind, " code for method ",
linfo.def, ": ", e)
else
println(STDERR, "WARNING: Encountered invalid ", kind, " code for top level expression in ",
println(stderr, "WARNING: Encountered invalid ", kind, " code for top level expression in ",
linfo.def, ": ", e)
end
end
Expand Down
12 changes: 6 additions & 6 deletions base/coreio.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

print(xs...) = print(STDOUT::IO, xs...)
println(xs...) = println(STDOUT::IO, xs...)
print(xs...) = print(stdout::IO, xs...)
println(xs...) = println(stdout::IO, xs...)
println(io::IO) = print(io, '\n')

struct DevNullStream <: IO end
const DevNull = DevNullStream()
const devnull = DevNullStream()
isreadable(::DevNullStream) = false
iswritable(::DevNullStream) = true
isopen(::DevNullStream) = true
Expand All @@ -26,6 +26,6 @@ let CoreIO = Union{Core.CoreSTDOUT, Core.CoreSTDERR}
unsafe_write(io::CoreIO, x::Ptr{UInt8}, nb::UInt) = Core.unsafe_write(io, x, nb)
end

STDIN = DevNull
STDOUT = Core.STDOUT
STDERR = Core.STDERR
stdin = devnull
stdout = Core.stdout
stderr = Core.stderr
21 changes: 14 additions & 7 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,12 @@ 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)
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))),
Expr(:const, Expr(:(=), esc(old), esc(new))),
constant ? Expr(:const, Expr(:(=), esc(old), esc(new))) : Expr(:(=), esc(old), esc(new)),
Expr(:call, :deprecate, __module__, Expr(:quote, old)))
end

Expand Down Expand Up @@ -961,14 +961,14 @@ function info(io::IO, msg...; prefix="INFO: ")
print(io, String(take!(buf)))
return
end
info(msg...; prefix="INFO: ") = info(STDERR, msg..., prefix=prefix)
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_once(msg...) = warn(stderr, msg..., once=true)

"""
warn([io, ] msg..., [prefix="WARNING: ", once=false, key=nothing, bt=nothing, filename=nothing, lineno::Int=0])
Expand Down Expand Up @@ -1018,19 +1018,19 @@ julia> warn("Beep Beep")
WARNING: Beep Beep
```
"""
warn(msg...; kw...) = warn(STDERR, msg...; kw...)
warn(msg...; kw...) = warn(stderr, msg...; kw...)

warn(io::IO, err::Exception; prefix="ERROR: ", kw...) =
warn(io, sprint(showerror, err), prefix=prefix; kw...)

warn(err::Exception; prefix="ERROR: ", kw...) =
warn(STDERR, err, prefix=prefix; kw...)
warn(stderr, err, prefix=prefix; kw...)

info(io::IO, err::Exception; prefix="ERROR: ", kw...) =
info(io, sprint(showerror, err), prefix=prefix; kw...)

info(err::Exception; prefix="ERROR: ", kw...) =
info(STDERR, err, prefix=prefix; kw...)
info(stderr, err, prefix=prefix; kw...)

# issue #25082
@deprecate_binding Void Nothing
Expand Down Expand Up @@ -1436,6 +1436,13 @@ function slicedim(A::AbstractVector, d::Integer, i::Number)
end
end

# Issue #25786
@deprecate_binding DevNull devnull
# TODO: When these are removed, also remove the uppercase variants in libuv.jl and stream.jl
@deprecate_binding STDIN stdin true nothing false
@deprecate_binding STDOUT stdout true nothing false
@deprecate_binding STDERR stderr true nothing false

# PR 25062
@deprecate(link_pipe(pipe; julia_only_read = true, julia_only_write = true),
link_pipe!(pipe, reader_supports_async = julia_only_read, writer_supports_async = julia_only_write),
Expand Down
6 changes: 3 additions & 3 deletions base/docs/basedocs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -789,16 +789,16 @@ A variable referring to the last computed value, automatically set at the intera
kw"ans"

"""
DevNull
devnull
Used in a stream redirect to discard all data written to it. Essentially equivalent to
/dev/null on Unix or NUL on Windows. Usage:
```julia
run(pipeline(`cat test.txt`, DevNull))
run(pipeline(`cat test.txt`, devnull))
```
"""
DevNull
devnull

# doc strings for code in boot.jl and built-ins

Expand Down
2 changes: 1 addition & 1 deletion base/download.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ else
global downloadcmd
if downloadcmd === nothing
for checkcmd in (:curl, :wget, :fetch)
if success(pipeline(`which $checkcmd`, DevNull))
if success(pipeline(`which $checkcmd`, devnull))
downloadcmd = checkcmd
break
end
Expand Down
2 changes: 1 addition & 1 deletion base/errorshow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ function showerror_ambiguous(io::IO, meth, f, args)
end

#Show an error by directly calling jl_printf.
#Useful in Base submodule __init__ functions where STDERR isn't defined yet.
#Useful in Base submodule __init__ functions where stderr isn't defined yet.
function showerror_nostdio(err, msg::AbstractString)
stderr_stream = ccall(:jl_stderr_stream, Ptr{Cvoid}, ())
ccall(:jl_printf, Cint, (Ptr{Cvoid},Cstring), stderr_stream, msg)
Expand Down
8 changes: 4 additions & 4 deletions base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export
DenseMatrix,
DenseVecOrMat,
DenseVector,
DevNull,
Dict,
Dims,
Enum,
Expand Down Expand Up @@ -135,10 +134,11 @@ export
ENV,
LOAD_PATH,
PROGRAM_FILE,
STDERR,
STDIN,
STDOUT,
stderr,
stdin,
stdout,
VERSION,
devnull,

# Mathematical constants
Inf,
Expand Down
4 changes: 2 additions & 2 deletions base/initdefs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ function _atexit()
try
f()
catch err
show(STDERR, err)
println(STDERR)
show(stderr, err)
println(stderr)
end
end
end
Loading

0 comments on commit 446085a

Please sign in to comment.