Commit Graph

423 Commits

Author SHA1 Message Date
Dustin Spicuzza
1b0bf352fa
Throw TypeError when subclasses forget to call __init__ (#2152)
- Fixes #2103
2020-07-07 12:04:06 +02:00
Yannick Jadoul
d54d6d8c61
Adding pybind11::cast overload for rvalue references (#1260)
* Adding pybind11::cast overload for rvalue references
2020-07-01 01:53:09 +02:00
B Krishna Chaitanya
714424387f Refactor: Extract Custom Type Casts related tests 2020-07-01 00:07:49 +02:00
fatvlady
8c06b95492 Fix compile error on GCC4.8 2020-06-29 21:01:20 +02:00
fatvlady
a3daf87d45 Add failing optional test 2020-06-29 21:01:20 +02:00
Ashley Whetter
8e85fadff2 Render py::none as None in docstrings
Closes #2270
2020-06-29 11:48:44 +02:00
Sergei Izmailov
ab323e04f3 Test py::iterable/py::iterator representation in docstrings 2020-06-10 13:36:31 +02:00
Sergei Izmailov
4f1531c454 Render py::int_ as int in docstrings 2020-06-10 13:36:31 +02:00
Sergei Izmailov
22b2504080 Render full numpy numeric names (e.g. numpy.int32) 2020-06-10 13:36:31 +02:00
Clemens Sielaff
63df87fa49
Add lvalue ref-qualified cpp_function constructors (#2213)
* added overload for l-value ref-qualified methods

* Added test.
Before, the code would have failed to build.
2020-06-10 13:35:10 +02:00
Eric Cousineau
4e3d9fea74 operators: Explicitly expose py::hash(py::self)
Add warnings about extending STL
2020-05-31 07:03:01 +02:00
Eric Cousineau
5309573005 operators: Move hash check to before mutations, tweak whitespace 2020-05-31 07:03:01 +02:00
Eric Cousineau
2c30e0a118
cmake: Expose PYBIND11_TEST_OVERRIDE (#2218)
Primarily for the ccmake curses GUI
2020-05-31 07:00:55 +02:00
Henry Schreiner
a38e5331d7
Fix CI, prepare test on Python 3.9 beta (#2233)
* Test on Python 3.9 beta
* Pin Sphinx
* Newer version of PyPy
2020-05-31 06:29:30 +02:00
Nicholas Musolino
02c83dba0f Propagate exceptions in sequence::size() (#2076) 2020-04-26 18:40:52 +02:00
Sebastian Koslowski
a86ac538f5 rename args_kw_only to kwonly 2020-04-26 18:07:51 +02:00
Jason Rhinelander
be0d804523 Support keyword-only arguments
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).
2020-04-26 18:07:51 +02:00
Dustin Spicuzza
0dfffcf257 Add is_final to disallow inheritance from Python
- Not currently supported on PyPy
2020-04-26 09:46:44 +02:00
Ralf W. Grosse-Kunstleve
f6e543b15e Adding a default virtual destructor to Animal type in test_tagbased_polymorphic.cpp.
With this change, and cast.h as-is in master, test_tagbased_polymorphic.cpp fails to compile with the error message below.
With the cast.h change in pull/2016, building and testing succeeds.

cd pybind11/build/tests && /usr/bin/c++  -DPYBIND11_TEST_BOOST -DPYBIND11_TEST_EIGEN -Dpybind11_tests_EXPORTS -Ipybind11/include -I/usr/include/python3.7m -isystem /usr/include/eigen3  -Os -DNDEBUG -fPIC -fvisibility=hidden   -std=c++2a -flto -fno-fat-lto-objects -Wall -Wextra -Wconversion -Wcast-qual -Wdeprecated -o CMakeFiles/pybind11_tests.dir/test_tagbased_polymorphic.cpp.o -c pybind11/tests/test_tagbased_polymorphic.cpp
In file included from pybind11/include/pybind11/attr.h:13,
                 from pybind11/include/pybind11/pybind11.h:44,
                 from pybind11/tests/pybind11_tests.h:2,
                 from pybind11/tests/test_tagbased_polymorphic.cpp:10:
pybind11/include/pybind11/cast.h: In instantiation of ‘static std::pair<const void*, const pybind11::detail::type_info*> pybind11::detail::type_caster_base<type>::src_and_type(const itype*) [with type = Animal; pybind11::detail::type_caster_base<type>::itype = Animal]’:
pybind11/include/pybind11/cast.h:906:31:   required from ‘static pybind11::handle pybind11::detail::type_caster_base<type>::cast_holder(const itype*, const void*) [with type = Animal; pybind11::detail::type_caster_base<type>::itype = Animal]’
pybind11/include/pybind11/cast.h:1566:51:   required from ‘static pybind11::handle pybind11::detail::move_only_holder_caster<type, holder_type>::cast(holder_type&&, pybind11::return_value_policy, pybind11::handle) [with type = Animal; holder_type = std::unique_ptr<Animal>]’
pybind11/include/pybind11/stl.h:175:69:   required from ‘static pybind11::handle pybind11::detail::list_caster<Type, Value>::cast(T&&, pybind11::return_value_policy, pybind11::handle) [with T = std::vector<std::unique_ptr<Animal> >; Type = std::vector<std::unique_ptr<Animal> >; Value = std::unique_ptr<Animal>]’
pybind11/include/pybind11/pybind11.h:159:43:   required from ‘void pybind11::cpp_function::initialize(Func&&, Return (*)(Args ...), const Extra& ...) [with Func = std::vector<std::unique_ptr<Animal> > (*&)(); Return = std::vector<std::unique_ptr<Animal> >; Args = {}; Extra = {pybind11::name, pybind11::scope, pybind11::sibling}]’
pybind11/include/pybind11/pybind11.h:64:9:   required from ‘pybind11::cpp_function::cpp_function(Return (*)(Args ...), const Extra& ...) [with Return = std::vector<std::unique_ptr<Animal> >; Args = {}; Extra = {pybind11::name, pybind11::scope, pybind11::sibling}]’
pybind11/include/pybind11/pybind11.h:819:22:   required from ‘pybind11::module& pybind11::module::def(const char*, Func&&, const Extra& ...) [with Func = std::vector<std::unique_ptr<Animal> > (*)(); Extra = {}]’
pybind11/tests/test_tagbased_polymorphic.cpp:141:36:   required from here
pybind11/include/pybind11/cast.h:880:61: error: ambiguous template instantiation for ‘struct pybind11::polymorphic_type_hook<Animal, void>’
         const void *vsrc = polymorphic_type_hook<itype>::get(src, instance_type);
                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
pybind11/include/pybind11/cast.h:844:8: note: candidates are: ‘template<class itype> struct pybind11::polymorphic_type_hook<itype, typename std::enable_if<std::is_polymorphic<_Tp>::value, void>::type> [with itype = Animal]’
 struct polymorphic_type_hook<itype, detail::enable_if_t<std::is_polymorphic<itype>::value>>
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pybind11/tests/test_tagbased_polymorphic.cpp:115:12: note:                 ‘template<class itype> struct pybind11::polymorphic_type_hook<itype, typename std::enable_if<std::is_base_of<Animal, itype>::value, void>::type> [with itype = Animal]’
     struct polymorphic_type_hook<itype, detail::enable_if_t<std::is_base_of<Animal, itype>::value>>
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from pybind11/include/pybind11/attr.h:13,
                 from pybind11/include/pybind11/pybind11.h:44,
                 from pybind11/tests/pybind11_tests.h:2,
                 from pybind11/tests/test_tagbased_polymorphic.cpp:10:
pybind11/include/pybind11/cast.h:880:61: error: incomplete type ‘pybind11::polymorphic_type_hook<Animal, void>’ used in nested name specifier
         const void *vsrc = polymorphic_type_hook<itype>::get(src, instance_type);
                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
2020-04-14 17:48:43 +02:00
fwjavox
e97c735fc4 stl_bind: add binding for std::vector::clear (#2074) 2020-01-17 01:16:56 +01:00
Vemund Handeland
6e39b765b2 Add C++20 char8_t/u8string support (#2026)
* Fix test build in C++20

* Add C++20 char8_t/u8string support
2019-12-19 12:16:24 +01:00
Sebastian Koslowski
dc65d66171 support for readonly buffers (#863) (#1466) 2019-11-24 08:33:05 +01:00
Francesco Biscani
deb3cb238a Add exception translation for std::overflow_error. (#1977) 2019-11-14 08:56:58 +01:00
Yannick Jadoul
55ff464233 Fixing SystemError when nb_bool/nb_nonzero sets a Python exception in type_caster<bool>::load (#1976) 2019-11-14 08:56:22 +01:00
Sebastian Gsänger
a83d69e78f test pair-copyability on C++17 upwards (#1886)
* test pair-copyability on C++17 upwards

The stdlib falsely detects containers like M=std::map<T, U>
as copyable, even when one of T and U is not copyable.
Therefore we cannot rely on the stdlib dismissing std::pair<T, M>
by itself, even on C++17.

* fix is_copy_assignable

bind_map used std::is_copy_assignable which suffers from the same problems
as std::is_copy_constructible, therefore the same fix has been applied.

* created tests for copyability
2019-10-31 12:38:24 +01:00
Hans Dembinski
bdf6a5e870 Report type names in return value policy-related cast exceptions (#1965) 2019-10-23 13:19:58 +02:00
Wenzel Jakob
31680e6f9c Implicit conversion from enum to int for Python 3.8 (fix by @sizmailov) 2019-09-20 11:06:10 +02:00
Wenzel Jakob
21d0eb460f Fix Python 3.8 test regression 2019-09-20 09:38:30 +02:00
Sergei Izmailov
09f0829401 Avoid conversion to int_ rhs argument of enum eq/ne (#1912)
* fix: Avoid conversion to `int_` rhs argument of enum eq/ne

* test: compare unscoped enum with strings

* suppress comparison to None warning

* test unscoped enum arithmetic and comparision with unsupported type
2019-09-19 18:23:27 +02:00
Lori A. Burns
f6c4c1047a restores __invert__ to arithmetic-enabled enum, fixes #1907 (#1909) 2019-09-04 22:16:21 +02:00
Stephen Larew
5b4751af26 Add const to buffer:request() (#1890) 2019-08-27 17:05:47 +02:00
kingofpayne
12e8774bc9 Added support for list insertion. (#1888) 2019-08-19 23:00:36 +02:00
Andre Schmeißer
19189b4c2c Make overload_cast_impl available in C++11 mode. (#1581)
* Make `overload_cast_impl` available in C++11 mode.

Narrow the scope of the `#if defined(PYBIND11_CPP14)` block around overload_cast to only
cover the parts where C++14 is stricly required. Thus, the implementation in
`pybind11::details::overload_cast_impl` is still available in C++11 mode.

* PR #1581: Modify test to use overload_cast_impl, update docs and change log
2019-08-19 12:54:33 +02:00
Sergei Lebedev
08b0bda4bc Added set::contains and generalized dict::contains (#1884)
Dynamically resolving __contains__ on each call is wasteful since set
has a public PySet_Contains function.
2019-08-16 21:32:27 +02:00
ali-beep
5ef13eb680 Add negative indexing support to stl_bind. (#1882) 2019-08-15 19:41:11 +02:00
Pauli Virtanen
c9d32a81f4 numpy: fix refcount leak to dtype singleton (#1860)
PyArray_DescrFromType returns a new reference, not borrowed one
2019-07-27 11:35:32 +02:00
Eric Cousineau
e9ca89f453 numpy: Add test for explicit dtype checks. At present, int64 + uint64 do not exactly match dtype(...).num 2019-07-23 13:17:20 +02:00
phil-zxx
c6b699d9c2 Added ability to convert from datetime.date to system_clock::time_point (#1848)
* Added ability to convert from Python datetime.date and datetime.time to C++ system_clock::time_point
2019-07-19 11:28:48 +02:00
Jeremy Maitin-Shepard
a3f4a0e8ab Add support for __await__, __aiter__, and __anext__ protocols (#1842) 2019-07-18 09:02:35 +02:00
Saran Tunyasuvunakool
b60fd233fa Make sure detail::get_internals acquires the GIL before making Python calls. (#1836)
This is only necessary if `get_internals` is called for the first time in a given module when the running thread is in a GIL-released state.

Fixes #1364
2019-07-15 16:47:02 +02:00
Igor Socec
a301c5add8 Dtype field ordering for NumPy 1.14 (#1837)
* Test dtype field order in numpy dtype tests

When running tests with NumPy 1.14 or later this test exposes the
"invalid buffer descriptor" error reported in #1274.

* Create dtype_ptr with ordered fields
2019-07-15 13:31:03 +02:00
Wenzel Jakob
9fd4712121 fix test suite (pytest changes in ExceptionInfo class) 2019-07-06 17:35:31 +02:00
Ian Bell
502ffe50a9 Add docs and tests for unary op on class (#1814) 2019-06-22 12:07:41 +02:00
Alexander Gagarin
b3bf248eec Fix casting of time points with non-system-clock duration with VS (#1748)
* Fix casting of time points with non-system-clock duration on Windows

Add explicit `time_point_cast` to time point with duration of system
clock. Fixes Visual Studio compile error.

* Add test case for custom time points casting
2019-06-13 09:17:10 +02:00
Wenzel Jakob
e11e71d85c Make compiler flags for -Werror specific to GNU, Clang, or Intel 2019-06-11 23:28:58 +02:00
sizmailov
21c3911bd3 add signed overload for py::slice::compute 2019-06-11 23:28:58 +02:00
Chris Rusby
22859bb8fc Support more natural syntax for vector extend 2019-06-11 23:28:58 +02:00
Roland Dreier
1aa8dd1745 Fix assertion failure for unions (#1685) (#1709)
In def_readonly and def_readwrite, there is an assertion that the member comes
from the class or a base class:

    static_assert(std::is_base_of<C, type>::value, "...");

However, if C and type are the same type, is_base_of will still only be true
if they are the same _non-union_ type.  This means we can't define accessors
for the members of a union type because of this assertion.

Update the assertion to test

    std::is_same<C, type>::value || std::is_base_of<C, type>::value

which will allow union types, or members of base classes.

Also add a basic unit test for accessing unions.
2019-06-11 23:28:58 +02:00
Alexander Gagarin
0071a3feb0 Fix async Python functors invoking from multiple C++ threads (#1587) (#1595)
* Fix async Python functors invoking from multiple C++ threads (#1587)

Ensure GIL is held during functor destruction.

* Add async Python callbacks test that runs in separate Python thread
2019-06-11 23:28:58 +02:00
Axel Huebl
000aabb2a7 Test: Numpy Scalar Creation (#1530)
I found that the numpy array tests already contained an empty-shaped
array test, but none with data in it.

Following PEP 3118, scalars have an empty shape and ndim 0. This
works already and is now also documented/covered by a test.
2019-06-11 14:00:05 +02:00