-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Rename srand to Random.seed! #28295
Rename srand to Random.seed! #28295
Conversation
stdlib/Random/src/deprecated.jl
Outdated
@@ -37,3 +37,6 @@ end | |||
|
|||
# PR #25668 | |||
@deprecate RandomDevice(unlimited::Bool) RandomDevice(; unlimited=unlimited) | |||
|
|||
# PR #Current | |||
@deprecate srand Random.seed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this should have a false
at the end to avoid exporting it, i.e.
@deprecate srand Random.seed false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also don't think this form is supported, I think you need to write a custom message with depwarn(...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No this works okay:
julia> module A
f() = 1
Base.@deprecate g A.f false
end
Main.A
julia> using .A
julia> A.g()
┌ Warning: `g` is deprecated, use `A.f` instead.
│ caller = top-level scope at none:0
└ @ Core none:0
1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, it is the other way around that does not work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will update it when I wake up tomorrow. In the meantime, does anyone know where the:
WARNING: importing deprecated binding Base.Random into Test. Base.Random is deprecated, run `using Random` instead ERROR: LoadError: error compiling top-level scope: deprecated binding: Base.Random WARNING: importing deprecated binding Base.Random into Test. Base.Random is deprecated, run `using Random` instead ERROR: LoadError: error compiling top-level scope: deprecated binding: Base.Random
and similar come from? As they seem to be the main culprit to the tests failing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In Test.jl you need using Random
instead of just using Random: ...
, which only imports specific items from Random (and not Random
itself).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. Thank you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you need using Random instead of just using Random: ...,
In this case, import Random
would be slightly better I think (imports only the binding Random
itself), as there is already a line using Random: ...
with explicit functions. But not worth changing again.
BTW, wouldn't it make sense that using Random: ...
also imports the Random
binding itself?
Welcome @MoonCoral! Wonderful first contribution! 🎉 |
This should be it. Tell me if I should squash the commits. |
NEWS.md
Outdated
@@ -1321,6 +1321,8 @@ Deprecated or removed | |||
|
|||
* `ndigits(n, b, [pad])` is deprecated in favor of `ndigits(n, base=b, pad=pad)` ([#27908]). | |||
|
|||
* `srand` is deprecated in favor of the unexported `Random.seed` ([#27726]). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the PR number should be mentioned here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue number is sufficient.
stdlib/Random/src/deprecated.jl
Outdated
@@ -37,3 +37,6 @@ end | |||
|
|||
# PR #25668 | |||
@deprecate RandomDevice(unlimited::Bool) RandomDevice(; unlimited=unlimited) | |||
|
|||
# PR #28295 | |||
@deprecate srand Random.seed false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a deprecation for guardsrand
-> guardseed
as well? It was introduced in the 0.7 cycle but I know some packages use it so could be good to add.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
guardsrand
was unexported in #27942, without deprecation...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't worry about squashing the commits, we can do that on merge. I have one outstanding comment, and other than that this looks great to me. Thanks for taking it on!
stdlib/Random/src/deprecated.jl
Outdated
@@ -37,3 +37,6 @@ end | |||
|
|||
# PR #25668 | |||
@deprecate RandomDevice(unlimited::Bool) RandomDevice(; unlimited=unlimited) | |||
|
|||
# PR #28295 | |||
@deprecate srand Random.seed false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was actually wrong about false
; that avoids exporting srand
, not Random.seed
. What you had originally was correct. Sorry about that!
I would like to use this renaming opportunity to suggest |
That's a good point; particularly if this is generalized to operate on an RNG, |
That went badly :( |
My apologies for my clumsy way to fix the merge conflict. I think all changes on my side should be fine now, so I'll refrain from touching git further and making things worse. |
In the diff here, many unrelated changes still appear, so I'm afraid you may have to touch git a bit more! |
I believe I managed to clean this up. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
state of the global RNG as it was before." | ||
function guardsrand(f::Function, r::AbstractRNG=GLOBAL_RNG) | ||
function guardseed(f::Function, r::AbstractRNG=GLOBAL_RNG) |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see that was already discussed. Never mind.
Closes #27726
Base.Random
when running tests.Random.seed(seed)
to be a common occurrence which could lead to confusion.(This is my first PR)