WIP: raise ValueError if param.depends is used without arguments or without defining dependencies
To raise an error in these cases where the depends decorator is used either without arguments or without providing any dependencies (same on methods on Parameterized classes).
@param.depends
def foo():
pass
# ValueError: The depends decorator on the callable 'foo' cannot be used without arguments.
@param.depends()
def foo():
pass
# ValueError: The depends decorator on the callable 'foo' require dependencies to be defined.
WIP because as such the following would raise an error (since internally Panel uses the depends decorator when it binds a callable) while the approach retained is to warn in this case (https://github.com/holoviz/panel/pull/3545).
import panel
def foo(val):
return val
pn.panel(pn.bind(foo, val='bob'))
Emitting a warning instead of raising an error when no dependencies are defined may be a better idea (that Panel could silence).
Codecov Report
Merging #631 (5877097) into master (d960230) will increase coverage by
0.03%. The diff coverage is88.37%.
@@ Coverage Diff @@
## master #631 +/- ##
==========================================
+ Coverage 82.91% 82.94% +0.03%
==========================================
Files 5 5
Lines 3073 3079 +6
==========================================
+ Hits 2548 2554 +6
Misses 525 525
| Impacted Files | Coverage Δ | |
|---|---|---|
| param/parameterized.py | 83.39% <88.37%> (+0.06%) |
:arrow_up: |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing dataPowered by Codecov. Last update d960230...5877097. Read the comment docs.
I don't think this is correct, @param.depends() is documented and the behavior is well defined in the user guide:
Conversely, if you want to declare that a given method does not depend on any parameters at all, you can use @param.depends().
So I'm perfectly happy to disallow param.depends without calling it but we should not disallow param.depends().
I'm not sure what the interaction with Panel is, but I agree with @philippjfr that depends() is not an error but depends is.
I no longer see much value in the changes I made in this PR. As stated above@param.depends() is valid. @param.depends could either raise an error or be accepted and made equivalent to @param.depends(). As I don't want to decide that now and this is definitely super low priority, I'm just going to close this. Let's revisit when this comes up again, if ever!