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

Keywords unlocked part 1 #25395

Closed
wants to merge 55 commits into from
Closed

Keywords unlocked part 1 #25395

wants to merge 55 commits into from

Conversation

bramtayl
Copy link
Contributor

@bramtayl bramtayl commented Jan 4, 2018

Part 1 of part 1 of #20402 for the recommendations here #25188 (comment) less qrfact[!]

@bramtayl
Copy link
Contributor Author

bramtayl commented Jan 4, 2018

The example for optional arguments that uses parse needs to be updated. I find the unixisms of mkpath/mkdir/chown particularly ugly. Any help tracking down bugs/omissions would be appreciated.

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"))
Copy link
Sponsor Member

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)

Copy link
Sponsor Member

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.

Copy link
Sponsor Member

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.

@vtjnash
Copy link
Sponsor Member

vtjnash commented Jan 4, 2018

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)
Copy link
Member

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.

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 it's fine

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 personally like it too, but adding such a change in this PR is quite unfortunate because it really invites bikeshedding.

Copy link
Member

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.

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 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.

@JeffBezanson
Copy link
Sponsor Member

Seconded, this looks really good!

Copy link
Sponsor Member

@StefanKarpinski StefanKarpinski left a 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"))
Copy link
Sponsor Member

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.
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 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.

Copy link
Contributor Author

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))
Copy link
Sponsor Member

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.

Copy link
Member

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)
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 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.

Copy link
Contributor Author

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)
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 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.

@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)
Copy link
Sponsor Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, that sounds right

@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)
Copy link
Member

@nalimilan nalimilan Jan 5, 2018

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).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't understand...

Copy link
Member

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? :-)

Copy link
Sponsor Member

@mbauman mbauman Jan 6, 2018

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".

Copy link
Member

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!

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 would be fine with leaving reverse and reverse! as they are but I don't hate this either.

Copy link
Contributor Author

@bramtayl bramtayl Jan 6, 2018

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)

Copy link
Member

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).

Copy link
Contributor Author

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).

Copy link
Sponsor Member

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
Copy link
Member

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")
Copy link
Member

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))
Copy link
Member

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)
Copy link
Member

Choose a reason for hiding this comment

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

base = 0?

@bramtayl
Copy link
Contributor Author

Thanks everyone for the detailed comments! I fixed some more things.

""
```
"""
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) =
Copy link
Sponsor Member

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.

@JeffBezanson
Copy link
Sponsor Member

Rebasing this now should give faster build times.

""
```
"""
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) =
Copy link
Member

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?

Copy link
Contributor Author

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?

@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)
Copy link
Sponsor Member

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.

@bramtayl
Copy link
Contributor Author

I'm having a heck of a time debugging this while rebasing it at the same time

@JeffBezanson JeffBezanson mentioned this pull request Jan 20, 2018
@JeffBezanson
Copy link
Sponsor Member

Rebased and fixed some things: #25647

@bramtayl bramtayl closed this Jan 20, 2018
@bramtayl bramtayl mentioned this pull request Jan 22, 2018
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants