pyjq
pyjq copied to clipboard
Why does `one` and `all` accept a variable number of arguments? Shouldn't they always require 2 arguments?
If I do something like pyjq.one('.foo')
I do not get an error, even though I did not provide a second argument. I would expect this to raise an exception rather than silently return None
.
Is there any use case where a user might want to call pyjq.one('.foo')
without a second argument? Why not just replace this expression with None
since that will always be the result?
If someone writes pyjq.all('.foo')
or similar, they most likely make a mistake and an exception should be raised that makes this mistake clear. The usual TypeError
for the wrong number of arguments would be good. This will make the mistake clear and save the users time debugging. I would like to see a standard TypeError
like below when I forget the second argument.
In [1]: def foo(a, b):
...: return a + b
...:
In [2]: foo(1)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[2], line 1
----> 1 foo(1)
TypeError: foo() missing 1 required positional argument: 'b'