Commit Graph

156 Commits

Author SHA1 Message Date
Aaron Gokaslan b4b67f026b
Fix typos (#3044) 2021-06-17 13:39:59 -07:00
Aaron Gokaslan cd4b49a2c8
Update py::kwargs examples to pass by reference (#3038) 2021-06-17 13:20:17 -07:00
Yichen 3ac690b88b
Explicitly export exception types. (#2999)
* Set visibility of exceptions to default.

Co-authored-by: XZiar <czktc2007@gmail.com>

* add test

* update docs

* Skip failed test.
2021-05-27 08:00:18 -07:00
Eric Cousineau b6ec0e950c
functions: Add doc on incorrect argument index (#2979)
test_call_policies: Explicitly check free-functions and static methods
2021-05-06 10:13:30 -04:00
JYX 3df0ee6fe3
docs: typo in classes.rst (#2926) 2021-04-02 11:46:43 -04:00
Tom de Geus 9c0aa69937
Pointing out namespace in docs (#2874) 2021-02-25 07:25:50 -08:00
Yannick Jadoul 1faf4a8ae4
docs: the order of alternatives for variant types matters, and follows the same rules as overload resolution (#2784) 2021-01-13 23:17:27 -05:00
Andy Maloney 14b375123c
docs: fix example code in Exceptions section (match vs. matches) (#2781) 2021-01-13 23:14:45 -05:00
Antony Lee d068ab286a
docs: pybind11/numpy.h does not require numpy at build time. (#2720)
This is nice enough to be mentioned explicitly in the docs.
2020-12-08 18:07:36 -05:00
Jean-Baptiste Lespiau af8849f47e
docs: list all pybind11 exceptions (#2671)
* List all the pyind11 exceptions.

For curious readers, see `translate_exception` and
`PYBIND11_RUNTIME_EXCEPTION.
2020-11-19 10:11:55 -05:00
Henry Schreiner f200832534 style: ssize_t -> py::ssize_t 2020-10-15 17:38:49 -04:00
Henry Schreiner 9a0c96dd4c
feat: py::prepend tag (#1131)
* feat: add a priority overload with py::prepend

* doc: fix wording as suggested by rwgk

* feat: add get_pointer

* refactor: is_prepended -> prepend (internal)

* docs: suggestion from @wjakob

* tests: add test covering get_pointer/set_pointer
2020-10-05 22:36:33 -04:00
Yannick Jadoul 1411207711
chore: drop support for PyPy < 7.3.1 and clean up old PyPy workarounds (#2456)
* Remove code inside 'PYPY_VERSION_NUM < 0x06000000' preprocessor if branch

* fix: more cleanup

* Remove more references to PyPy 5.7 and 5.9 in the docs

* Update comment on PyUnicode_UTF* in PyPy

Co-authored-by: Henry Schreiner <henryschreineriii@gmail.com>
2020-10-05 10:43:27 -04:00
Yannick Jadoul b70894df52
docs: add std::valarray to docs/advanced/cast/stl.rst (#2547) 2020-10-04 09:52:55 -04:00
Henry Schreiner 6bcd220c8d
refactor: module -> module_ with typedef (#2544)
* WIP: module -> module_ without typedef

* refactor: allow py::module to work again
2020-10-03 13:38:03 -04:00
Henry Schreiner dabbbf315d
fix: use OVERRIDE instead of OVERLOAD (#2490)
* fix: use OVERRIDE instead of OVERLOAD

* docs: more accurate statement
2020-09-15 12:10:31 -04:00
Yannick Jadoul 16f199f8d9
Change base parameter type in register_exception and exception constructor from PyObject* to handle (#2467)
* Change base parameter type in register_exception and excepion constructor from PyObject* to handle

* Fix compilation error passing `handle` to `PyObject*`
2020-09-15 10:24:39 -04:00
Yannick Jadoul d65e34d61d
Resolve empty statement warning when using PYBIND11_OVERLOAD_PURE_NAME and PYBIND11_OVERLOAD_PURE (#2325)
* Wrap PYBIND11_OVERLOAD_NAME and PYBIND11_OVERLOAD_PURE_NAME in do { ... } while (false), and resolve trailing semicolon

* Deprecate PYBIND11_OVERLOAD_* and get_overload in favor of PYBIND11_OVERRIDE_* and get_override

* Correct erroneous usage of 'overload' instead of 'override' in the implementation and internals

* Fix tests to use non-deprecated PYBIND11_OVERRIDE_* macros

* Update docs to use override instead of overload where appropriate, and add warning about deprecated aliases

* Add semicolons to deprecated PYBIND11_OVERLOAD macros to match original behavior

* Remove deprecation of PYBIND11_OVERLOAD_* macros and get_overload

* Add note to changelog and upgrade guide
2020-09-15 14:56:20 +02:00
Henry Schreiner f12ec00d70
feat: py::type::of<T>() and py::type::of(h) (#2364)
* feat: type<T>()

* refactor: using py::type as class

* refactor: py::object as base

* wip: tigher api

* refactor: fix conversion and limit API further

* docs: some added notes from @EricCousineau-TRI

* refactor: use py::type::of
2020-09-14 18:06:26 -04:00
Boris Staletic 32bb9071aa
Avoid C-style casts for pointers in docs (#2487)
Why only for pointers? Because C casts are hard to grep for.
2020-09-14 20:07:29 +02:00
Holger Kohr fbc7563623
Add py::object casting example to embedding docs (#2466)
* Add py::object casting example to embedding docs

* Move implicit cast example to object.rst

* Move to bottom and improve implicit casting text

* Fix xref

* Improve wording as per @bstaletic's suggestion
2020-09-09 10:39:20 -04:00
Henry Schreiner 37f845a1dc
ci: disallow some common capitalization mistakes (#2472)
* ci: only annotate linux for now

* style: block some common mistakes
2020-09-08 15:26:50 +02:00
michalsustr 3bd0d7a8d5
Add note about specifying custom base class for Exceptions. (#2465)
* Add note about specifying custom base.

* Update exception docs based on PR feedback.

* Fix trailing whitespace.

Co-authored-by: Michal Sustr <michal.sustr@aic.fel.cvut.cz>
2020-09-06 13:35:53 +02:00
Henry Schreiner 0dbda6e80b
feat: py::pos_only (#2459)
* feat: py::pos_only

* fix: review points from @YannickJadoul

* fix: review points from @bstaletic

* refactor: kwonly -> kw_only
2020-09-04 20:02:05 -04:00
Eric Cousineau 44fa79ca80
pytypes: Add Gotchas section about default-constructed wrapper types and py::none() (#2362) 2020-09-04 19:26:57 -04:00
Sergei Izmailov 4c36fb7b12
[DOC] avoid C++ types in docstrings (#2441)
* doc: avoid C++ types in docstrings

* A bit of rewording

* Another bit of rewording

* Third rewording
2020-09-01 14:56:43 +02:00
Yannick Jadoul b3d8fec066
Adapt code example in advanced/classes.rst to new handling of forgetting to call the superclass __init__ (#2429) 2020-08-24 00:00:12 +02:00
Yannick Jadoul 4493751a5f
Fix new-style __init__ usage in numpy docs (#2426) 2020-08-23 18:35:51 +02:00
jbarlow83 b8863698d6
Improve documentation of Python and C++ exceptions (#2408)
The main change is to treat error_already_set as a separate category
of exception that arises in different circumstances and needs to be
handled differently. The asymmetry between Python and C++ exceptions
is further emphasized.
2020-08-23 00:11:09 +02:00
Henry Schreiner a6887b604a docs: update changelog and versionadded 2020-08-20 14:42:00 -04:00
Henry Schreiner 1729aae96f
feat: new FindPython support (#2370)
* feat: FindPython support

* refactor: rename to PYBIND11_FINDPYTHON

* docs: Caps fixes

* feat: NOPYTHON mode

* test: check simple call

* docs: add changelog/upgrade guide

* feat: Support Python3 and Python2

* refactor: Use targets in tests

* fix: support CMake 3.4+

* feat: classic search also finds virtual environments

* docs: some updates from @wjakob's review

* fix: wrong name for QUIET mode variable, reported by @skoslowski

* refactor: cleaner output messaging

* fix: support debug Python's in FindPython mode too

* fixup! refactor: cleaner output messaging

* fix: missing pybind11_FOUND and pybind11_INCLUDE_DIR restored to subdir mode

* fix: nicer reporting of Python / PyPy

* fix: out-of-order variable fix

* docs: minor last-minute cleanup
2020-08-19 12:26:26 -04:00
James R. Barlow 3618bea2aa Add and document py::error_already_set::discard_as_unraisable()
To deal with exceptions that hit destructors or other noexcept functions.

Includes fixes to support Python 2.7 and extends documentation on
error handling.

@virtuald and @YannickJadoul both contributed to this PR.
2020-08-16 10:05:03 -07:00
Yannick Jadoul 3e448c0b5e
Enable py::ellipsis on Python 2 (#2360)
* Enable py::ellipsis on Python 2

* Enable py::ellipsis tests on Python 2 and mention `Ellipsis` in the docs
2020-08-04 14:45:55 +02:00
Boris Staletic 441e777040
Use new style __init__ in numpy docs (#2316) 2020-07-23 16:03:55 +02:00
Henry Schreiner d8c7ee00a6
ci: GHA basic format & pre-commit (#2309) 2020-07-20 13:35:21 -04:00
Kota Yamaguchi e248869893
Fix undefined memoryview format (#2223)
* Fix undefined memoryview format

* Add missing <algorithm> header

* Add workaround for py27 array compatibility

* Workaround py27 memoryview behavior

* Fix memoryview constructor from buffer_info

* Workaround PyMemoryView_FromMemory availability in py27

* Fix up memoryview tests

* Update memoryview test from buffer to check signedness

* Use static factory method to create memoryview

* Remove ndim arg from memoryview::frombuffer and add tests

* Allow ndim=0 memoryview and documentation fixup

* Use void* to align to frombuffer method signature

* Add const variants of frombuffer and frommemory

* Add memory view section in doc

* Fix docs

* Add test for null buffer

* Workaround py27 nullptr behavior in test

* Rename frombuffer to from_buffer
2020-07-15 08:50:43 -07:00
Dustin Spicuzza 1b0bf352fa
Throw TypeError when subclasses forget to call __init__ (#2152)
- Fixes #2103
2020-07-07 12:04:06 +02:00
Wenzel Jakob fc3a4490b8 Minor clarification (@AntoinePrv, #2083) 2020-07-01 00:29:55 +02:00
Guilherme Dantas 8908552dfc typo 2020-07-01 00:12:33 +02:00
Matthijs van der Burgh b524008967
Deepcopy documentation (#2242)
* (docs) convert note to real note

* (docs) Add information about (deep)copy
2020-06-10 13:30:41 +02:00
Wenzel Jakob a54eab92d2 Revert "Change __init__(self) to __new__(cls)"
This reverts commit 9ed8b44033.
2020-04-26 22:53:50 +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
Orell Garten 9ed8b44033 Change __init__(self) to __new__(cls)
__init__(self) cannot return values. According to https://stackoverflow.com/questions/2491819/how-to-return-a-value-from-init-in-python __new__(cls) should be used, which works.
2020-04-26 09:21:42 +02:00
Francesco Biscani deb3cb238a Add exception translation for std::overflow_error. (#1977) 2019-11-14 08:56:58 +01: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
Ian Bell 502ffe50a9 Add docs and tests for unary op on class (#1814) 2019-06-22 12:07:41 +02:00
Wenzel Jakob 51ca6b0832 Update docs on std::out_of_range exception mapping (#1254) 2019-06-11 23:28:58 +02:00
Roland Dreier 7a24bcf1f6 Fix malformed reST (#1802)
Commit 2b045757b5 ("Improve documentation related to inheritance. (#1676)") left off
a ':' from a hyperlink, which breaks the Travis CI build.
2019-06-11 10:57:49 +02:00