"vscode:/vscode.git/clone" did not exist on "fd61f5038eac57a96f0d2dbcf2a4f125bc91f1ca"
  • Jason Rhinelander's avatar
    Add support for positional args with args/kwargs · 2686da83
    Jason Rhinelander authored
    This commit rewrites the function dispatcher code to support mixing
    regular arguments with py::args/py::kwargs arguments.  It also
    simplifies the argument loader noticeably as it no longer has to worry
    about args/kwargs: all of that is now sorted out in the dispatcher,
    which now simply appends a tuple/dict if the function takes
    py::args/py::kwargs, then passes all the arguments in a vector.
    
    When the argument loader hit a py::args or py::kwargs, it doesn't do
    anything special: it just calls the appropriate type_caster just like it
    does for any other argument (thus removing the previous special cases
    for args/kwargs).
    
    Switching to passing arguments in a single std::vector instead of a pair
    of tuples also makes things simpler, both in the dispatch and the
    argument_loader: since this argument list is strictly pybind-internal
    (i.e. it never goes to Python) we have no particular reason to use a
    Python tuple here.
    
    Some (intentional) restrictions:
    - you may not bind a function that has args/kwargs somewhere other than
      the end (this somewhat matches Python, and keeps the dispatch code a
      little cleaner by being able to not worry about where to inject the
      args/kwargs in the argument list).
    - If you specify an argument both positionally and via a keyword
      argument, you get a TypeError alerting you to this (as you do in
      Python).
    2686da83
test_kwargs_and_defaults.cpp 2.96 KB