An idea to provide Hints and Errors on Keywords#503
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #503 +/- ##
========================================
Coverage 99.78% 99.79%
========================================
Files 85 86 +1
Lines 9418 9640 +222
========================================
+ Hits 9398 9620 +222
Misses 20 20 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
… to probably handle those
|
A first small thing that works by now – even using two macros to define keywords for a single function and one collecting all it passes on is that a first function can now report its keywords and where they are passed on to in the end. |
…he remaining roadmap.
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
|
That's an interesting idea, though I would expect there to be an upstream library for that? So that each library that wants to do that doesn't make a separate function for keyword hints. For example REPL could offer keyword autocomplete based on such information in the future. BTW, I don't think julia> f(; a=10) = a
f (generic function with 1 method)
julia> m1 = methods(f)[1]
f(; a)
@ Main REPL[30]:1
julia> Base.kwarg_decl(m1)
1-element Vector{Symbol}:
:aThis would avoid interfering in function definitions. |
|
That is an awesome remark, since I was already thinking about how to combine methods of one function in the macro. nice was to avoid that! I think the main difference to classical keywords and their autocomplete is this nested-and-pass-on-kezwords. |
|
The other macro is also not necessary, one can just define a and use that in the accepted keywords function. |
|
Gave it a 5-minute try that took me 12, which might also just be me having defined that a bit strange in the keywords (have to check) – one can filter the It was still nice to learn a bit about macros, though I could now – with your idea for the one and mine for the other – omit both macros completely. Ok, the function you proposed is internal so it might break, but the code is really much much simpler now. Thanks for the idea – I will carefully check for the |
# Conflicts: # src/solvers/gradient_descent.jl # src/solvers/solver.jl
and fix a typo.
|
This now indeed works. I still have to go though solvers and maybe some constructors to see where they pass in And the mode (whether to warn or to error) I maybe want to set as a preference like the tutorial mode. So this small experiment is on a good way. |
|
That looks good 👍 . One minor note, I'd suggest changing the name |
|
good point, maybe something like |
|
it actually states the “current function” the keywords are meant for, so something along/similar to function (again not directly that ;)) would be fitting as well. Ah! |
|
I think both |
even found two typos of keywords in the old tests we ran.
…nd narrowed down with the new mode)
|
This is nearly done. It is already working fine.
The good thing: With this I found one small bug where we passed on an unnecessary keyword ( |
|
I checked the code that Makie uses for hints and it looks too involved for me to just take over. So I leave hints for a next PR and declare this PR finished. |
Co-authored-by: Mateusz Baran <mateuszbaran89@gmail.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
|
Everything else looks fine to me, so it's just the |
# Conflicts: # Changelog.md
Since a few things are nested and some keywords are “passed on”, e.g. to the debug or record factory,
currently there is no errors or warnings when a keyword is provided, that says “unused”.
There is also no easy way to tell which keywords could be passed e.g. to a certain solver,
This is a small experiment based on the approach from Makie.jl to see whether we can warn, error and/or give hints on keywords. Similarly, this should be usable to upfront determine all keywords that are accepted by a function … in the long run maybe even with a remark what/where it would be used internally for
🗺️
implement a Levenstein distance to find closest keywords if someone has a typo?