Skip to content
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

Add Compat for TypeUtils #304

Closed
wants to merge 2 commits into from
Closed
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: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ Currently, the `@compat` macro supports the following syntaxes:

* `Compat.isapprox` with `nans` keyword argument [#20022](https://github.com/JuliaLang/julia/pull/20022)

* The `isabstract`, `parameter_upper_bound`, `typename` reflection methods were added in Julia 0.6. This package re-exports these from the `Compat.TypeUtils` submodule. On earlier versions of julia, that module contains the same functions, but operating on the pre-0.6 type system representation.

* `take!` method for `Task`s since some functions now return `Channel`s instead of `Task`s [#19841](https://github.com/JuliaLang/julia/pull/19841).

## Renamed functions
Expand Down
12 changes: 11 additions & 1 deletion src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1773,4 +1773,14 @@ else
import Base.isapprox
end

end # module
module TypeUtils
@static if isdefined(Core, :UnionAll)
using Base: isabstract, parameter_upper_bound, typename
else
isabstract(t::DataType) = t.abstract
parameter_upper_bound(t::DataType, idx) = t.parameters[idx].ub
typename(t::DataType) = t.name
end
export isabstract, parameter_upper_bound, typename
end # module TypeUtils
end # module Compat
8 changes: 8 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1604,3 +1604,11 @@ end
# julia#20022
@test !Compat.isapprox(NaN, NaN)
@test Compat.isapprox(NaN, NaN, nans=true)

# julia#20006
abstract AbstractFoo20006
immutable ConcreteFoo20006{T<:Int} <: AbstractFoo20006
end
@test Compat.TypeUtils.isabstract(AbstractFoo20006)
@test Compat.TypeUtils.parameter_upper_bound(ConcreteFoo20006, 1) == Int
@test isa(Compat.TypeUtils.typename(Array), TypeName)