Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
pybind11
Commits
93716147
Commit
93716147
authored
Dec 28, 2021
by
Henry Schreiner
Browse files
Merge branch 'master' into stable
parents
acae9301
45f792ef
Changes
57
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
440 additions
and
217 deletions
+440
-217
.github/workflows/ci.yml
.github/workflows/ci.yml
+33
-29
.github/workflows/upstream.yml
.github/workflows/upstream.yml
+112
-0
.pre-commit-config.yaml
.pre-commit-config.yaml
+14
-8
CMakeLists.txt
CMakeLists.txt
+8
-6
README.rst
README.rst
+1
-1
docs/Doxyfile
docs/Doxyfile
+1
-2
docs/advanced/cast/custom.rst
docs/advanced/cast/custom.rst
+1
-1
docs/advanced/cast/eigen.rst
docs/advanced/cast/eigen.rst
+1
-1
docs/advanced/cast/overview.rst
docs/advanced/cast/overview.rst
+90
-90
docs/advanced/exceptions.rst
docs/advanced/exceptions.rst
+1
-1
docs/advanced/functions.rst
docs/advanced/functions.rst
+14
-2
docs/basics.rst
docs/basics.rst
+1
-1
docs/changelog.rst
docs/changelog.rst
+94
-2
docs/release.rst
docs/release.rst
+4
-5
docs/requirements.txt
docs/requirements.txt
+5
-8
docs/upgrade.rst
docs/upgrade.rst
+4
-0
include/pybind11/attr.h
include/pybind11/attr.h
+24
-16
include/pybind11/cast.h
include/pybind11/cast.h
+29
-41
include/pybind11/chrono.h
include/pybind11/chrono.h
+2
-2
include/pybind11/complex.h
include/pybind11/complex.h
+1
-1
No files found.
.github/workflows/ci.yml
View file @
93716147
...
...
@@ -23,35 +23,39 @@ jobs:
strategy
:
fail-fast
:
false
matrix
:
runs-on
:
[
ubuntu-latest
,
windows-
latest
,
macos-latest
]
runs-on
:
[
ubuntu-latest
,
windows-
2022
,
macos-latest
]
python
:
-
'
2.7'
-
'
3.5'
-
'
3.6'
-
'
3.9'
-
'
3.10'
# - '3.11-dev'
-
'
pypy-3.7-v7.3.5'
# - 'pypy-3.8'
-
'
pypy-3.7-v7.3.7'
-
'
pypy-3.8-v7.3.7'
# Items in here will either be added to the build matrix (if not
# present), or add new keys to an existing matrix element if all the
# existing keys match.
#
# We support three optional keys: args (both build), args1 (first
# build), and args2 (second build).
# We support an optional key: args, for cmake args
include
:
# Just add a key
-
runs-on
:
ubuntu-latest
python
:
3.6
python
:
'
3.6
'
args
:
>
-DPYBIND11_FINDPYTHON=ON
-DCMAKE_CXX_FLAGS="-D_=1"
-
runs-on
:
windows-latest
python
:
3.6
python
:
'
3.6
'
args
:
>
-DPYBIND11_FINDPYTHON=ON
-
runs-on
:
macos-latest
python
:
pypy-2.7
python
:
'
pypy-2.7'
# Inject a couple Windows 2019 runs
-
runs-on
:
windows-2019
python
:
'
3.9'
-
runs-on
:
windows-2019
python
:
'
2.7'
name
:
"
🐍
${{
matrix.python
}}
•
${{
matrix.runs-on
}}
•
x64
${{
matrix.args
}}"
runs-on
:
${{ matrix.runs-on }}
...
...
@@ -65,7 +69,8 @@ jobs:
python-version
:
${{ matrix.python }}
-
name
:
Setup Boost (Linux)
if
:
runner.os == 'Linux'
# Can't use boost + define _
if
:
runner.os == 'Linux' && matrix.python != '3.6'
run
:
sudo apt-get install libboost-dev
-
name
:
Setup Boost (macOS)
...
...
@@ -122,7 +127,7 @@ jobs:
run
:
git clean -fdx
# Second build - C++17 mode and in a build directory
-
name
:
Configure
${{ matrix.args2 }}
-
name
:
Configure
C++17
run
:
>
cmake -S . -B build2
-DPYBIND11_WERROR=ON
...
...
@@ -130,7 +135,6 @@ jobs:
-DDOWNLOAD_EIGEN=ON
-DCMAKE_CXX_STANDARD=17
${{ matrix.args }}
${{ matrix.args2 }}
-
name
:
Build
run
:
cmake --build build2 -j
2
...
...
@@ -184,6 +188,7 @@ jobs:
# setuptools
-
name
:
Setuptools helpers test
run
:
pytest tests/extra_setuptools
if
:
"
!(matrix.python
==
'3.5'
&&
matrix.runs-on
==
'windows-2022')"
deadsnakes
:
...
...
@@ -244,6 +249,8 @@ jobs:
python -m pip install -r tests/requirements.txt
-
name
:
Configure
env
:
SETUPTOOLS_USE_DISTUTILS
:
stdlib
run
:
>
cmake -S . -B build
-DCMAKE_BUILD_TYPE=Debug
...
...
@@ -552,37 +559,37 @@ jobs:
set +e; source /opt/intel/oneapi/setvars.sh; set -e
cmake --build build-11 --target test_cmake_build
-
name
:
Configure C++1
7
-
name
:
Configure C++1
4
run
:
|
set +e; source /opt/intel/oneapi/setvars.sh; set -e
cmake -S . -B build-1
7
\
cmake -S . -B build-1
4
\
-DPYBIND11_WERROR=ON \
-DDOWNLOAD_CATCH=ON \
-DDOWNLOAD_EIGEN=OFF \
-DCMAKE_CXX_STANDARD=1
7
\
-DCMAKE_CXX_STANDARD=1
4
\
-DCMAKE_CXX_COMPILER=$(which icpc) \
-DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)")
-
name
:
Build C++1
7
-
name
:
Build C++1
4
run
:
|
set +e; source /opt/intel/oneapi/setvars.sh; set -e
cmake --build build-1
7
-j 2 -v
cmake --build build-1
4
-j 2 -v
-
name
:
Python tests C++1
7
-
name
:
Python tests C++1
4
run
:
|
set +e; source /opt/intel/oneapi/setvars.sh; set -e
sudo service apport stop
cmake --build build-1
7
--target check
cmake --build build-1
4
--target check
-
name
:
C++ tests C++1
7
-
name
:
C++ tests C++1
4
run
:
|
set +e; source /opt/intel/oneapi/setvars.sh; set -e
cmake --build build-1
7
--target cpptest
cmake --build build-1
4
--target cpptest
-
name
:
Interface test C++1
7
-
name
:
Interface test C++1
4
run
:
|
set +e; source /opt/intel/oneapi/setvars.sh; set -e
cmake --build build-1
7
--target test_cmake_build
cmake --build build-1
4
--target test_cmake_build
# Testing on CentOS (manylinux uses a centos base, and this is an easy way
...
...
@@ -704,14 +711,11 @@ jobs:
-
name
:
Install Doxygen
run
:
sudo apt-get install -y doxygen librsvg2-bin
# Changed to rsvg-convert in 20.04
-
name
:
Install docs & setup requirements
run
:
python3 -m pip install -r docs/requirements.txt
-
name
:
Build docs
run
:
p
ython3 -m sphinx -W -b html docs docs/.build
run
:
p
ipx run nox -s docs
-
name
:
Make SDist
run
:
p
ython3 setup.py
sdist
run
:
p
ipx run nox -s build -- --
sdist
-
run
:
git status --ignored
...
...
@@ -723,7 +727,7 @@ jobs:
-
name
:
Compare Dists (headers only)
working-directory
:
include
run
:
|
python3 -m pip install --user -U ../dist/*
python3 -m pip install --user -U ../dist/*
.tar.gz
installed=$(python3 -c "import pybind11; print(pybind11.get_include() + '/pybind11')")
diff -rq $installed ./pybind11
...
...
.github/workflows/upstream.yml
0 → 100644
View file @
93716147
name
:
Upstream
on
:
workflow_dispatch
:
pull_request
:
concurrency
:
group
:
upstream-${{ github.ref }}
cancel-in-progress
:
true
env
:
PIP_ONLY_BINARY
:
numpy
jobs
:
standard
:
name
:
"
🐍
3.11
dev
•
ubuntu-latest
•
x64"
runs-on
:
ubuntu-latest
if
:
"
contains(github.event.pull_request.labels.*.name,
'python
dev')"
steps
:
-
uses
:
actions/checkout@v2
-
name
:
Setup Python
3.11
uses
:
actions/setup-python@v2
with
:
python-version
:
"
3.11-dev"
-
name
:
Setup Boost (Linux)
if
:
runner.os == 'Linux'
run
:
sudo apt-get install libboost-dev
-
name
:
Update CMake
uses
:
jwlawson/actions-setup-cmake@v1.11
-
name
:
Prepare env
run
:
|
python -m pip install -r tests/requirements.txt
-
name
:
Setup annotations on Linux
if
:
runner.os == 'Linux'
run
:
python -m pip install pytest-github-actions-annotate-failures
# First build - C++11 mode and inplace
-
name
:
Configure C++11
run
:
>
cmake -S . -B .
-DPYBIND11_WERROR=ON
-DDOWNLOAD_CATCH=ON
-DDOWNLOAD_EIGEN=ON
-DCMAKE_CXX_STANDARD=11
-
name
:
Build C++11
run
:
cmake --build . -j
2
-
name
:
Python tests C++11
run
:
cmake --build . --target pytest -j
2
-
name
:
C++11 tests
run
:
cmake --build . --target cpptest -j
2
-
name
:
Interface test C++11
run
:
cmake --build . --target test_cmake_build
-
name
:
Clean directory
run
:
git clean -fdx
# Second build - C++17 mode and in a build directory
-
name
:
Configure C++17
run
:
>
cmake -S . -B build2
-DPYBIND11_WERROR=ON
-DDOWNLOAD_CATCH=ON
-DDOWNLOAD_EIGEN=ON
-DCMAKE_CXX_STANDARD=17
${{ matrix.args }}
${{ matrix.args2 }}
-
name
:
Build
run
:
cmake --build build2 -j
2
-
name
:
Python tests
run
:
cmake --build build2 --target pytest
-
name
:
C++ tests
run
:
cmake --build build2 --target cpptest
# Third build - C++17 mode with unstable ABI
-
name
:
Configure (unstable ABI)
run
:
>
cmake -S . -B build3
-DPYBIND11_WERROR=ON
-DDOWNLOAD_CATCH=ON
-DDOWNLOAD_EIGEN=ON
-DCMAKE_CXX_STANDARD=17
-DPYBIND11_INTERNALS_VERSION=10000000
"-DPYBIND11_TEST_OVERRIDE=test_call_policies.cpp;test_gil_scoped.cpp;test_thread.cpp"
${{ matrix.args }}
-
name
:
Build (unstable ABI)
run
:
cmake --build build3 -j
2
-
name
:
Python tests (unstable ABI)
run
:
cmake --build build3 --target pytest
-
name
:
Interface test
run
:
cmake --build build2 --target test_cmake_build
# This makes sure the setup_helpers module can build packages using
# setuptools
-
name
:
Setuptools helpers test
run
:
pytest tests/extra_setuptools
.pre-commit-config.yaml
View file @
93716147
...
...
@@ -15,7 +15,7 @@
repos
:
# Standard hooks
-
repo
:
https://github.com/pre-commit/pre-commit-hooks
rev
:
v4.
0.1
rev
:
v4.
1.0
hooks
:
-
id
:
check-added-large-files
-
id
:
check-case-conflict
...
...
@@ -33,27 +33,27 @@ repos:
exclude
:
^noxfile.py$
-
repo
:
https://github.com/asottile/pyupgrade
rev
:
v2.29.
0
rev
:
v2.29.
1
hooks
:
-
id
:
pyupgrade
-
repo
:
https://github.com/PyCQA/isort
rev
:
5.
9.3
rev
:
5.
10.1
hooks
:
-
id
:
isort
# Black, the code formatter, natively supports pre-commit
-
repo
:
https://github.com/psf/black
rev
:
21.
9
b0
# Keep in sync with blacken-docs
rev
:
21.
12
b0
# Keep in sync with blacken-docs
hooks
:
-
id
:
black
-
repo
:
https://github.com/asottile/blacken-docs
rev
:
v1.1
1
.0
rev
:
v1.1
2
.0
hooks
:
-
id
:
blacken-docs
additional_dependencies
:
-
black==21.
9
b0
# keep in sync with black hook
-
black==21.
12
b0
# keep in sync with black hook
# Changes tabs to spaces
-
repo
:
https://github.com/Lucas-C/pre-commit-hooks
...
...
@@ -61,6 +61,12 @@ repos:
hooks
:
-
id
:
remove-tabs
# Autoremoves unused imports
-
repo
:
https://github.com/hadialqattan/pycln
rev
:
v1.1.0
hooks
:
-
id
:
pycln
-
repo
:
https://github.com/pre-commit/pygrep-hooks
rev
:
v1.9.0
hooks
:
...
...
@@ -98,7 +104,7 @@ repos:
# Check static types with mypy
-
repo
:
https://github.com/pre-commit/mirrors-mypy
rev
:
v0.9
10-1
rev
:
v0.9
30
hooks
:
-
id
:
mypy
# Running per-file misbehaves a bit, so just run on all files, it's fast
...
...
@@ -122,7 +128,7 @@ repos:
args
:
[
"
-L"
,
"
nd,ot,thist"
]
-
repo
:
https://github.com/shellcheck-py/shellcheck-py
rev
:
v0.
7.2.1
rev
:
v0.
8.0.3
hooks
:
-
id
:
shellcheck
...
...
CMakeLists.txt
View file @
93716147
...
...
@@ -16,6 +16,11 @@ else()
cmake_policy
(
VERSION 3.22
)
endif
()
# Avoid infinite recursion if tests include this as a subdirectory
if
(
DEFINED PYBIND11_MASTER_PROJECT
)
return
()
endif
()
# Extract project version from source
file
(
STRINGS
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/include/pybind11/detail/common.h"
pybind11_version_defines REGEX
"#define PYBIND11_VERSION_(MAJOR|MINOR|PATCH) "
)
...
...
@@ -45,13 +50,8 @@ if(NOT pybind11_FIND_QUIETLY)
message
(
STATUS
"pybind11 v
${
pybind11_VERSION
}
${
pybind11_VERSION_TYPE
}
"
)
endif
()
# Avoid infinite recursion if tests include this as a subdirectory
if
(
DEFINED PYBIND11_MASTER_PROJECT
)
set
(
PYBIND11_TEST OFF
)
endif
()
# Check if pybind11 is being used directly or via add_subdirectory
if
(
CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR
AND NOT DEFINED PYBIND11_MASTER_PROJECT
)
if
(
CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR
)
### Warn if not an out-of-source builds
if
(
CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR
)
set
(
lines
...
...
@@ -80,6 +80,8 @@ if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR AND NOT DEFINED PYBIND11_MASTER_
endif
()
set
(
pybind11_system
""
)
set_property
(
GLOBAL PROPERTY USE_FOLDERS ON
)
else
()
set
(
PYBIND11_MASTER_PROJECT OFF
)
set
(
pybind11_system SYSTEM
)
...
...
README.rst
View file @
93716147
...
...
@@ -106,7 +106,7 @@ goodies:
- Binaries are generally smaller by a factor of at least 2 compared to
equivalent bindings generated by Boost.Python. A recent pybind11
conversion of PyRosetta, an enormous Boost.Python binding project,
`reported <http://graylab.jhu.edu/RosettaCon
2016
/PyRosetta-4.pdf>`_
`reported <http
s
://graylab.jhu.edu/
Sergey/2016.
RosettaCon/PyRosetta-4.pdf>`_
a binary size reduction of **5.4x** and compile time reduction by
**5.8x**.
...
...
docs/Doxyfile
View file @
93716147
...
...
@@ -18,6 +18,5 @@ ALIASES += "endrst=\endverbatim"
QUIET = YES
WARNINGS = YES
WARN_IF_UNDOCUMENTED = NO
PREDEFINED = DOXYGEN_SHOULD_SKIP_THIS \
PY_MAJOR_VERSION=3 \
PREDEFINED = PY_MAJOR_VERSION=3 \
PYBIND11_NOINLINE
docs/advanced/cast/custom.rst
View file @
93716147
...
...
@@ -46,7 +46,7 @@ type is explicitly allowed.
* function signatures and declares a local variable
* 'value' of type inty
*/
PYBIND11_TYPE_CASTER(inty,
_
("inty"));
PYBIND11_TYPE_CASTER(inty,
const_name
("inty"));
/**
* Conversion part 1 (Python->C++): convert a PyObject into a inty
...
...
docs/advanced/cast/eigen.rst
View file @
93716147
...
...
@@ -52,7 +52,7 @@ can be mapped *and* if the numpy array is writeable (that is
the passed variable will be transparently carried out directly on the
``numpy.ndarray``.
This means you can
can
write code such as the following and have it work as
This means you can write code such as the following and have it work as
expected:
.. code-block:: cpp
...
...
docs/advanced/cast/overview.rst
View file @
93716147
...
...
@@ -75,96 +75,96 @@ The following basic data types are supported out of the box (some may require
an additional extension header to be included). To pass other data structures
as arguments and return values, refer to the section on binding :ref:`classes`.
+------------------------------------+---------------------------+-------------------------------+
| Data type | Description | Header file |
+====================================+===========================+===============================+
| ``int8_t``, ``uint8_t`` | 8-bit integers | :file:`pybind11/pybind11.h` |
+------------------------------------+---------------------------+-------------------------------+
| ``int16_t``, ``uint16_t`` | 16-bit integers | :file:`pybind11/pybind11.h` |
+------------------------------------+---------------------------+-------------------------------+
| ``int32_t``, ``uint32_t`` | 32-bit integers | :file:`pybind11/pybind11.h` |
+------------------------------------+---------------------------+-------------------------------+
| ``int64_t``, ``uint64_t`` | 64-bit integers | :file:`pybind11/pybind11.h` |
+------------------------------------+---------------------------+-------------------------------+
| ``ssize_t``, ``size_t`` | Platform-dependent size | :file:`pybind11/pybind11.h` |
+------------------------------------+---------------------------+-------------------------------+
| ``float``, ``double`` | Floating point types | :file:`pybind11/pybind11.h` |
+------------------------------------+---------------------------+-------------------------------+
| ``bool`` | Two-state Boolean type | :file:`pybind11/pybind11.h` |
+------------------------------------+---------------------------+-------------------------------+
| ``char`` | Character literal | :file:`pybind11/pybind11.h` |
+------------------------------------+---------------------------+-------------------------------+
| ``char16_t`` | UTF-16 character literal | :file:`pybind11/pybind11.h` |
+------------------------------------+---------------------------+-------------------------------+
| ``char32_t`` | UTF-32 character literal | :file:`pybind11/pybind11.h` |
+------------------------------------+---------------------------+-------------------------------+
| ``wchar_t`` | Wide character literal | :file:`pybind11/pybind11.h` |
+------------------------------------+---------------------------+-------------------------------+
| ``const char *`` | UTF-8 string literal | :file:`pybind11/pybind11.h` |
+------------------------------------+---------------------------+-------------------------------+
| ``const char16_t *`` | UTF-16 string literal | :file:`pybind11/pybind11.h` |
+------------------------------------+---------------------------+-------------------------------+
| ``const char32_t *`` | UTF-32 string literal | :file:`pybind11/pybind11.h` |
+------------------------------------+---------------------------+-------------------------------+
| ``const wchar_t *`` | Wide string literal | :file:`pybind11/pybind11.h` |
+------------------------------------+---------------------------+-------------------------------+
| ``std::string`` | STL dynamic UTF-8 string | :file:`pybind11/pybind11.h` |
+------------------------------------+---------------------------+-------------------------------+
| ``std::u16string`` | STL dynamic UTF-16 string | :file:`pybind11/pybind11.h` |
+------------------------------------+---------------------------+-------------------------------+
| ``std::u32string`` | STL dynamic UTF-32 string | :file:`pybind11/pybind11.h` |
+------------------------------------+---------------------------+-------------------------------+
| ``std::wstring`` | STL dynamic wide string | :file:`pybind11/pybind11.h` |
+------------------------------------+---------------------------+-------------------------------+
| ``std::string_view``, | STL C++17 string views | :file:`pybind11/pybind11.h` |
| ``std::u16string_view``, etc. | | |
+------------------------------------+---------------------------+-------------------------------+
| ``std::pair<T1, T2>`` | Pair of two custom types | :file:`pybind11/pybind11.h` |
+------------------------------------+---------------------------+-------------------------------+
| ``std::tuple<...>`` | Arbitrary tuple of types | :file:`pybind11/pybind11.h` |
+------------------------------------+---------------------------+-------------------------------+
| ``std::reference_wrapper<...>`` | Reference type wrapper | :file:`pybind11/pybind11.h` |
+------------------------------------+---------------------------+-------------------------------+
| ``std::complex<T>`` | Complex numbers | :file:`pybind11/complex.h` |
+------------------------------------+---------------------------+-------------------------------+
| ``std::array<T, Size>`` | STL static array | :file:`pybind11/stl.h` |
+------------------------------------+---------------------------+-------------------------------+
| ``std::vector<T>`` | STL dynamic array | :file:`pybind11/stl.h` |
+------------------------------------+---------------------------+-------------------------------+
| ``std::deque<T>`` | STL double-ended queue | :file:`pybind11/stl.h` |
+------------------------------------+---------------------------+-------------------------------+
| ``std::valarray<T>`` | STL value array | :file:`pybind11/stl.h` |
+------------------------------------+---------------------------+-------------------------------+
| ``std::list<T>`` | STL linked list | :file:`pybind11/stl.h` |
+------------------------------------+---------------------------+-------------------------------+
| ``std::map<T1, T2>`` | STL ordered map | :file:`pybind11/stl.h` |
+------------------------------------+---------------------------+-------------------------------+
| ``std::unordered_map<T1, T2>`` | STL unordered map | :file:`pybind11/stl.h` |
+------------------------------------+---------------------------+-------------------------------+
| ``std::set<T>`` | STL ordered set | :file:`pybind11/stl.h` |
+------------------------------------+---------------------------+-------------------------------+
| ``std::unordered_set<T>`` | STL unordered set | :file:`pybind11/stl.h` |
+------------------------------------+---------------------------+-------------------------------+
| ``std::optional<T>`` | STL optional type (C++17) | :file:`pybind11/stl.h` |
+------------------------------------+---------------------------+-------------------------------+
| ``std::experimental::optional<T>`` | STL optional type (exp.) | :file:`pybind11/stl.h` |
+------------------------------------+---------------------------+-------------------------------+
| ``std::variant<...>`` | Type-safe union (C++17) | :file:`pybind11/stl.h` |
+------------------------------------+---------------------------+-------------------------------+
| ``std::filesystem::path<T>`` | STL path (C++17) [#]_ | :file:`pybind11/stl
.h`
|
+------------------------------------+---------------------------+-------------------------------+
| ``std::function<...>`` | STL polymorphic function | :file:`pybind11/functional.h` |
+------------------------------------+---------------------------+-------------------------------+
| ``std::chrono::duration<...>`` | STL time duration | :file:`pybind11/chrono.h` |
+------------------------------------+---------------------------+-------------------------------+
| ``std::chrono::time_point<...>`` | STL date/time | :file:`pybind11/chrono.h` |
+------------------------------------+---------------------------+-------------------------------+
| ``Eigen::Matrix<...>`` | Eigen: dense matrix | :file:`pybind11/eigen.h` |
+------------------------------------+---------------------------+-------------------------------+
| ``Eigen::Map<...>`` | Eigen: mapped memory | :file:`pybind11/eigen.h` |
+------------------------------------+---------------------------+-------------------------------+
| ``Eigen::SparseMatrix<...>`` | Eigen: sparse matrix | :file:`pybind11/eigen.h` |
+------------------------------------+---------------------------+-------------------------------+
+------------------------------------+---------------------------+-------------------------------
----
+
| Data type | Description | Header file
|
+====================================+===========================+===============================
====
+
| ``int8_t``, ``uint8_t`` | 8-bit integers | :file:`pybind11/pybind11.h`
|
+------------------------------------+---------------------------+-------------------------------
----
+
| ``int16_t``, ``uint16_t`` | 16-bit integers | :file:`pybind11/pybind11.h`
|
+------------------------------------+---------------------------+-------------------------------
----
+
| ``int32_t``, ``uint32_t`` | 32-bit integers | :file:`pybind11/pybind11.h`
|
+------------------------------------+---------------------------+-------------------------------
----
+
| ``int64_t``, ``uint64_t`` | 64-bit integers | :file:`pybind11/pybind11.h`
|
+------------------------------------+---------------------------+-------------------------------
----
+
| ``ssize_t``, ``size_t`` | Platform-dependent size | :file:`pybind11/pybind11.h`
|
+------------------------------------+---------------------------+-------------------------------
----
+
| ``float``, ``double`` | Floating point types | :file:`pybind11/pybind11.h`
|
+------------------------------------+---------------------------+-------------------------------
----
+
| ``bool`` | Two-state Boolean type | :file:`pybind11/pybind11.h`
|
+------------------------------------+---------------------------+-------------------------------
----
+
| ``char`` | Character literal | :file:`pybind11/pybind11.h`
|
+------------------------------------+---------------------------+-------------------------------
----
+
| ``char16_t`` | UTF-16 character literal | :file:`pybind11/pybind11.h`
|
+------------------------------------+---------------------------+-------------------------------
----
+
| ``char32_t`` | UTF-32 character literal | :file:`pybind11/pybind11.h`
|
+------------------------------------+---------------------------+-------------------------------
----
+
| ``wchar_t`` | Wide character literal | :file:`pybind11/pybind11.h`
|
+------------------------------------+---------------------------+-------------------------------
----
+
| ``const char *`` | UTF-8 string literal | :file:`pybind11/pybind11.h`
|
+------------------------------------+---------------------------+-------------------------------
----
+
| ``const char16_t *`` | UTF-16 string literal | :file:`pybind11/pybind11.h`
|
+------------------------------------+---------------------------+-------------------------------
----
+
| ``const char32_t *`` | UTF-32 string literal | :file:`pybind11/pybind11.h`
|
+------------------------------------+---------------------------+-------------------------------
----
+
| ``const wchar_t *`` | Wide string literal | :file:`pybind11/pybind11.h`
|
+------------------------------------+---------------------------+-------------------------------
----
+
| ``std::string`` | STL dynamic UTF-8 string | :file:`pybind11/pybind11.h`
|
+------------------------------------+---------------------------+-------------------------------
----
+
| ``std::u16string`` | STL dynamic UTF-16 string | :file:`pybind11/pybind11.h`
|
+------------------------------------+---------------------------+-------------------------------
----
+
| ``std::u32string`` | STL dynamic UTF-32 string | :file:`pybind11/pybind11.h`
|
+------------------------------------+---------------------------+-------------------------------
----
+
| ``std::wstring`` | STL dynamic wide string | :file:`pybind11/pybind11.h`
|
+------------------------------------+---------------------------+-------------------------------
----
+
| ``std::string_view``, | STL C++17 string views | :file:`pybind11/pybind11.h`
|
| ``std::u16string_view``, etc. | |
|
+------------------------------------+---------------------------+-------------------------------
----
+
| ``std::pair<T1, T2>`` | Pair of two custom types | :file:`pybind11/pybind11.h`
|
+------------------------------------+---------------------------+-------------------------------
----
+
| ``std::tuple<...>`` | Arbitrary tuple of types | :file:`pybind11/pybind11.h`
|
+------------------------------------+---------------------------+-------------------------------
----
+
| ``std::reference_wrapper<...>`` | Reference type wrapper | :file:`pybind11/pybind11.h`
|
+------------------------------------+---------------------------+-------------------------------
----
+
| ``std::complex<T>`` | Complex numbers | :file:`pybind11/complex.h`
|
+------------------------------------+---------------------------+-------------------------------
----
+
| ``std::array<T, Size>`` | STL static array | :file:`pybind11/stl.h`
|
+------------------------------------+---------------------------+-------------------------------
----
+
| ``std::vector<T>`` | STL dynamic array | :file:`pybind11/stl.h`
|
+------------------------------------+---------------------------+-------------------------------
----
+
| ``std::deque<T>`` | STL double-ended queue | :file:`pybind11/stl.h`
|
+------------------------------------+---------------------------+-------------------------------
----
+
| ``std::valarray<T>`` | STL value array | :file:`pybind11/stl.h`
|
+------------------------------------+---------------------------+-------------------------------
----
+
| ``std::list<T>`` | STL linked list | :file:`pybind11/stl.h`
|
+------------------------------------+---------------------------+-------------------------------
----
+
| ``std::map<T1, T2>`` | STL ordered map | :file:`pybind11/stl.h`
|
+------------------------------------+---------------------------+-------------------------------
----
+
| ``std::unordered_map<T1, T2>`` | STL unordered map | :file:`pybind11/stl.h`
|
+------------------------------------+---------------------------+-------------------------------
----
+
| ``std::set<T>`` | STL ordered set | :file:`pybind11/stl.h`
|
+------------------------------------+---------------------------+-------------------------------
----
+
| ``std::unordered_set<T>`` | STL unordered set | :file:`pybind11/stl.h`
|
+------------------------------------+---------------------------+-------------------------------
----
+
| ``std::optional<T>`` | STL optional type (C++17) | :file:`pybind11/stl.h`
|
+------------------------------------+---------------------------+-------------------------------
----
+
| ``std::experimental::optional<T>`` | STL optional type (exp.) | :file:`pybind11/stl.h`
|
+------------------------------------+---------------------------+-------------------------------
----
+
| ``std::variant<...>`` | Type-safe union (C++17) | :file:`pybind11/stl.h`
|
+------------------------------------+---------------------------+-------------------------------
----
+
| ``std::filesystem::path<T>`` | STL path (C++17) [#]_ | :file:`pybind11/stl
/filesystem.h`
|
+------------------------------------+---------------------------+-------------------------------
----
+
| ``std::function<...>`` | STL polymorphic function | :file:`pybind11/functional.h`
|
+------------------------------------+---------------------------+-------------------------------
----
+
| ``std::chrono::duration<...>`` | STL time duration | :file:`pybind11/chrono.h`
|
+------------------------------------+---------------------------+-------------------------------
----
+
| ``std::chrono::time_point<...>`` | STL date/time | :file:`pybind11/chrono.h`
|
+------------------------------------+---------------------------+-------------------------------
----
+
| ``Eigen::Matrix<...>`` | Eigen: dense matrix | :file:`pybind11/eigen.h`
|
+------------------------------------+---------------------------+-------------------------------
----
+
| ``Eigen::Map<...>`` | Eigen: mapped memory | :file:`pybind11/eigen.h`
|
+------------------------------------+---------------------------+-------------------------------
----
+
| ``Eigen::SparseMatrix<...>`` | Eigen: sparse matrix | :file:`pybind11/eigen.h`
|
+------------------------------------+---------------------------+-------------------------------
----
+
.. [#] ``std::filesystem::path`` is converted to ``pathlib.Path`` and
``os.PathLike`` is converted to ``std::filesystem::path``, but this requires
...
...
docs/advanced/exceptions.rst
View file @
93716147
...
...
@@ -64,7 +64,7 @@ at its exception handler.
+--------------------------------------+--------------------------------------+
Exception translation is not bidirectional. That is, *catching* the C++
exceptions defined above
above
will not trap exceptions that originate from
exceptions defined above will not trap exceptions that originate from
Python. For that, catch :class:`pybind11::error_already_set`. See :ref:`below
<handling_python_exceptions_cpp>` for further details.
...
...
docs/advanced/functions.rst
View file @
93716147
...
...
@@ -306,8 +306,9 @@ The class ``py::args`` derives from ``py::tuple`` and ``py::kwargs`` derives
from ``py::dict``.
You may also use just one or the other, and may combine these with other
arguments as long as the ``py::args`` and ``py::kwargs`` arguments are the last
arguments accepted by the function.
arguments. Note, however, that ``py::kwargs`` must always be the last argument
of the function, and ``py::args`` implies that any further arguments are
keyword-only (see :ref:`keyword_only_arguments`).
Please refer to the other examples for details on how to iterate over these,
and on how to cast their entries into C++ objects. A demonstration is also
...
...
@@ -366,6 +367,8 @@ like so:
py::class_<MyClass>("MyClass")
.def("myFunction", py::arg("arg") = static_cast<SomeType *>(nullptr));
.. _keyword_only_arguments:
Keyword-only arguments
======================
...
...
@@ -397,6 +400,15 @@ feature does *not* require Python 3 to work.
.. versionadded:: 2.6
As of pybind11 2.9, a ``py::args`` argument implies that any following arguments
are keyword-only, as if ``py::kw_only()`` had been specified in the same
relative location of the argument list as the ``py::args`` argument. The
``py::kw_only()`` may be included to be explicit about this, but is not
required. (Prior to 2.9 ``py::args`` may only occur at the end of the argument
list, or immediately before a ``py::kwargs`` argument at the end).
.. versionadded:: 2.9
Positional-only arguments
=========================
...
...
docs/basics.rst
View file @
93716147
...
...
@@ -109,7 +109,7 @@ a file named :file:`example.cpp` with the following contents:
PYBIND11_MODULE(example, m) {
m.doc() = "pybind11 example plugin"; // optional module docstring
m.def("add", &add, "A function
which
adds two numbers");
m.def("add", &add, "A function
that
adds two numbers");
}
.. [#f1] In practice, implementation and binding code will generally be located
...
...
docs/changelog.rst
View file @
93716147
...
...
@@ -7,8 +7,100 @@ Starting with version 1.8.0, pybind11 releases use a `semantic versioning
<http://semver.org>`_ policy.
IN DEVELOPMENT
--------------
Version 2.9.0 (Dec 28, 2021)
----------------------------
This is the last version to support Python 2.7 and 3.5.
New Features:
* Allow ``py::args`` to be followed by other arguments; the remaining arguments
are implicitly keyword-only, as if a ``py::kw_only{}`` annotation had been
used.
`#3402 <https://github.com/pybind/pybind11/pull/3402>`_
* Add C++ Exception type to throw and catch ``AttributeError``. Useful for
defining custom ``__setattr__`` and ``__getattr__`` methods.
`#3387 <https://github.com/pybind/pybind11/pull/3387>`_
Changes:
* Make str/bytes/memoryview more interoperable with ``std::string_view``.
`#3521 <https://github.com/pybind/pybind11/pull/3521>`_
* Replace ``_`` with ``const_name`` in internals, avoid defining ``pybind::_``
if ``_`` defined as macro (common gettext usage)
`#3423 <https://github.com/pybind/pybind11/pull/3423>`_
Bug fixes:
* Fix a regression in 2.8.0 that caused undefined behavior (typically
segfaults) in ``make_key_iterator``/``make_value_iterator`` if dereferencing
the iterator returned a temporary value instead of a reference.
`#3348 <https://github.com/pybind/pybind11/pull/3348>`_
* Fix a rare warning about extra copy in an Eigen constructor.
`#3486 <https://github.com/pybind/pybind11/pull/3486>`_
* Fix caching of the C++ overrides.
`#3465 <https://github.com/pybind/pybind11/pull/3465>`_
* Add missing ``std::forward`` calls to some ``cpp_function`` overloads.
`#3443 <https://github.com/pybind/pybind11/pull/3443>`_
* Support PyPy 7.3.7 and the PyPy3.8 beta. Test python-3.11 on PRs with the
``python dev`` label.
`#3419 <https://github.com/pybind/pybind11/pull/3419>`_
* Fix 2.8.0 regression with MSVC 2017 + C++17 mode + Python 3.
`#3407 <https://github.com/pybind/pybind11/pull/3407>`_
* Modernize usage of ``PyCodeObject`` on Python 3.9 (toward supporting Python
3.11a1)
`#3368 <https://github.com/pybind/pybind11/pull/3368>`_
* A long-standing bug in eigen.h was fixed (originally PR #3343). The bug was
unmasked by newly added ``static_assert``'s in the Eigen 3.4.0 release.
`#3352 <https://github.com/pybind/pybind11/pull/3352>`_
* Replace usage of deprecated ``Eigen::MappedSparseMatrix`` with
``Eigen::Map<Eigen::SparseMatrix<...>>`` for Eigen 3.3+.
`#3499 <https://github.com/pybind/pybind11/pull/3499>`_
* Fixed the potential for dangling references when using properties with
``std::optional`` types.
`#3376 <https://github.com/pybind/pybind11/pull/3376>`_
* Tweaks to support Microsoft Visual Studio 2022.
`#3497 <https://github.com/pybind/pybind11/pull/3497>`_
Build system improvements:
* Nicer CMake printout and IDE organisation for pybind11's own tests.
`#3479 <https://github.com/pybind/pybind11/pull/3479>`_
* CMake: report version type as part of the version string to avoid a spurious
space in the package status message.
`#3472 <https://github.com/pybind/pybind11/pull/3472>`_
* Support multiple raw inclusion of CMake helper files (Conan.io does this for
multi-config generators).
`#3420 <https://github.com/pybind/pybind11/pull/3420>`_
* Fix harmless warning on CMake 3.22.
`#3368 <https://github.com/pybind/pybind11/pull/3368>`_
* Flags starting with ``-g`` in ``$CFLAGS`` and ``$CPPFLAGS`` are no longer
overridden by ``.Pybind11Extension``.
`#3436 <https://github.com/pybind/pybind11/pull/3436>`_
* Ensure ThreadPool is closed in ``setup_helpers``.
`#3548 <https://github.com/pybind/pybind11/pull/3548>`_
* Avoid LTS on ``mips64`` and ``ppc64le`` (reported broken).
`#3557 <https://github.com/pybind/pybind11/pull/3557>`_
v2.8.1 (Oct 27, 2021)
---------------------
...
...
docs/release.rst
View file @
93716147
...
...
@@ -22,6 +22,9 @@ the version just below.
To release a new version of pybind11:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
If you don't have nox, you should either use ``pipx run nox`` instead, or use
``pipx install nox`` or ``brew install nox`` (Unix).
- Update the version number
- Update ``PYBIND11_VERSION_MAJOR`` etc. in
``include/pybind11/detail/common.h``. PATCH should be a simple integer.
...
...
@@ -51,14 +54,12 @@ To release a new version of pybind11:
notifications to users watching releases, and also uploads PyPI packages).
(Note: if you do not use an existing tag, this creates a new lightweight tag
for you, so you could skip the above step.)
- GUI method: Under `releases <https://github.com/pybind/pybind11/releases>`_
click "Draft a new release" on the far right, fill in the tag name
(if you didn't tag above, it will be made here), fill in a release name
like "Version X.Y.Z", and copy-and-paste the markdown-formatted (!) changelog
into the description (usually ``cat docs/changelog.rst | pandoc -f rst -t gfm``).
Check "pre-release" if this is a beta/RC.
- CLI method: with ``gh`` installed, run ``gh release create vX.Y.Z -t "Version X.Y.Z"``
If this is a pre-release, add ``-p``.
...
...
@@ -90,9 +91,7 @@ If you need to manually upload releases, you can download the releases from the
.. code-block:: bash
python3 -m pip install build
python3 -m build
PYBIND11_SDIST_GLOBAL=1 python3 -m build
nox -s build
twine upload dist/*
This makes SDists and wheels, and the final line uploads them.
docs/requirements.txt
View file @
93716147
breathe==4.26.1
# docutils 0.17 breaks HTML tags & RTD theme
# https://github.com/sphinx-doc/sphinx/issues/9001
docutils==0.16
sphinx==3.3.1
sphinx_rtd_theme==0.5.0
sphinxcontrib-moderncmakedomain==3.17
sphinxcontrib-svg2pdfconverter==1.1.0
breathe==4.31.0
sphinx==3.5.4
sphinx_rtd_theme==1.0.0
sphinxcontrib-moderncmakedomain==3.19
sphinxcontrib-svg2pdfconverter==1.1.1
docs/upgrade.rst
View file @
93716147
...
...
@@ -17,6 +17,10 @@ v2.9
converted to using ``py::module_::import("types").attr("SimpleNamespace")``
instead.
* The use of ``_`` in custom type casters can now be replaced with the more
readable ``const_name`` instead. The old ``_`` shortcut has been retained
unless it is being used as a macro (like for gettext).
.. _upgrade-guide-2.7:
...
...
include/pybind11/attr.h
View file @
93716147
...
...
@@ -174,7 +174,7 @@ struct function_record {
function_record
()
:
is_constructor
(
false
),
is_new_style_constructor
(
false
),
is_stateless
(
false
),
is_operator
(
false
),
is_method
(
false
),
has_args
(
false
),
has_kwargs
(
false
),
has_kw_only_args
(
false
),
prepend
(
false
)
{
}
has_kwargs
(
false
),
prepend
(
false
)
{
}
/// Function name
char
*
name
=
nullptr
;
/* why no C++ strings? They generate heavier code.. */
...
...
@@ -221,17 +221,15 @@ struct function_record {
/// True if the function has a '**kwargs' argument
bool
has_kwargs
:
1
;
/// True once a 'py::kw_only' is encountered (any following args are keyword-only)
bool
has_kw_only_args
:
1
;
/// True if this function is to be inserted at the beginning of the overload resolution chain
bool
prepend
:
1
;
/// Number of arguments (including py::args and/or py::kwargs, if present)
std
::
uint16_t
nargs
;
/// Number of trailing arguments (counted in `nargs`) that are keyword-only
std
::
uint16_t
nargs_kw_only
=
0
;
/// Number of leading positional arguments, which are terminated by a py::args or py::kwargs
/// argument or by a py::kw_only annotation.
std
::
uint16_t
nargs_pos
=
0
;
/// Number of leading arguments (counted in `nargs`) that are positional-only
std
::
uint16_t
nargs_pos_only
=
0
;
...
...
@@ -411,20 +409,23 @@ template <> struct process_attribute<is_new_style_constructor> : process_attribu
static
void
init
(
const
is_new_style_constructor
&
,
function_record
*
r
)
{
r
->
is_new_style_constructor
=
true
;
}
};
inline
void
process_kw_only_arg
(
const
arg
&
a
,
function_record
*
r
)
{
if
(
!
a
.
name
||
a
.
name
[
0
]
==
'\0'
)
pybind11_fail
(
"arg(): cannot specify an unnamed argument after an kw_only() annotation"
);
++
r
->
nargs_kw_only
;
inline
void
check_kw_only_arg
(
const
arg
&
a
,
function_record
*
r
)
{
if
(
r
->
args
.
size
()
>
r
->
nargs_pos
&&
(
!
a
.
name
||
a
.
name
[
0
]
==
'\0'
))
pybind11_fail
(
"arg(): cannot specify an unnamed argument after a kw_only() annotation or args() argument"
);
}
inline
void
append_self_arg_if_needed
(
function_record
*
r
)
{
if
(
r
->
is_method
&&
r
->
args
.
empty
())
r
->
args
.
emplace_back
(
"self"
,
nullptr
,
handle
(),
/*convert=*/
true
,
/*none=*/
false
);
}
/// Process a keyword argument attribute (*without* a default value)
template
<
>
struct
process_attribute
<
arg
>
:
process_attribute_default
<
arg
>
{
static
void
init
(
const
arg
&
a
,
function_record
*
r
)
{
if
(
r
->
is_method
&&
r
->
args
.
empty
())
r
->
args
.
emplace_back
(
"self"
,
nullptr
,
handle
(),
true
/*convert*/
,
false
/*none not allowed*/
);
append_self_arg_if_needed
(
r
);
r
->
args
.
emplace_back
(
a
.
name
,
nullptr
,
handle
(),
!
a
.
flag_noconvert
,
a
.
flag_none
);
if
(
r
->
has_kw_only_args
)
process
_kw_only_arg
(
a
,
r
);
check
_kw_only_arg
(
a
,
r
);
}
};
...
...
@@ -432,7 +433,7 @@ template <> struct process_attribute<arg> : process_attribute_default<arg> {
template
<
>
struct
process_attribute
<
arg_v
>
:
process_attribute_default
<
arg_v
>
{
static
void
init
(
const
arg_v
&
a
,
function_record
*
r
)
{
if
(
r
->
is_method
&&
r
->
args
.
empty
())
r
->
args
.
emplace_back
(
"self"
,
nullptr
/*descr*/
,
handle
()
/*parent*/
,
true
/*convert*/
,
false
/*none not allowed*/
);
r
->
args
.
emplace_back
(
"self"
,
/*descr
=
*/
nullptr
,
/*parent
=
*/
handle
(),
/*convert
=
*/
true
,
/*none=*/
false
);
if
(
!
a
.
value
)
{
#if !defined(NDEBUG)
...
...
@@ -457,21 +458,28 @@ template <> struct process_attribute<arg_v> : process_attribute_default<arg_v> {
}
r
->
args
.
emplace_back
(
a
.
name
,
a
.
descr
,
a
.
value
.
inc_ref
(),
!
a
.
flag_noconvert
,
a
.
flag_none
);
if
(
r
->
has_kw_only_args
)
process
_kw_only_arg
(
a
,
r
);
check
_kw_only_arg
(
a
,
r
);
}
};
/// Process a keyword-only-arguments-follow pseudo argument
template
<
>
struct
process_attribute
<
kw_only
>
:
process_attribute_default
<
kw_only
>
{
static
void
init
(
const
kw_only
&
,
function_record
*
r
)
{
r
->
has_kw_only_args
=
true
;
append_self_arg_if_needed
(
r
);
if
(
r
->
has_args
&&
r
->
nargs_pos
!=
static_cast
<
std
::
uint16_t
>
(
r
->
args
.
size
()))
pybind11_fail
(
"Mismatched args() and kw_only(): they must occur at the same relative argument location (or omit kw_only() entirely)"
);
r
->
nargs_pos
=
static_cast
<
std
::
uint16_t
>
(
r
->
args
.
size
());
}
};
/// Process a positional-only-argument maker
template
<
>
struct
process_attribute
<
pos_only
>
:
process_attribute_default
<
pos_only
>
{
static
void
init
(
const
pos_only
&
,
function_record
*
r
)
{
append_self_arg_if_needed
(
r
);
r
->
nargs_pos_only
=
static_cast
<
std
::
uint16_t
>
(
r
->
args
.
size
());
if
(
r
->
nargs_pos_only
>
r
->
nargs_pos
)
pybind11_fail
(
"pos_only(): cannot follow a py::args() argument"
);
// It also can't follow a kw_only, but a static_assert in pybind11.h checks that
}
};
...
...
include/pybind11/cast.h
View file @
93716147
...
...
@@ -27,23 +27,6 @@
#include <utility>
#include <vector>
#if defined(PYBIND11_CPP17)
# if defined(__has_include)
# if __has_include(<string_view>)
# define PYBIND11_HAS_STRING_VIEW
# endif
# elif defined(_MSC_VER)
# define PYBIND11_HAS_STRING_VIEW
# endif
#endif
#ifdef PYBIND11_HAS_STRING_VIEW
#include <string_view>
#endif
#if defined(__cpp_lib_char8_t) && __cpp_lib_char8_t >= 201811L
# define PYBIND11_HAS_U8STRING
#endif
PYBIND11_NAMESPACE_BEGIN
(
PYBIND11_NAMESPACE
)
PYBIND11_NAMESPACE_BEGIN
(
detail
)
...
...
@@ -150,7 +133,8 @@ public:
return
false
;
}
else
{
handle
src_or_index
=
src
;
#if PY_VERSION_HEX < 0x03080000
// PyPy: 7.3.7's 3.8 does not implement PyLong_*'s __index__ calls.
#if PY_VERSION_HEX < 0x03080000 || defined(PYPY_VERSION)
object
index
;
if
(
!
PYBIND11_LONG_CHECK
(
src
.
ptr
()))
{
// So: index_check(src.ptr())
index
=
reinterpret_steal
<
object
>
(
PyNumber_Index
(
src
.
ptr
()));
...
...
@@ -224,7 +208,7 @@ public:
return
PyLong_FromUnsignedLongLong
((
unsigned
long
long
)
src
);
}
PYBIND11_TYPE_CASTER
(
T
,
_
<
std
::
is_integral
<
T
>::
value
>
(
"int"
,
"float"
));
PYBIND11_TYPE_CASTER
(
T
,
const_name
<
std
::
is_integral
<
T
>::
value
>
(
"int"
,
"float"
));
};
template
<
typename
T
>
struct
void_caster
{
...
...
@@ -237,7 +221,7 @@ public:
static
handle
cast
(
T
,
return_value_policy
/* policy */
,
handle
/* parent */
)
{
return
none
().
inc_ref
();
}
PYBIND11_TYPE_CASTER
(
T
,
_
(
"None"
));
PYBIND11_TYPE_CASTER
(
T
,
const_name
(
"None"
));
};
template
<
>
class
type_caster
<
void_type
>
:
public
void_caster
<
void_type
>
{};
...
...
@@ -280,7 +264,7 @@ public:
template
<
typename
T
>
using
cast_op_type
=
void
*&
;
explicit
operator
void
*&
()
{
return
value
;
}
static
constexpr
auto
name
=
_
(
"capsule"
);
static
constexpr
auto
name
=
const_name
(
"capsule"
);
private:
void
*
value
=
nullptr
;
};
...
...
@@ -331,7 +315,7 @@ public:
static
handle
cast
(
bool
src
,
return_value_policy
/* policy */
,
handle
/* parent */
)
{
return
handle
(
src
?
Py_True
:
Py_False
).
inc_ref
();
}
PYBIND11_TYPE_CASTER
(
bool
,
_
(
"bool"
));
PYBIND11_TYPE_CASTER
(
bool
,
const_name
(
"bool"
));
};
// Helper class for UTF-{8,16,32} C++ stl strings:
...
...
@@ -421,7 +405,7 @@ template <typename StringType, bool IsView = false> struct string_caster {
return
s
;
}
PYBIND11_TYPE_CASTER
(
StringType
,
_
(
PYBIND11_STRING_NAME
));
PYBIND11_TYPE_CASTER
(
StringType
,
const_name
(
PYBIND11_STRING_NAME
));
private:
static
handle
decode_utfN
(
const
char
*
buffer
,
ssize_t
nbytes
)
{
...
...
@@ -558,7 +542,7 @@ public:
return
one_char
;
}
static
constexpr
auto
name
=
_
(
PYBIND11_STRING_NAME
);
static
constexpr
auto
name
=
const_name
(
PYBIND11_STRING_NAME
);
template
<
typename
_T
>
using
cast_op_type
=
pybind11
::
detail
::
cast_op_type
<
_T
>
;
};
...
...
@@ -595,7 +579,7 @@ public:
return
cast
(
*
src
,
policy
,
parent
);
}
static
constexpr
auto
name
=
_
(
"Tuple["
)
+
concat
(
make_caster
<
Ts
>::
name
...)
+
_
(
"]"
);
static
constexpr
auto
name
=
const_name
(
"Tuple["
)
+
concat
(
make_caster
<
Ts
>::
name
...)
+
const_name
(
"]"
);
template
<
typename
T
>
using
cast_op_type
=
type
;
...
...
@@ -780,14 +764,14 @@ template <typename base, typename holder> struct is_holder_type :
template
<
typename
base
,
typename
deleter
>
struct
is_holder_type
<
base
,
std
::
unique_ptr
<
base
,
deleter
>>
:
std
::
true_type
{};
template
<
typename
T
>
struct
handle_type_name
{
static
constexpr
auto
name
=
_
<
T
>
();
};
template
<
>
struct
handle_type_name
<
bytes
>
{
static
constexpr
auto
name
=
_
(
PYBIND11_BYTES_NAME
);
};
template
<
>
struct
handle_type_name
<
int_
>
{
static
constexpr
auto
name
=
_
(
"int"
);
};
template
<
>
struct
handle_type_name
<
iterable
>
{
static
constexpr
auto
name
=
_
(
"Iterable"
);
};
template
<
>
struct
handle_type_name
<
iterator
>
{
static
constexpr
auto
name
=
_
(
"Iterator"
);
};
template
<
>
struct
handle_type_name
<
none
>
{
static
constexpr
auto
name
=
_
(
"None"
);
};
template
<
>
struct
handle_type_name
<
args
>
{
static
constexpr
auto
name
=
_
(
"*args"
);
};
template
<
>
struct
handle_type_name
<
kwargs
>
{
static
constexpr
auto
name
=
_
(
"**kwargs"
);
};
template
<
typename
T
>
struct
handle_type_name
{
static
constexpr
auto
name
=
const_name
<
T
>
();
};
template
<
>
struct
handle_type_name
<
bytes
>
{
static
constexpr
auto
name
=
const_name
(
PYBIND11_BYTES_NAME
);
};
template
<
>
struct
handle_type_name
<
int_
>
{
static
constexpr
auto
name
=
const_name
(
"int"
);
};
template
<
>
struct
handle_type_name
<
iterable
>
{
static
constexpr
auto
name
=
const_name
(
"Iterable"
);
};
template
<
>
struct
handle_type_name
<
iterator
>
{
static
constexpr
auto
name
=
const_name
(
"Iterator"
);
};
template
<
>
struct
handle_type_name
<
none
>
{
static
constexpr
auto
name
=
const_name
(
"None"
);
};
template
<
>
struct
handle_type_name
<
args
>
{
static
constexpr
auto
name
=
const_name
(
"*args"
);
};
template
<
>
struct
handle_type_name
<
kwargs
>
{
static
constexpr
auto
name
=
const_name
(
"**kwargs"
);
};
template
<
typename
type
>
struct
pyobject_caster
{
...
...
@@ -1130,6 +1114,9 @@ constexpr arg operator"" _a(const char *name, size_t) { return arg(name); }
PYBIND11_NAMESPACE_BEGIN
(
detail
)
template
<
typename
T
>
using
is_kw_only
=
std
::
is_same
<
intrinsic_t
<
T
>
,
kw_only
>
;
template
<
typename
T
>
using
is_pos_only
=
std
::
is_same
<
intrinsic_t
<
T
>
,
pos_only
>
;
// forward declaration (definition in attr.h)
struct
function_record
;
...
...
@@ -1165,17 +1152,18 @@ class argument_loader {
template
<
typename
Arg
>
using
argument_is_args
=
std
::
is_same
<
intrinsic_t
<
Arg
>
,
args
>
;
template
<
typename
Arg
>
using
argument_is_kwargs
=
std
::
is_same
<
intrinsic_t
<
Arg
>
,
kwargs
>
;
// Get args/kwargs argument positions relative to the end of the argument list:
static
constexpr
auto
args_pos
=
constexpr_first
<
argument_is_args
,
Args
...
>
()
-
(
int
)
sizeof
...(
Args
),
kwargs_pos
=
constexpr_first
<
argument_is_kwargs
,
Args
...
>
()
-
(
int
)
sizeof
...(
Args
);
static
constexpr
bool
args_kwargs_are_last
=
kwargs_pos
>=
-
1
&&
args_pos
>=
kwargs_pos
-
1
;
// Get kwargs argument position, or -1 if not present:
static
constexpr
auto
kwargs_pos
=
constexpr_last
<
argument_is_kwargs
,
Args
...
>
();
static_assert
(
args_
kwargs_are_last
,
"py::args/
py::kwargs
are
only permitted as the last argument
(s)
of a function"
);
static_assert
(
kw
args_
pos
==
-
1
||
kwargs_pos
==
(
int
)
sizeof
...(
Args
)
-
1
,
"
py::kwargs
is
only permitted as the last argument of a function"
);
public:
static
constexpr
bool
has_kwargs
=
kwargs_pos
<
0
;
static
constexpr
bool
has_args
=
args_pos
<
0
;
static
constexpr
bool
has_kwargs
=
kwargs_pos
!=
-
1
;
// py::args argument position; -1 if not present.
static
constexpr
int
args_pos
=
constexpr_last
<
argument_is_args
,
Args
...
>
();
static_assert
(
args_pos
==
-
1
||
args_pos
==
constexpr_first
<
argument_is_args
,
Args
...
>
(),
"py::args cannot be specified more than once"
);
static
constexpr
auto
arg_names
=
concat
(
type_descr
(
make_caster
<
Args
>::
name
)...);
...
...
include/pybind11/chrono.h
View file @
93716147
...
...
@@ -97,7 +97,7 @@ public:
return
PyDelta_FromDSU
(
dd
.
count
(),
ss
.
count
(),
us
.
count
());
}
PYBIND11_TYPE_CASTER
(
type
,
_
(
"datetime.timedelta"
));
PYBIND11_TYPE_CASTER
(
type
,
const_name
(
"datetime.timedelta"
));
};
inline
std
::
tm
*
localtime_thread_safe
(
const
std
::
time_t
*
time
,
std
::
tm
*
buf
)
{
...
...
@@ -195,7 +195,7 @@ public:
localtime
.
tm_sec
,
us
.
count
());
}
PYBIND11_TYPE_CASTER
(
type
,
_
(
"datetime.datetime"
));
PYBIND11_TYPE_CASTER
(
type
,
const_name
(
"datetime.datetime"
));
};
// Other clocks that are not the system clock are not measured as datetime.datetime objects
...
...
include/pybind11/complex.h
View file @
93716147
...
...
@@ -59,7 +59,7 @@ public:
return
PyComplex_FromDoubles
((
double
)
src
.
real
(),
(
double
)
src
.
imag
());
}
PYBIND11_TYPE_CASTER
(
std
::
complex
<
T
>
,
_
(
"complex"
));
PYBIND11_TYPE_CASTER
(
std
::
complex
<
T
>
,
const_name
(
"complex"
));
};
PYBIND11_NAMESPACE_END
(
detail
)
PYBIND11_NAMESPACE_END
(
PYBIND11_NAMESPACE
)
Prev
1
2
3
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment