-
Notifications
You must be signed in to change notification settings - Fork 25
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
Piracy fix for kwcall #171
Conversation
Codecov Report
@@ Coverage Diff @@
## master #171 +/- ##
==========================================
+ Coverage 77.58% 77.61% +0.03%
==========================================
Files 11 11
Lines 736 746 +10
==========================================
+ Hits 571 579 +8
- Misses 165 167 +2
Flags with carried forward coverage won't be shown. Click here to find out more.
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
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.
Unfortunately it fails in all older Julia versions (<=1.8)
Works now in julia 1.5. Let's see if CI succeeds for older version as well. It needed way much more of wiggling around with internals than I expected or wanted. |
@@ -157,3 +157,22 @@ function format_diff( | |||
$text_b | |||
""" | |||
end | |||
|
|||
function is_kwcall(signature::DataType) |
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.
Perhaps it would make sense to use https://github.com/FluxML/MacroTools.jl or https://github.com/invenia/ExprTools.jl instead of rolling this on our own?
julia> ex = :(
function Base.f(x::T, y::T; z::Bool=false) where T
x + y
end
);
julia> ExprTools.splitdef(ex)
Dict{Symbol, Any} with 6 entries:
:args => Any[:(x::T), :(y::T)]
:body => quote…
:kwargs => Any[:($(Expr(:kw, :(z::Bool), false)))]
:head => :function
:whereparams => Any[:T]
:name => :(Base.f)
julia> MacroTools.splitdef(ex)
Dict{Symbol, Any} with 5 entries:
:name => :(Base.f)
:args => Any[:(x::T), :(y::T)]
:kwargs => Any[:($(Expr(:kw, :(z::Bool), false)))]
:body => quote…
:whereparams => (:T,)
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, but of course that's for expressions, not methods/signatures, so it might not be helpful.
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, these ones unfortunately do not offer what we need here. I couldn't find any good way to test this in other packages. Most just ignore old julia versions, where Core.kwcall
doesn't exist, or use some regex with the function name of the kwsorter. The first is not an option here (unless we drop support for julia-pre-1.9, or have different semantics for the tests depending on the julia version). The second option relies on weirder internals, where we won't get good error messages in future changes (as regexes and strings just tell "no", not fail with some type error etc.). Thus, I think the current proposal here is the best we can currently do. I already added a try-catch with some additional debug information for people to open issues here.
The implementation of #131 does not work properly if the function in question has a kwarg (see the change in the test file here for an example).
This fixes that by ignoring the first two elements of the signature of a
kwcall
(first istypeof(kwcall)
and second isAny
, the NamedTuple of all kwargs to be applied), and then considering the third to be "the original function" and everything behind that as positional arguments.