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

deprecate unintended methods of zeros, ones #21183

Merged
merged 5 commits into from
Apr 4, 2017
Merged
Show file tree
Hide file tree
Changes from 4 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
8 changes: 8 additions & 0 deletions base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,14 @@ for (fname, felt) in ((:zeros,:zero), (:ones,:one))
$fname(dims::Tuple) = ($fname)(Float64, dims)
$fname(T::Type, dims...) = $fname(T, dims)
$fname(dims...) = $fname(dims)

# #19635
function ($fname){T}(::Type{T}, arr::Array{T})
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be moved to base/deprecated.jl. That way it will be deleted when we delete the 0.6 deprecations (which happens late in the next release cycle); we might not notice/remember to delete it if it's in array.jl.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One also needs to change a @test_throws when this is deleted. Thats why I put it here and not in deprecated.jl. You are still in favor of deprecated.jl?

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, that is a bit tricky. Still, I think I'd favor moving this to deprecated.jl and then writing the test like this:

@test_throws ErrorException error("some error") # TODO: change this to MethodError when 0.6 deprecations are deleted

msg = string("`", $fname, "{T}(::Type{T}, arr::Array{T})` is deprecated, use ",
"`", $fname , "(T, size(arr))` instead. ",
)
error(msg)
end
end
end

Expand Down
6 changes: 6 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1298,6 +1298,12 @@ end
end
end

# #19635
for f in (:ones, :zeros)
@eval @deprecate ($f)(T::Type, arr) ($f)(T, size(arr))
@eval ($f)(T::Type, i::Integer) = ($f)(T, (i,))
end

# END 0.6 deprecations

# BEGIN 1.0 deprecations
Expand Down
11 changes: 5 additions & 6 deletions test/arrayops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2054,12 +2054,11 @@ end
zs = zeros(SparseMatrixCSC([1 2; 3 4]), Complex{Float64}, (2,3))
test_zeros(zs, SparseMatrixCSC{Complex{Float64}}, (2, 3))

@testset "#19265" begin
@test_throws MethodError zeros(Float64, [1.])
x = [1.]
test_zeros(zeros(x, Float64), Vector{Float64}, (1,))
@test x == [1.]
end
# #19265"
@test_throws ErrorException zeros(Float64, [1.])
x = [1.]
test_zeros(zeros(x, Float64), Vector{Float64}, (1,))
@test x == [1.]

# exotic indexing
oarr = zeros(randn(3), UInt16, 1:3, -1:0)
Expand Down