Skip to content

Why does one and all accept a variable number of arguments? Shouldn't they always require 2 arguments? #81

Description

@DevJac

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'

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions