1. 03 Oct, 2020 1 commit
  2. 05 Sep, 2020 1 commit
    • Henry Schreiner's avatar
      feat: py::pos_only (#2459) · 0dbda6e8
      Henry Schreiner authored
      * feat: py::pos_only
      
      * fix: review points from @YannickJadoul
      
      * fix: review points from @bstaletic
      
      * refactor: kwonly -> kw_only
      0dbda6e8
  3. 24 Jul, 2020 1 commit
  4. 26 Apr, 2020 2 commits
    • Sebastian Koslowski's avatar
      rename args_kw_only to kwonly · a86ac538
      Sebastian Koslowski authored
      a86ac538
    • Jason Rhinelander's avatar
      Support keyword-only arguments · be0d8045
      Jason Rhinelander authored
      This adds support for a `py::args_kw_only()` annotation that can be
      specified between `py::arg` annotations to indicate that any following
      arguments are keyword-only.  This allows you to write:
      
          m.def("f", [](int a, int b) { /* ... */ },
                py::arg("a"), py::args_kw_only(), py::arg("b"));
      
      and have it work like Python 3's:
      
          def f(a, *, b):
              # ...
      
      with respect to how `a` and `b` arguments are accepted (that is, `a` can
      be positional or by keyword; `b` can only be specified by keyword).
      be0d8045
  5. 06 Apr, 2019 1 commit
    • Henry Schreiner's avatar
      CI fixes (#1744) · ae951ca0
      Henry Schreiner authored
      * Fix warning that not including a cmake source or build dir will be a fatal error (it is now on newest CMakes)
          * Fixes appveyor
      * Travis uses CMake 3.9 for more than a year now
      * Travis dropped sudo: false in December
      * Dropping Sphinx 2
      - clang7: Suppress self-assign warnings; fix missing virtual dtors
      - pypy:
        - Keep old version (newer stuff breaks)
        - Pin packages to extra index for speed
      - travis:
        - Make docker explicit; remove docker if not needed
        - Make commands more verbose (for debugging / repro)
        - Make Ubuntu dist explicit per job
      - Fix Windows
      - Add names to travis
      ae951ca0
  6. 23 Dec, 2017 1 commit
  7. 05 Aug, 2017 1 commit
    • Jason Rhinelander's avatar
      Update all remaining tests to new test styles · 391c7544
      Jason Rhinelander authored
      This udpates all the remaining tests to the new test suite code and
      comment styles started in #898.  For the most part, the test coverage
      here is unchanged, with a few minor exceptions as noted below.
      
      - test_constants_and_functions: this adds more overload tests with
        overloads with different number of arguments for more comprehensive
        overload_cast testing.  The test style conversion broke the overload
        tests under MSVC 2015, prompting the additional tests while looking
        for a workaround.
      
      - test_eigen: this dropped the unused functions `get_cm_corners` and
        `get_cm_corners_const`--these same tests were duplicates of the same
        things provided (and used) via ReturnTester methods.
      
      - test_opaque_types: this test had a hidden dependence on ExampleMandA
        which is now fixed by using the global UserType which suffices for the
        relevant test.
      
      - test_methods_and_attributes: this required some additions to UserType
        to make it usable as a replacement for the test's previous SimpleType:
        UserType gained a value mutator, and the `value` property is not
        mutable (it was previously readonly).  Some overload tests were also
        added to better test overload_cast (as described above).
      
      - test_numpy_array: removed the untemplated mutate_data/mutate_data_t:
        the templated versions with an empty parameter pack expand to the same
        thing.
      
      - test_stl: this was already mostly in the new style; this just tweaks
        things a bit, localizing a class, and adding some missing
        `// test_whatever` comments.
      
      - test_virtual_functions: like `test_stl`, this was mostly in the new
        test style already, but needed some `// test_whatever` comments.
        This commit also moves the inherited virtual example code to the end
        of the file, after the main set of tests (since it is less important
        than the other tests, and rather length); it also got renamed to
        `test_inherited_virtuals` (from `test_inheriting_repeat`) because it
        tests both inherited virtual approaches, not just the repeat approach.
      391c7544
  8. 31 Jan, 2017 1 commit
    • 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
  9. 06 Sep, 2016 3 commits
    • Dean Moldovan's avatar
      Remove superseded handle::operator() overloads · 16db1bfb
      Dean Moldovan authored
      The variadic handle::operator() offers the same functionality as well
      as mixed positional, keyword, * and ** arguments. The tests are also
      superseded by the ones in `test_callbacks`.
      16db1bfb
    • Dean Moldovan's avatar
      Support keyword arguments and generalized unpacking in C++ · c743e1b1
      Dean Moldovan authored
      A Python function can be called with the syntax:
      ```python
      foo(a1, a2, *args, ka=1, kb=2, **kwargs)
      ```
      This commit adds support for the equivalent syntax in C++:
      ```c++
      foo(a1, a2, *args, "ka"_a=1, "kb"_a=2, **kwargs)
      ```
      
      In addition, generalized unpacking is implemented, as per PEP 448,
      which allows calls with multiple * and ** unpacking:
      ```python
      bar(*args1, 99, *args2, 101, **kwargs1, kz=200, **kwargs2)
      ```
      and
      ```c++
      bar(*args1, 99, *args2, 101, **kwargs1, "kz"_a=200, **kwargs2)
      ```
      c743e1b1
    • Wenzel Jakob's avatar
      minor doc & style fixes · fe34241e
      Wenzel Jakob authored
      fe34241e
  10. 03 Sep, 2016 1 commit
    • Jason Rhinelander's avatar
      Make test initialization self-registering · 52f4be89
      Jason Rhinelander authored
      Adding or removing tests is a little bit cumbersome currently: the test
      needs to be added to CMakeLists.txt, the init function needs to be
      predeclared in pybind11_tests.cpp, then called in the plugin
      initialization.  While this isn't a big deal for tests that are being
      committed, it's more of a hassle when working on some new feature or
      test code for which I temporarily only care about building and linking
      the test being worked on rather than the entire test suite.
      
      This commit changes tests to self-register their initialization by
      having each test initialize a local object (which stores the
      initialization function in a static variable).  This makes changing the
      set of tests being build easy: one only needs to add or comment out
      test names in tests/CMakeLists.txt.
      
      A couple other minor changes that go along with this:
      
      - test_eigen.cpp is now included in the test list, then removed if eigen
        isn't available.  This lets you disable the eigen tests by commenting
        it out, just like all the other tests, but keeps the build working
        without eigen eigen isn't available.  (Also, if it's commented out, we
        don't even bother looking for and reporting the building with/without
        eigen status message).
      
      - pytest is now invoked with all the built test names (with .cpp changed
        to .py) so that it doesn't try to run tests that weren't built.
      52f4be89
  11. 19 Aug, 2016 3 commits
    • Dean Moldovan's avatar
      99dbdc16
    • Dean Moldovan's avatar
      Simplify tests by replacing output capture with asserts where possible · 665e8804
      Dean Moldovan authored
      The C++ part of the test code is modified to achieve this. As a result,
      this kind of test:
      
      ```python
      with capture:
          kw_func1(5, y=10)
      assert capture == "kw_func(x=5, y=10)"
      ```
      
      can be replaced with a simple:
      
      `assert kw_func1(5, y=10) == "x=5, y=10"`
      665e8804
    • Dean Moldovan's avatar
      Port tests to pytest · a0c1ccf0
      Dean Moldovan authored
      Use simple asserts and pytest's powerful introspection to make testing
      simpler. This merges the old .py/.ref file pairs into simple .py files
      where the expected values are right next to the code being tested.
      
      This commit does not touch the C++ part of the code and replicates the
      Python tests exactly like the old .ref-file-based approach.
      a0c1ccf0
  12. 04 Aug, 2016 1 commit
    • Dean Moldovan's avatar
      Use generic arg names for functions without explicitly named arguments · ecced6c5
      Dean Moldovan authored
      Example signatures (old => new):
        foo(int) => foo(arg0: int)
        bar(Object, int) => bar(self: Object, arg0: int)
      
      The change makes the signatures uniform for named and unnamed arguments
      and it helps static analysis tools reconstruct function signatures from
      docstrings.
      
      This also tweaks the signature whitespace style to better conform to
      PEP 8 for annotations and default arguments:
        " : " => ": "
        " = " => "="
      ecced6c5
  13. 18 Jul, 2016 1 commit
    • Jason Rhinelander's avatar
      Rename examples files, as per #288 · b3f3d79f
      Jason Rhinelander authored
      This renames example files from `exampleN` to `example-description`.
      
      Specifically, the following renaming is applied:
      
      example1 -> example-methods-and-attributes
      example2 -> example-python-types
      example3 -> example-operator-overloading
      example4 -> example-constants-and-functions
      example5 -> example-callbacks (*)
      example6 -> example-sequence-and-iterators
      example7 -> example-buffers
      example8 -> example-custom-ref-counting
      example9 -> example-modules
      example10 -> example-numpy-vectorize
      example11 -> example-arg-keywords-and-defaults
      example12 -> example-virtual-functions
      example13 -> example-keep-alive
      example14 -> example-opaque-types
      example15 -> example-pickling
      example16 -> example-inheritance
      example17 -> example-stl-binders
      example18 -> example-eval
      example19 -> example-custom-exceptions
      
      * the inheritance parts of example5 are moved into example-inheritance
      (previously example16), and the remainder is left as example-callbacks.
      
      This commit also renames the internal variables ("Example1",
      "Example2", "Example4", etc.) into non-numeric names ("ExampleMandA",
      "ExamplePythonTypes", "ExampleWithEnum", etc.) to correspond to the
      file renaming.
      
      The order of tests is preserved, but this can easily be changed if
      there is some more natural ordering by updating the list in
      examples/CMakeLists.txt.
      b3f3d79f
  14. 15 Jun, 2016 1 commit
  15. 03 Jun, 2016 1 commit
  16. 25 May, 2016 1 commit
    • Yung-Yu Chen's avatar
      pybind11::args should have been derived from tuple · 114bfeb7
      Yung-Yu Chen authored
      args was derived from list, but cpp_function::dispatcher sends a tuple to it->impl (line #346 and #392 in pybind11.h).  As a result args::size() and args::operator[] don't work at all.  On my mac args::size() returns -1.  Making args a subclass of tuple fixes it.
      114bfeb7
  17. 15 May, 2016 1 commit
  18. 08 May, 2016 1 commit
  19. 18 Apr, 2016 1 commit
  20. 17 Jan, 2016 2 commits
  21. 29 Jul, 2015 1 commit