-
-
Notifications
You must be signed in to change notification settings - Fork 117
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
required keyword arguments #586
Merged
Merged
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a9da698
required keyword arguments working
c6c4be8
using @test_throws and UndeKeywordError now
51bb759
defining UndefKeywordError only if not yet in Base
35a2e6c
corrected UndefKeywordError message
01727dd
added README entry for required keyword arguments
b9465b2
Merge branch 'master' into master
timziebart e4dbb1d
Update README.md
timziebart af801ee
updated README with link
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,13 +25,31 @@ else | |
new_style_typealias(ex) = false | ||
end | ||
|
||
if !isdefined(Base, :UndefKeywordError) | ||
struct UndefKeywordError <: Exception | ||
kw | ||
end | ||
Base.showerror(io::IO, e::UndefKeywordError) = print(io, "keyword argument $(e.kw) not assigned") | ||
export UndefKeywordError | ||
end | ||
|
||
"Convert a functions symbol argument to the corresponding required keyword argument." | ||
function symbol2kw(sym::Symbol) | ||
Expr(:kw, sym, Expr(:call, throw, UndefKeywordError(sym))) | ||
end | ||
symbol2kw(arg) = arg | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't handle the case where the argument has a type. It should probably be: arg2kw(arg, sym) = Expr(:kw, arg, Expr(:call, throw, UndefKeywordError(sym)))
symbol2kw(arg::Symbol) = arg2kw(arg, arg)
symbol2kw(arg::Expr) = isexpr(arg, :(::)) ? arg2kw(arg, arg.args[1]) : arg
symbol2kw(arg) = arg There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
function _compat(ex::Expr) | ||
if ex.head === :call | ||
f = ex.args[1] | ||
if VERSION < v"0.6.0-dev.826" && length(ex.args) == 3 && # julia#18510 | ||
istopsymbol(withincurly(ex.args[1]), :Base, :Nullable) | ||
ex = Expr(:call, f, ex.args[2], Expr(:call, :(Compat._Nullable_field2), ex.args[3])) | ||
end | ||
if !isdefined(Base, :UndefKeywordError) && length(ex.args) > 1 && isexpr(ex.args[2], :parameters) | ||
params = ex.args[2] | ||
params.args = map(symbol2kw, params.args) | ||
end | ||
elseif ex.head === :curly | ||
f = ex.args[1] | ||
if VERSION < v"0.6.0-dev.2575" #20414 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Sorry, this should also print the exception type, so
as it does on Julia v0.7:
otherwise LGTM