Skip to content

Rename super() to supertype() #14338

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ eltype{T,n}(::Type{AbstractArray{T,n}}) = T
elsize{T}(::AbstractArray{T}) = sizeof(T)
ndims{T,n}(::AbstractArray{T,n}) = n
ndims{T,n}(::Type{AbstractArray{T,n}}) = n
ndims{T<:AbstractArray}(::Type{T}) = ndims(super(T))
ndims{T<:AbstractArray}(::Type{T}) = ndims(supertype(T))
length(t::AbstractArray) = prod(size(t))::Int
endof(a::AbstractArray) = length(a)
first(a::AbstractArray) = a[first(eachindex(a))]
Expand Down
2 changes: 1 addition & 1 deletion base/atomics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ for (typ, lt) in atomicintsmap
for rmwop in [:xchg, :add, :sub, :and, :nand, :or, :xor, :max, :min]
rmw = string(rmwop)
fn = symbol("atomic_", rmw, "!")
if (rmw == "max" || rmw == "min") && super(typ) == Unsigned
if (rmw == "max" || rmw == "min") && supertype(typ) == Unsigned
# LLVM distinguishes signedness in the operation, not the integer type.
rmw = "u" * rmw
end
Expand Down
3 changes: 3 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -918,3 +918,6 @@ function tty_size()
end
return iosize()
end

#14335
@deprecate super(T::DataType) supertype(T)
4 changes: 2 additions & 2 deletions base/dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,9 @@ function merge!(d::Associative, others::Associative...)
end
keytype{K,V}(::Type{Associative{K,V}}) = K
keytype(a::Associative) = keytype(typeof(a))
keytype{A<:Associative}(::Type{A}) = keytype(super(A))
keytype{A<:Associative}(::Type{A}) = keytype(supertype(A))
valtype{K,V}(::Type{Associative{K,V}}) = V
valtype{A<:Associative}(::Type{A}) = valtype(super(A))
valtype{A<:Associative}(::Type{A}) = valtype(supertype(A))
valtype(a::Associative) = valtype(typeof(a))
function merge(d::Associative, others::Associative...)
K, V = keytype(d), valtype(d)
Expand Down
2 changes: 1 addition & 1 deletion base/docs/Docs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ function typesummary(T::DataType)
"""
**Summary:**
```julia
$(T.abstract ? "abstract" : T.mutable ? "type" : "immutable") $T <: $(super(T))
$(T.abstract ? "abstract" : T.mutable ? "type" : "immutable") $T <: $(supertype(T))
```
"""
]
Expand Down
4 changes: 2 additions & 2 deletions base/docs/helpdb/Base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7416,11 +7416,11 @@ The inverse of `ind2sub`, returns the linear index corresponding to the provided
sub2ind

"""
super(T::DataType)
supertype(T::DataType)

Return the supertype of DataType `T`.
"""
super
supertype

"""
readline(stream=STDIN)
Expand Down
2 changes: 1 addition & 1 deletion base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1059,7 +1059,7 @@ export
promote_type,
subtypes,
instances,
super,
supertype,
typeintersect,
typejoin,
widen,
Expand Down
4 changes: 2 additions & 2 deletions base/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

const (<:) = issubtype

super(T::DataType) = T.super
supertype(T::DataType) = T.super

## generic comparison ##

Expand Down Expand Up @@ -193,7 +193,7 @@ widen{T<:Number}(x::T) = convert(widen(T), x)

eltype(::Type) = Any
eltype(::Type{Any}) = Any
eltype(t::DataType) = eltype(super(t))
eltype(t::DataType) = eltype(supertype(t))
eltype(x) = eltype(typeof(x))

# copying immutable things
Expand Down
14 changes: 7 additions & 7 deletions base/promotion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function typejoin(a::ANY, b::ANY)
while !is(b,Any)
if a <: b.name.primary
while a.name !== b.name
a = super(a)
a = supertype(a)
end
# join on parameters
n = length(a.parameters)
Expand All @@ -87,7 +87,7 @@ function typejoin(a::ANY, b::ANY)
end
return a.name.primary{p...}
end
b = super(b)
b = supertype(b)
end
return Any
end
Expand Down Expand Up @@ -157,16 +157,16 @@ end
# overflow.
function promote_result{T<:Number,S<:Number}(::Type{T},::Type{S},::Type{Bottom},::Type{Bottom})
@_pure_meta
promote_to_super(T, S, typejoin(T,S))
promote_to_supertype(T, S, typejoin(T,S))
end

# promote numeric types T and S to typejoin(T,S) if T<:S or S<:T
# for example this makes promote_type(Integer,Real) == Real without
# promoting arbitrary pairs of numeric types to Number.
promote_to_super{T<:Number }(::Type{T}, ::Type{T}, ::Type{T}) = (@_pure_meta; T)
promote_to_super{T<:Number,S<:Number}(::Type{T}, ::Type{S}, ::Type{T}) = (@_pure_meta; T)
promote_to_super{T<:Number,S<:Number}(::Type{T}, ::Type{S}, ::Type{S}) = (@_pure_meta; S)
promote_to_super{T<:Number,S<:Number}(::Type{T}, ::Type{S}, ::Type) =
promote_to_supertype{T<:Number }(::Type{T}, ::Type{T}, ::Type{T}) = (@_pure_meta; T)
promote_to_supertype{T<:Number,S<:Number}(::Type{T}, ::Type{S}, ::Type{T}) = (@_pure_meta; T)
promote_to_supertype{T<:Number,S<:Number}(::Type{T}, ::Type{S}, ::Type{S}) = (@_pure_meta; S)
promote_to_supertype{T<:Number,S<:Number}(::Type{T}, ::Type{S}, ::Type) =
error("no promotion exists for ", T, " and ", S)

+(x::Number, y::Number) = +(promote(x,y)...)
Expand Down
2 changes: 1 addition & 1 deletion base/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function _subtypes(m::Module, x::DataType, sts=Set(), visited=Set())
for s in names(m,true)
if isdefined(m,s)
t = eval(m,s)
if isa(t, DataType) && t.name.name == s && super(t).name == x.name
if isa(t, DataType) && t.name.name == s && supertype(t).name == x.name
ti = typeintersect(t, x)
ti != Bottom && push!(sts, ti)
elseif isa(t, Module) && !in(t, visited)
Expand Down
4 changes: 2 additions & 2 deletions base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,7 @@ xdump(fn::Function, io::IO, x::Array, n::Int, indent) =
# Types
xdump(fn::Function, io::IO, x::Union, n::Int, indent) = println(io, x)
function xdump(fn::Function, io::IO, x::DataType, n::Int, indent)
println(io, x, "::", typeof(x), " ", " <: ", super(x))
println(io, x, "::", typeof(x), " ", " <: ", supertype(x))
fields = fieldnames(x)
if n > 0
for idx in 1:min(10, length(fields))
Expand Down Expand Up @@ -992,7 +992,7 @@ function dumptype(io::IO, x, n::Int, indent)
if any(tt -> string(x.name) == typargs(tt), t.types)
println(io, indent, " ", s, " = ", t)
end
elseif isa(t, DataType) && super(t).name == x.name
elseif isa(t, DataType) && supertype(t).name == x.name
# type aliases
if string(s) != string(t.name)
println(io, indent, " ", s, " = ", t.name)
Expand Down
16 changes: 8 additions & 8 deletions doc/manual/types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1228,29 +1228,29 @@ As it happens, types are all composite values and thus all have a type of

:obj:`DataType` is its own type.

Another operation that applies to some types is :func:`super`, which
Another operation that applies to some types is :func:`supertype`, which
reveals a type's supertype.
Only declared types (:obj:`DataType`) have unambiguous supertypes:

.. doctest::

julia> super(Float64)
julia> supertype(Float64)
AbstractFloat

julia> super(Number)
julia> supertype(Number)
Any

julia> super(AbstractString)
julia> supertype(AbstractString)
Any

julia> super(Any)
julia> supertype(Any)
Any

If you apply :func:`super` to other type objects (or non-type objects), a
If you apply :func:`supertype` to other type objects (or non-type objects), a
:exc:`MethodError` is raised::

julia> super(Union{Float64,Int64})
ERROR: `super` has no method matching super(::Type{Union{Float64,Int64}})
julia> supertype(Union{Float64,Int64})
ERROR: `supertype` has no method matching supertype(::Type{Union{Float64,Int64}})

"Value types"
-------------
Expand Down
2 changes: 1 addition & 1 deletion doc/stdlib/base.rst
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ All Objects
Types
-----

.. function:: super(T::DataType)
.. function:: supertype(T::DataType)

.. Docstring generated from Julia source

Expand Down
4 changes: 2 additions & 2 deletions examples/juliatypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ inst(t::TagT) = t
inst(t::UnionAllT, param) = subst(t.T, Dict{Any,Any}(t.var => param))
inst(t::UnionAllT, param, rest...) = inst(inst(t,param), rest...)

super(t::TagT) = t.name===TupleName ? AnyT : inst(t.name.super, t.params...)
supertype(t::TagT) = t.name===TupleName ? AnyT : inst(t.name.super, t.params...)

extend(d::Dict, k, v) = (x = copy(d); x[k]=v; x)

Expand Down Expand Up @@ -260,7 +260,7 @@ function issub(a::TagT, b::TagT, env)
b === AnyT && return true
a === AnyT && return false
if a.name !== b.name
return issub(super(a), b, env)
return issub(supertype(a), b, env)
end
if a.name === TupleName
va, vb = a.vararg, b.vararg
Expand Down
4 changes: 2 additions & 2 deletions examples/typetree.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function store_type(sname::AbstractString, t::TypeConstructor)
end

function store_type(sname::AbstractString, t::DataType)
suptype = super(t)
suptype = supertype(t)
subtypes = (suptype != t) ? store_type(typ_name(suptype), suptype) : types_tree
tnode = add_ttnode(subtypes, sname, t)
return tnode.subtypes
Expand All @@ -71,7 +71,7 @@ function store_type(sname::AbstractString, t::Tuple)
end

function store_type(sname::AbstractString, t)
suptype = super(t)
suptype = supertype(t)
subtypes = (suptype != t) ? store_type(typ_name(suptype), suptype) : types_tree
tnode = add_ttnode(subtypes, sname, t)
return tnode.subtypes
Expand Down
2 changes: 1 addition & 1 deletion test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3317,7 +3317,7 @@ immutable RGB{T<:AbstractFloat} <: Paint{T}
end

myeltype{T}(::Type{Paint{T}}) = T
myeltype{P<:Paint}(::Type{P}) = myeltype(super(P))
myeltype{P<:Paint}(::Type{P}) = myeltype(supertype(P))
myeltype(::Type{Any}) = Any

end
Expand Down