-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Keywords unlocked part 1 #25395
Keywords unlocked part 1 #25395
Conversation
This reverts commit 377fe70.
The example for optional arguments that uses |
base/file.jl
Outdated
@@ -81,37 +81,40 @@ Temporarily changes the current working directory and applies function `f` befor | |||
""" | |||
cd(f::Function) = cd(f, homedir()) | |||
|
|||
checkmode(mode::Unsigned) = mode | |||
checkmode(mode::Signed) = throw(ArgumentError("mode must be an unsigned integer; try 0o$mode")) |
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.
this seems unnecessarily strict. maybe just drop the error? (convert will check InexectError anyways)
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.
It also shouldn't suggest 0o
this way because mode
won't be printed in octal.
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.
It probably makes sense to check that a mode only has three octal digits, but otherwise I think that any integer value between 0
and 511 = 0o777
should be acceptable, regardless of type.
This is looking quite nice! |
@@ -68,7 +68,7 @@ unsafe_convert(::Type{Ptr{T}}, a::AbstractArray{T}) where {T} = error("conversio | |||
|
|||
# unsafe pointer to array conversions | |||
""" | |||
unsafe_wrap(Array, pointer::Ptr{T}, dims, own=false) | |||
unsafe_wrap(Array, pointer::Ptr{T}, dims; own = 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.
Please don't change the whitespace around =
for everything. Omitting it for keyword arguments is standard style in Base.
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 think it's fine
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 personally like it too, but adding such a change in this PR is quite unfortunate because it really invites bikeshedding.
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.
Yes, if we could keep this to implementation only, that would be nice.
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 think it's fine. It would have been preferable to do this without style changes and make style changes separately, but @bramtayl has been kind enough to do a large amount of tedious but important work here, so rather than asking him to do more, let's just focus on getting the meaningful content correct here and we can make our coding styles consistent to our hearts content after 1.0 is out.
Seconded, this looks really good! |
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.
This is a really pleasant change! Thanks so much for taking the time and effort to go through this so thoroughly. I've left a few comments which should be addressed (the Timer
/ repeat
one is the most significant) but aside from those issues, this looks great to me.
base/file.jl
Outdated
@@ -81,37 +81,40 @@ Temporarily changes the current working directory and applies function `f` befor | |||
""" | |||
cd(f::Function) = cd(f, homedir()) | |||
|
|||
checkmode(mode::Unsigned) = mode | |||
checkmode(mode::Signed) = throw(ArgumentError("mode must be an unsigned integer; try 0o$mode")) |
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.
It probably makes sense to check that a mode only has three octal digits, but otherwise I think that any integer value between 0
and 511 = 0o777
should be acceptable, regardless of type.
base/file.jl
Outdated
@@ -616,12 +616,12 @@ function chmod(path::AbstractString, mode::Integer; recursive::Bool=false) | |||
end | |||
|
|||
""" | |||
chown(path::AbstractString, owner::Integer, group::Integer=-1) | |||
chown(path::AbstractString, owner::Integer; group::Integer = -1) | |||
|
|||
Change the owner and/or group of `path` to `owner` and/or `group`. If the value entered for `owner` or `group` | |||
is `-1` the corresponding ID will not change. Only integer `owner`s and `group`s are currently supported. |
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 wonder if we should change this to use nothing
as the sentinel value instead. We would have to translate nothing
to -1 for libuv, but using -1 just because libuv does seems to be exposing an implementation detail. So the behavior here would be to error on negative values, replace nothing
with -1
, and pass positive integers through unchanged. Not a big deal, just a thought now that we use nothing
commonly as a sentinel.
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.
That makes more sense to me too.
base/loading.jl
Outdated
@@ -88,7 +88,7 @@ macro return_if_file(path) | |||
end | |||
|
|||
function find_package(name::String) | |||
endswith(name, ".jl") && (name = chop(name, 0, 3)) | |||
endswith(name, ".jl") && (name = chop(name, head = 0, tail = 3)) |
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.
Here you can drop the head = 0
since that's the default. It was only needed for the positional form because the head
argument is first.
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.
^ bump
base/event.jl
Outdated
@@ -341,7 +341,7 @@ end | |||
## timer-based notifications | |||
|
|||
""" | |||
Timer(delay, repeat=0) | |||
Timer(delay; repeat = 0) |
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 think the repeat
argument to Timer
is kind of confusingly named – it seems like it gives a repeat count, but instead gives the interval of repetition. Perhaps it should be called interval
instead with the same behavior? I.e. if given the timer repeats with the given interval, if not given the timer does not repeat. We might in the future want to add a repeat
keyword argument which controls how many times a timer repeats. Of course, we might want to call such an argument count
instead, but you see my point.
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 confused by repeat
at first too. I'll change it to interval
.
@@ -68,7 +68,7 @@ unsafe_convert(::Type{Ptr{T}}, a::AbstractArray{T}) where {T} = error("conversio | |||
|
|||
# unsafe pointer to array conversions | |||
""" | |||
unsafe_wrap(Array, pointer::Ptr{T}, dims, own=false) | |||
unsafe_wrap(Array, pointer::Ptr{T}, dims; own = 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 think it's fine. It would have been preferable to do this without style changes and make style changes separately, but @bramtayl has been kind enough to do a large amount of tedious but important work here, so rather than asking him to do more, let's just focus on getting the meaningful content correct here and we can make our coding styles consistent to our hearts content after 1.0 is out.
base/deprecated.jl
Outdated
@deprecate chop(s, head) chop(s, head = head) | ||
@deprecate chop(s, head, tail) chop(s, head = head, tail = tail) | ||
@deprecate tryparse(T, s, base) tryparse(T, s, base = base) | ||
@deprecate parse(T, s, base) parse(T, s, base = base) |
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.
Should these have T::Type{<:Integer}
or something like that?
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.
Sure, that sounds right
base/deprecated.jl
Outdated
@deprecate reverse!(v, start) reverse!(v, start = start) | ||
@deprecate reverse!(v, start, stop) reverse!(v, start = start, stop = stop) | ||
@deprecate reverse(v, start) reverse(v, start = start) | ||
@deprecate reverse(v, start, stop) reverse(v, start = start, stop = stop) |
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 wonder whether reverse
should be kept as is. There's a pattern of passing start and stop indices as keyword positional arguments, e.g. with SubString
and copy!
. I prefer using keyword arguments for arguments which are of a "different nature" than other arguments (typically, options vs. data).
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 don't understand...
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.
What don't you understand exactly? :-)
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.
@nalimilan did you typo "There's a pattern of passing start and stop indices as keyword arguments"? I think you meant "keyword positional arguments".
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.
Ah, thanks, that explains it!
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 would be fine with leaving reverse
and reverse!
as they are but I don't hate this either.
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'm not super passionate either but its worth noting that if they are both optional arguments then you wouldn't be able to do something like reverse(v, stop = stop)
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.
Yeah, you would have to pass start(v)
before the stop index. But this remark also applies to functions with similar arguments, so I think we should keep them consistent (either way).
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.
Do you have a list of such functions? It might be just worth changing all of them (if they are exported).
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.
How about dropping that part for now so that we can get this merged now?
base/event.jl
Outdated
|
||
Create a timer that wakes up tasks waiting for it (by calling [`wait`](@ref) on the timer object). | ||
|
||
Waiting tasks are woken after an intial delay of `delay` seconds, and then repeating with the given | ||
`repeat` interval in seconds. If `repeat` is equal to `0`, the timer is only triggered once. When | ||
`interval` in seconds. If `repeat` is equal to `0`, the timer is only triggered once. When |
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.
`repeat`
-> `interval`
base/file.jl
Outdated
@@ -81,37 +81,44 @@ Temporarily changes the current working directory and applies function `f` befor | |||
""" | |||
cd(f::Function) = cd(f, homedir()) | |||
|
|||
function checkmode(mode::Int) = | |||
if !(0 <= mode <= 511) | |||
ArgumentError("Mode must be between 0 and 511 = 0o777") |
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.
throw(...)
?
base/loading.jl
Outdated
@@ -88,7 +88,7 @@ macro return_if_file(path) | |||
end | |||
|
|||
function find_package(name::String) | |||
endswith(name, ".jl") && (name = chop(name, 0, 3)) | |||
endswith(name, ".jl") && (name = chop(name, head = 0, tail = 3)) |
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.
^ bump
base/parse.jl
Outdated
return base | ||
end | ||
throw(ArgumentError("invalid base: base must be 2 ≤ base ≤ 62, got $base")) | ||
end | ||
|
||
""" | ||
tryparse(type, str, [base]) | ||
tryparse(type, str, base = base) |
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.
base = 0
?
Thanks everyone for the detailed comments! I fixed some more things. |
base/strings/util.jl
Outdated
"" | ||
``` | ||
""" | ||
chop(s::AbstractString) = SubString(s, start(s), prevind(s, endof(s))) | ||
chop(s::AbstractString, head::Integer, tail::Integer) = | ||
chop(s::AbstractString; head::Integer, tail::Integer) = |
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.
Forgot the default values here.
Rebasing this now should give faster build times. |
base/strings/util.jl
Outdated
"" | ||
``` | ||
""" | ||
chop(s::AbstractString) = SubString(s, start(s), prevind(s, endof(s))) | ||
chop(s::AbstractString, head::Integer, tail::Integer) = | ||
chop(s::AbstractString; head::Integer = 0, tail::Integer = 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.
This will overwrite the method on the line above, right?
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 shoot I messed this up. If I understand correctly start(s)
and prevind(s, endof(s))
are supposed to be optimizations for the default cause. If I'm understanding correctly constant propagation is not working right now for keyword arguments. So maybe I should comment out the first method and add back in the optimization if that ever happens?
base/deprecated.jl
Outdated
@deprecate parse(T::Type{<:Integer}, s, base) parse(T, s, base = base) | ||
@deprecate mkdir(path, mode) mkdir(path, mode = mode) | ||
import Filesystem.mkpath | ||
@deprecate mkpath(path, mode) mkpath(path, mode = mode) |
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.
Can wrap this line in @eval Filesystem begin ... end
instead.
I'm having a heck of a time debugging this while rebasing it at the same time |
Rebased and fixed some things: #25647 |
Part 1 of part 1 of #20402 for the recommendations here #25188 (comment) less qrfact[!]