From fb4a9fa62a09f3f37ad1b29e9cbfd1a3c00e661c Mon Sep 17 00:00:00 2001 From: "Steven G. Johnson" Date: Tue, 28 Nov 2017 23:19:24 -0500 Subject: [PATCH 1/2] rename Display -> AbstractDisplay --- base/deprecated.jl | 3 ++ base/exports.jl | 2 +- base/markdown/render/rich.jl | 2 +- base/multimedia.jl | 58 ++++++++++++++++++------------------ base/precompile.jl | 4 +-- base/repl/REPL.jl | 6 ++-- doc/src/stdlib/io-network.md | 4 +-- 7 files changed, 41 insertions(+), 38 deletions(-) diff --git a/base/deprecated.jl b/base/deprecated.jl index f037e84656c4e..2df773cd1ead5 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -2138,6 +2138,9 @@ finalizer(f::Ptr{Void}, o::Function) = invoke(finalizer, Tuple{Ptr{Void}, Any}, 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 +# issue #24822 +@deprecate_binding Display AbstractDisplay + # issue #24794 @deprecate linspace(start, stop) linspace(start, stop, 50) @deprecate logspace(start, stop) logspace(start, stop, 50) diff --git a/base/exports.jl b/base/exports.jl index 540f8eea07c10..8213ecce7b584 100644 --- a/base/exports.jl +++ b/base/exports.jl @@ -1054,7 +1054,7 @@ export UDPSocket, # multimedia I/O - Display, + AbstractDisplay, display, displayable, TextDisplay, diff --git a/base/markdown/render/rich.jl b/base/markdown/render/rich.jl index 01617b5c81404..44aaad2783ff7 100644 --- a/base/markdown/render/rich.jl +++ b/base/markdown/render/rich.jl @@ -18,7 +18,7 @@ function tohtml(m::MIME"image/svg+xml", img) show(io, m, img) end -# Display infrastructure +# AbstractDisplay infrastructure function bestmime(val) for mime in ("text/html", "image/svg+xml", "image/png", "text/plain") diff --git a/base/multimedia.jl b/base/multimedia.jl index af0ef33d4fcb4..733e3f9c6ca39 100644 --- a/base/multimedia.jl +++ b/base/multimedia.jl @@ -2,7 +2,7 @@ module Multimedia -export Display, display, pushdisplay, popdisplay, displayable, redisplay, +export AbstractDisplay, display, pushdisplay, popdisplay, displayable, redisplay, MIME, @MIME_str, reprmime, stringmime, istextmime, mimewritable, TextDisplay @@ -58,7 +58,7 @@ literal strings; to construct `MIME` types in a more flexible manner use For example, if you define a `MyImage` type and know how to write it to a PNG file, you could define a function `show(stream, ::MIME"image/png", x::MyImage) = ...` to allow -your images to be displayed on any PNG-capable `Display` (such as IJulia). As usual, be sure +your images to be displayed on any PNG-capable `AbstractDisplay` (such as IJulia). As usual, be sure to `import Base.show` in order to add new methods to the built-in Julia function `show`. @@ -158,31 +158,31 @@ for mime in ["application/atom+xml", "application/ecmascript", end ########################################################################### -# We have an abstract Display class that can be subclassed in order to +# We have an abstract AbstractDisplay class that can be subclassed in order to # define new rich-display output devices. A typical subclass should -# overload display(d::Display, m::MIME, x) for supported MIME types m, +# overload display(d::AbstractDisplay, m::MIME, x) for supported MIME types m, # (typically using reprmime or stringmime to get the MIME -# representation of x) and should also overload display(d::Display, x) -# to display x in whatever MIME type is preferred by the Display and +# representation of x) and should also overload display(d::AbstractDisplay, x) +# to display x in whatever MIME type is preferred by the AbstractDisplay and # is writable by x. display(..., x) should throw a MethodError if x # cannot be displayed. The return value of display(...) is up to the -# Display type. +# AbstractDisplay type. -abstract type Display end +abstract type AbstractDisplay end # it is convenient to accept strings instead of ::MIME -display(d::Display, mime::AbstractString, x) = display(d, MIME(mime), x) +display(d::AbstractDisplay, mime::AbstractString, x) = display(d, MIME(mime), x) display(mime::AbstractString, x) = display(MIME(mime), x) """ displayable(mime) -> Bool - displayable(d::Display, mime) -> Bool + displayable(d::AbstractDisplay, mime) -> Bool Returns a boolean value indicating whether the given `mime` type (string) is displayable by any of the displays in the current display stack, or specifically by the display `d` in the second variant. """ -displayable(d::Display, mime::AbstractString) = displayable(d, MIME(mime)) +displayable(d::AbstractDisplay, mime::AbstractString) = displayable(d, MIME(mime)) displayable(mime::AbstractString) = displayable(MIME(mime)) # simplest display, which only knows how to display text/plain @@ -190,11 +190,11 @@ displayable(mime::AbstractString) = displayable(MIME(mime)) """ TextDisplay(io::IO) -Returns a `TextDisplay <: Display`, which displays any object as the text/plain MIME type +Returns a `TextDisplay <: AbstractDisplay`, which displays any object as the text/plain MIME type (by default), writing the text representation to the given I/O stream. (This is how objects are printed in the Julia REPL.) """ -struct TextDisplay <: Display +struct TextDisplay <: AbstractDisplay io::IO end display(d::TextDisplay, M::MIME"text/plain", x) = show(d.io, M, x) @@ -213,31 +213,31 @@ close(d::TextDisplay) = close(d.io) ########################################################################### # We keep a stack of Displays, and calling display(x) uses the topmost -# Display that is capable of displaying x (doesn't throw an error) +# AbstractDisplay that is capable of displaying x (doesn't throw an error) -const displays = Display[] +const displays = AbstractDisplay[] """ - pushdisplay(d::Display) + pushdisplay(d::AbstractDisplay) Pushes a new display `d` on top of the global display-backend stack. Calling `display(x)` or `display(mime, x)` will display `x` on the topmost compatible backend in the stack (i.e., the topmost backend that does not throw a [`MethodError`](@ref)). """ -function pushdisplay(d::Display) +function pushdisplay(d::AbstractDisplay) global displays push!(displays, d) end """ popdisplay() - popdisplay(d::Display) + popdisplay(d::AbstractDisplay) Pop the topmost backend off of the display-backend stack, or the topmost copy of `d` in the second variant. """ popdisplay() = pop!(displays) -function popdisplay(d::Display) +function popdisplay(d::AbstractDisplay) for i = length(displays):-1:1 if d == displays[i] return splice!(displays, i) @@ -250,15 +250,15 @@ function reinit_displays() pushdisplay(TextDisplay(STDOUT)) end -xdisplayable(D::Display, args...) = applicable(display, D, args...) +xdisplayable(D::AbstractDisplay, args...) = applicable(display, D, args...) """ display(x) - display(d::Display, x) + display(d::AbstractDisplay, x) display(mime, x) - display(d::Display, mime, x) + display(d::AbstractDisplay, mime, x) -Display `x` using the topmost applicable display in the display stack, typically using the +AbstractDisplay `x` using the topmost applicable display in the display stack, typically using the richest supported multimedia output for `x`, with plain-text [`STDOUT`](@ref) output as a fallback. The `display(d, x)` variant attempts to display `x` on the given display `d` only, throwing a [`MethodError`](@ref) if `d` cannot display objects of this type. @@ -304,7 +304,7 @@ function display(m::MIME, x) throw(MethodError(display, (m, x))) end -displayable(d::D, ::MIME{mime}) where {D<:Display,mime} = +displayable(d::D, ::MIME{mime}) where {D<:AbstractDisplay,mime} = method_exists(display, Tuple{D,MIME{mime},Any}) function displayable(m::MIME) @@ -315,7 +315,7 @@ function displayable(m::MIME) end ########################################################################### -# The redisplay method can be overridden by a Display in order to +# The redisplay method can be overridden by a AbstractDisplay in order to # update an existing display (instead of, for example, opening a new # window), and is used by the IJulia interface to defer display # until the next interactive prompt. This is especially useful @@ -324,9 +324,9 @@ end """ redisplay(x) - redisplay(d::Display, x) + redisplay(d::AbstractDisplay, x) redisplay(mime, x) - redisplay(d::Display, mime, x) + redisplay(d::AbstractDisplay, mime, x) By default, the `redisplay` functions simply call [`display`](@ref). However, some display backends may override `redisplay` to modify an existing @@ -364,8 +364,8 @@ function redisplay(m::Union{MIME,AbstractString}, x) end # default redisplay is simply to call display -redisplay(d::Display, x) = display(d, x) -redisplay(d::Display, m::Union{MIME,AbstractString}, x) = display(d, m, x) +redisplay(d::AbstractDisplay, x) = display(d, x) +redisplay(d::AbstractDisplay, m::Union{MIME,AbstractString}, x) = display(d, m, x) ########################################################################### diff --git a/base/precompile.jl b/base/precompile.jl index 08b1b636f60c2..accf477cad0ac 100644 --- a/base/precompile.jl +++ b/base/precompile.jl @@ -199,7 +199,7 @@ precompile(Tuple{typeof(Base._rsearchindex), Array{Int8, 1}, Array{UInt8, 1}, In precompile(Tuple{typeof(Base._rsearch), Array{Int8, 1}, Array{UInt8, 1}, Int64}) precompile(Tuple{typeof(Base.rsearch), Array{UInt8, 1}, Char, Int64}) precompile(Tuple{typeof(Base.rsearch), Array{Int8, 1}, Char, Int64}) -precompile(Tuple{typeof(Base.splice!), Array{Base.Multimedia.Display, 1}, Int64, Array{Any, 1}}) +precompile(Tuple{typeof(Base.splice!), Array{Base.Multimedia.AbstractDisplay, 1}, Int64, Array{Any, 1}}) precompile(Tuple{typeof(Core.Inference.isbits), Base.LineEdit.EmptyCompletionProvider}) precompile(Tuple{typeof(Core.Inference.isbits), Base.LineEdit.EmptyHistoryProvider}) precompile(Tuple{typeof(Base._setindex!), Base.Dict{Symbol, Any}, Base.LineEdit.Prompt, Symbol, Int64}) @@ -341,7 +341,7 @@ precompile(Tuple{typeof(Base.LineEdit.setup_prefix_keymap), Base.REPL.REPLHistor precompile(Tuple{typeof(Base.getindex), Type{Base.Dict{Any, Any}}, Base.Dict{Any, Any}, Base.Dict{Any, Any}, Base.Dict{Any, Any}, Base.Dict{Any, Any}, Base.Dict{Any, Any}, Base.Dict{Any, Any}}) precompile(Tuple{typeof(Base.prepend!), Array{Base.Dict{Any, Any}, 1}, Array{Base.Dict{Any, Any}, 1}}) precompile(Tuple{typeof(Base.REPL.mode_keymap), Base.LineEdit.Prompt}) -precompile(Tuple{typeof(Core.Inference.isbits), Array{Base.Multimedia.Display, 1}}) +precompile(Tuple{typeof(Core.Inference.isbits), Array{Base.Multimedia.AbstractDisplay, 1}}) precompile(Tuple{typeof(Base.Multimedia.popdisplay), Base.REPL.REPLDisplay{Base.REPL.LineEditREPL}}) precompile(Tuple{Type{String}, Base.BitArray{1}}) precompile(Tuple{typeof(Base.REPL.ends_with_semicolon), String}) diff --git a/base/repl/REPL.jl b/base/repl/REPL.jl index cebdef8a0810f..d9574df1147a4 100644 --- a/base/repl/REPL.jl +++ b/base/repl/REPL.jl @@ -14,7 +14,7 @@ export StreamREPL import Base: - Display, + AbstractDisplay, display, show, AnyDict, @@ -113,7 +113,7 @@ function ip_matches_func(ip, func::Symbol) return false end -struct REPLDisplay{R<:AbstractREPL} <: Display +struct REPLDisplay{R<:AbstractREPL} <: AbstractDisplay repl::R end @@ -271,7 +271,7 @@ mutable struct LineEditREPL <: AbstractREPL in_help::Bool envcolors::Bool waserror::Bool - specialdisplay::Union{Void,Display} + specialdisplay::Union{Void,AbstractDisplay} options::Options interface::ModalInterface backendref::REPLBackendRef diff --git a/doc/src/stdlib/io-network.md b/doc/src/stdlib/io-network.md index 060baec61eaad..50e90e2aee0dd 100644 --- a/doc/src/stdlib/io-network.md +++ b/doc/src/stdlib/io-network.md @@ -89,7 +89,7 @@ output (such as images, formatted text, or even audio and video), consisting of `x` (with a plain-text fallback). * Overloading [`show`](@ref) allows one to indicate arbitrary multimedia representations (keyed by standard MIME types) of user-defined types. - * Multimedia-capable display backends may be registered by subclassing a generic `Display` type + * Multimedia-capable display backends may be registered by subclassing a generic `AbstractDisplay` type and pushing them onto a stack of display backends via [`pushdisplay`](@ref). The base Julia runtime provides only plain-text display, but richer displays may be enabled by @@ -111,7 +111,7 @@ PNG images in a window can register this capability with Julia, so that calling types with PNG representations will automatically display the image using the module's window. In order to define a new display backend, one should first create a subtype `D` of the abstract -class `Display`. Then, for each MIME type (`mime` string) that can be displayed on `D`, one should +class `AbstractDisplay`. Then, for each MIME type (`mime` string) that can be displayed on `D`, one should define a function `display(d::D, ::MIME"mime", x) = ...` that displays `x` as that MIME type, usually by calling [`reprmime(mime, x)`](@ref). A `MethodError` should be thrown if `x` cannot be displayed as that MIME type; this is automatic if one calls [`reprmime`](@ref). Finally, one should define a function From 365260da96bdd716e83548ebf62842962b72b9a3 Mon Sep 17 00:00:00 2001 From: "Steven G. Johnson" Date: Tue, 28 Nov 2017 23:22:02 -0500 Subject: [PATCH 2/2] NEWS --- NEWS.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS.md b/NEWS.md index a9d2533299cf2..51ff5727d001e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -529,6 +529,8 @@ Deprecated or removed * The unexported type `AbstractIOBuffer` has been renamed to `GenericIOBuffer` ([#17360] [#22796]). + * `Display` has been renamed to `AbstractDisplay` ([#24831]). + * Remaining vectorized methods over `SparseVector`s, particularly `floor`, `ceil`, `trunc`, `round`, and most common transcendental functions such as `exp`, `log`, and `sin` variants, have been deprecated in favor of dot-syntax ([#22961]).