jw3126 / argcheck.jl Goto Github PK
View Code? Open in Web Editor NEWPackage for checking function arguments
License: Other
Package for checking function arguments
License: Other
Recent changes deprecated then disallowed
@argcheck condition "message"
and now require explicit specification of an error, eg
@argcheck condition ArgumentError("message")
I think that making things explicit is good design, and I like that I can specify other errors when checking arguments (eg BoundsError
, etc), but I still think that ArgumentError
is a useful default — after all, the name of the package is ArgCheck.
So I am asking that you please consider allowing the first code snippet above again, making it equivalent to the second. AFAICT the macro should be able to check the AST for a <: AbstractString
.
As @MrVPlusOne suggested on discourse it probably makes sense to merge this package with SmartAsserts.jl. I think the best option would be to copy the clever enable/disable mechanism to ArgCheck.jl. What do you think @MrVPlusOne ?
IIUC, the effect of @skipargcheck
is dynamically scoped:
using OptionalArgChecks
@noinline f(x) = @argcheck x > 0
@noinline g(x) = f(x)
h(x) = @skipargcheck g(x)
h(-1) # no error
That is to say, @skipargcheck
is effective no matter how far away the function using @argcheck
is in the call chain. This is very different from @inbounds
as it works only with inlined calls (i.e., @inbounds
scoping is more-or-less lexical). On the other hand, there is no way for a callee to reliably throw an exception when using @argcheck
. I understand that exception is not used as "output" in Julia most of the time. However, you can find in some places exception type is crucial (e.g., NLsolve.jl, Optim.jl).
I do think OptionalArgChecks.jl is a very interesting approach to optional error handling. But, if my understanding of its scope is correct, I think it's better to have a warning on its scoping rule. Ideally, I think it's better to have a separate macro for enabling OptionalArgChecks.jl.
This issue is used to trigger TagBot; feel free to unsubscribe.
If you haven't already, you should update your TagBot.yml
to include issue comment triggers.
Please see this post on Discourse for instructions and more details.
If you'd like for me to do this for you, comment TagBot fix
on this issue.
I'll open a PR within a few hours, please be patient!
julia> @argcheck false DomainError
ERROR: MethodError: Cannot `convert` an object of type String to an object of type
DomainError
This may have arisen from a call to the constructor DomainError(...),
since type constructors fall back to convert methods.
in build_error(::Bool, ::Type{DomainError}) at /home/tamas/.julia/v0.5/ArgCheck/sr
c/ArgCheck.jl:7
The tag name "v0.5" is not of the appropriate SemVer form (vX.Y.Z).
cc: @jw3126
using ArgCheck
x=1
y=2
@argcheck isapprox(x,y; atol=0.1)
# ArgumentError: isapprox(x, y; atol=0.1) must hold.
Error message should give the values of x,y
function f(x)
@argcheck x ≥ 0
x
end
julia> f(-2)
ERROR: ArgumentError: x ≥ 0 must hold. Got
≥ => >=
x => -2
Notice the line with the ≥ => >=
.
This seems to be an issue with the unicode greater-than-or-equal symbol. Indeed, if I define instead
julia> function f(x)
@argcheck x >= 0
x
end
The error prints fine
julia> f(-2)
ERROR: ArgumentError: x >= 0 must hold. Got
x => -2
using ArgCheck
A = Int
B = Float64
@argcheck A <: B
ArgumentError: A <: B must hold.
This
function f(a)
@check !startswith(a,"o")
end
f("o")
causes this error
ERROR: CheckError: !(startswith(a, "o")) must hold. Got
startswith(a, "o") => true
It would be nice if it could display the contents of a
@JuliaRegistrator register()
julia> using ArgCheck
julia> x = y = z = 1
1
julia> x == y == z
true
julia> @argcheck x == y == z
ERROR: MethodError: objects of type Int64 are not callable
Readme/doc improvement suggestion: explain why @argcheck
is "better" than @assert
for method arguments. Thanks!
I came here via here.
@JuliaRegistrator register()
julia> using ArgCheck
julia> [1] .== [2]
1-element BitVector:
0
julia> @check [1] .== [2]
ERROR: UndefVarError: `.==` not defined
Stacktrace:
[1] top-level scope
@ REPL[111]:1
Here, the check I wrote is bad since it doesn't return a bool, but the error message is confusing.
The version was bumped to 2.0 recently yet I am unsure what the breaking change was (the label check?).
Some packages keep a CHANGELOG.md with short summaries, please consider doing this.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.