Commit Graph

2878 Commits

Author SHA1 Message Date
Henry Schreiner
9591cfb0b8
fix(cmake): findpython issues and 3.12 support for pybind11_find_import (#4941)
* fix(cmake): findpython issues and 3.12 support for pybind11_find_import

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>

* Update pybind11NewTools.cmake

---------

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
2023-11-16 00:54:47 -05:00
Henry Schreiner
6831666f5c
ci: add more versions of numpy/scipy/pypy (#4714)
* ci: add more versions of numpy/scipy/pypy

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>

* Apply suggestions from code review

* style: pre-commit fixes

* Update requirements.txt

* Update requirements.txt

* Apply suggestions from code review

---------

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-11-16 00:52:05 -05:00
Henry Schreiner
6cf90e7286
fix(cmake): avoid really slow compile on emscripten (#4642)
* fix: avoid really slow compile on emscripten

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>

* Update tools/pybind11Common.cmake

---------

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
2023-11-16 00:50:15 -05:00
Henry Schreiner
b389ae77cb
chore: update changelog script for categories (#4942) 2023-11-15 18:59:07 -05:00
Ralf W. Grosse-Kunstleve
2376f6e953 Use py::handle instead of py::object to avoid clang-tidy errors. 2023-11-14 23:46:42 -08:00
Ralf W. Grosse-Kunstleve
79f6bdca36 Replace .stl_binders. with .cases_for_stubgen. 2023-11-14 23:40:33 -08:00
Ralf W. Grosse-Kunstleve
1a2e8a6624 C++11 compatibility. 2023-11-14 23:35:28 -08:00
Ralf W. Grosse-Kunstleve
69dac469fe Add m.basics tests in ntest_cases_for_stubgen.py 2023-11-14 23:19:48 -08:00
Ralf W. Grosse-Kunstleve
1fa0065967 pre-commit clang-format, NO manual changes. 2023-11-14 22:55:01 -08:00
Ralf W. Grosse-Kunstleve
644d15054e Minimal changes to make the basics code build. 2023-11-14 22:52:49 -08:00
Ralf W. Grosse-Kunstleve
1b4fa7172b Unmodified copy of c6cb3c6282/test-data/pybind11_mypy_demo/src/main.cpp 2023-11-14 22:50:34 -08:00
Ralf W. Grosse-Kunstleve
d1694d9ac5 Use locally defined bindings to avoid dependency on test_stl. 2023-11-14 22:44:42 -08:00
Ralf W. Grosse-Kunstleve
e5f210e61b Rename user_type to UserType 2023-11-14 14:08:59 -08:00
Ralf W. Grosse-Kunstleve
11040768ca Add Annotated[Any, "..."] wrapping in type_info_description() 2023-11-14 13:50:20 -08:00
Ralf W. Grosse-Kunstleve
61ee34ee07 Pull in Annotated[list[int], FixedSize(2)] from test_stl 2023-11-14 13:23:11 -08:00
Ralf W. Grosse-Kunstleve
781304e431 Add test_cases_for_stubgen
Material to inform https://github.com/python/mypy/issues/16306
2023-11-14 13:14:14 -08:00
Ralf W. Grosse-Kunstleve
0b984334d9 Remove CppTypePybind11() wrapping for now. 2023-11-14 12:59:19 -08:00
Ralf W. Grosse-Kunstleve
9548fa5e4e Merge branch 'master' into annotated_any 2023-11-11 08:56:35 -08:00
Ralf W. Grosse-Kunstleve
e250155afa
Fix a long-standing bug in the handling of Python multiple inheritance (#4762)
* Equivalent of 5718e4d080

* Resolve clang-tidy errors.

* Moving test_PPCCInit() first changes the behavior!

* Resolve new Clang dev C++11 errors:

```
The CXX compiler identification is Clang 17.0.0
```

```
pytypes.h:1615:23: error: identifier '_s' preceded by whitespace in a literal operator declaration is deprecated [-Werror,-Wdeprecated-literal-operator]
```

```
cast.h:1380:26: error: identifier '_a' preceded by whitespace in a literal operator declaration is deprecated [-Werror,-Wdeprecated-literal-operator]
```

* Resolve gcc 4.8.5 error:

```
pytypes.h:1615:12: error: missing space between '""' and suffix identifier
```

* Specifically exclude `__clang__`

* Snapshot of debugging code (does NOT pass pre-commit checks).

* Revert "Snapshot of debugging code (does NOT pass pre-commit checks)."

This reverts commit 1d4f9ff263.

* [ci skip] Order Dependence Demo

* Revert "[ci skip] Order Dependence Demo"

This reverts commit d37b5409d4.

* One way to deal with the order dependency issue. This is not the best way, more like a proof of concept.

* Move test_PC() first again.

* Add `all_type_info_add_base_most_derived_first()`, use in `all_type_info_populate()`

* Revert "One way to deal with the order dependency issue. This is not the best way, more like a proof of concept."

This reverts commit eb09c6c1b9.

* clang-tidy fixes (automatic)

* Add `is_redundant_value_and_holder()` and use to avoid forcing `__init__` overrides when they are not needed.

* Streamline implementation and avoid unsafe `reinterpret_cast<instance *>()` introduced with PR #2152

The `reinterpret_cast<instance *>(self)` is unsafe if `__new__` is mocked,
which was actually found in the wild: the mock returned `None` for `self`.
This was inconsequential because `inst` is currently cast straight back to
`PyObject *` to compute `all_type_info()`, which is empty if `self` is not
a pybind11 `instance`, and then `inst` is never dereferenced. However, the
unsafe detour through `instance *` is easily avoided and the updated
implementation is less prone to accidents while debugging or refactoring.

* Fix actual undefined behavior exposed by previous changes.

It turns out the previous commit message is incorrect, the `inst` pointer is actually dereferenced, in the `value_and_holder` ctor here:

f3e0602802/include/pybind11/detail/type_caster_base.h (L262-L263)

```
259     // Main constructor for a found value/holder:
260     value_and_holder(instance *i, const detail::type_info *type, size_t vpos, size_t index)
261         : inst{i}, index{index}, type{type},
262           vh{inst->simple_layout ? inst->simple_value_holder
263                                  : &inst->nonsimple.values_and_holders[vpos]} {}
```

* Add test_mock_new()

* Experiment: specify indirect bases

* Revert "Experiment: specify indirect bases"

This reverts commit 4f90d85f9f.

* Add `all_type_info_check_for_divergence()` and some tests.

* Call `all_type_info_check_for_divergence()` also from `type_caster_generic::load_impl<>`

* Resolve clang-tidy error:

```
include/pybind11/detail/type_caster_base.h:795:21: error: the 'empty' method should be used to check for emptiness instead of 'size' [readability-container-size-empty,-warnings-as-errors]
                if (matching_bases.size() != 0) {
                    ^~~~~~~~~~~~~~~~~~~~~~~~~~
                    !matching_bases.empty()
```

* Revert "Resolve clang-tidy error:"

This reverts commit df27188dc6.

* Revert "Call `all_type_info_check_for_divergence()` also from `type_caster_generic::load_impl<>`"

This reverts commit 5f5fd6a68e.

* Revert "Add `all_type_info_check_for_divergence()` and some tests."

This reverts commit 0a9599f775.
2023-11-08 12:44:04 -08:00
Ralf W. Grosse-Kunstleve
2c35fde389
Fix refcount bug introduced with PR #4916. (#4927)
https://github.com/pybind/pybind11/pull/4916/files#r1387035547
2023-11-08 11:16:10 -08:00
Henry Schreiner
c758b81f3b
chore: move to ruff-format (#4912)
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
Co-authored-by: Ralf W. Grosse-Kunstleve <rwgk@google.com>
2023-11-07 23:42:54 -08:00
pre-commit-ci[bot]
0a974fed54
chore(deps): update pre-commit hooks (#4923)
updates:
- [github.com/pre-commit/mirrors-clang-format: v17.0.3 → v17.0.4](https://github.com/pre-commit/mirrors-clang-format/compare/v17.0.3...v17.0.4)
- [github.com/astral-sh/ruff-pre-commit: v0.1.2 → v0.1.4](https://github.com/astral-sh/ruff-pre-commit/compare/v0.1.2...v0.1.4)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-11-07 22:59:52 -08:00
cyyever
f2606930bf
Use newer PyCode API and other fixes (#4916)
* Use PyCode API

* style: pre-commit fixes

* Free locals

* Fix PY_VERSION_HEX check

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-11-05 14:08:32 -08:00
Social_Mean
31b0a5d94f fix doc typo 2023-11-03 23:51:16 -04:00
Axel Huebl
76b7f53649
Python_ADDITIONAL_VERSIONS: 3.12 (#4909)
Add 3.12 to the default `Python_ADDITIONAL_VERSIONS`.
2023-10-31 22:56:16 -04:00
Henry Schreiner
a18c10f690
fix(cmake): make library component optional (#4805)
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
2023-10-27 11:02:05 -04:00
Henry Schreiner
3aece819fd
chore: update hooks and Ruff config (#4904)
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
2023-10-27 01:26:28 -04:00
Chun Yang
1e28599e41
fix: Add missing spaces to error string (#4906)
* [minor] Add a missing space

Add a missing space to error message

* Add space after period, always add newline.
2023-10-26 20:40:19 -07:00
Mattias Ellert
fa27d2fd43
Adapt to changed function name in Python 3.13 (#4902)
According to https://docs.python.org/3.13/whatsnew/3.13.html:

Add PyThreadState_GetUnchecked() function: similar to
PyThreadState_Get(), but don't kill the process with a fatal error if
it is NULL. The caller is responsible to check if the result is
NULL. Previously, the function was private and known as
_PyThreadState_UncheckedGet().
2023-10-24 09:46:26 -07:00
Ralf W. Grosse-Kunstleve
acfd64605c Merge branch 'master' into annotated_any 2023-10-23 15:42:03 -07:00
Ralf W. Grosse-Kunstleve
bf88e29c95
Bug fix: Replace bare static exception<T> with gil_safe_call_once_and_store. (#4897)
This is to ensure that `Py_DECREF()` is not called after the Python interpreter was finalized already:

3414c56b6c/include/pybind11/gil_safe_call_once.h (L19)
2023-10-23 12:51:04 -07:00
Ralf W. Grosse-Kunstleve
169b0e57eb Add test returning py::exception<void> (fails at runtime).
Passing `py::exception<void>` does not compile:

```
pytypes.h:459:36: error: could not convert ‘{h, pybind11::object::borrowed_t()}’ from ‘<brace-enclosed initializer list>’ to ‘pybind11::exception<void>’
  459 |     return {h, object::borrowed_t{}};
```
2023-10-22 09:14:33 -07:00
Ralf W. Grosse-Kunstleve
6a3a954a6b Add missing handle_type_name<dtype>.
Discovered via manual inspection by @sizmailov:

https://github.com/pybind/pybind11/pull/4888#issuecomment-1774023960

NOTE: This is actually a bug fix, in its own right.
2023-10-22 07:59:06 -07:00
Ralf W. Grosse-Kunstleve
74817b7f9f Add missing handle_type_name<module_>.
Discovered via manual inspection by @sizmailov:

https://github.com/pybind/pybind11/pull/4888#issuecomment-1774023960

NOTE: This is actually a bug fix, in its own right.
2023-10-22 07:59:05 -07:00
Ralf W. Grosse-Kunstleve
3c20944355 Add missing handle_type_name<> specializations for bytearray, memoryview, type.
Discovered via manual inspection by @sizmailov:

https://github.com/pybind/pybind11/pull/4888#issuecomment-1774023960
2023-10-22 07:58:45 -07:00
Ralf W. Grosse-Kunstleve
63a48815fc Add missing handle_type_name<slice> specialization (discovered only through global testing). 2023-10-21 23:55:33 -07:00
Ralf W. Grosse-Kunstleve
7c8991a0a0 Use Union[set, frozenset] for internal consistency. 2023-10-21 13:03:25 -07:00
Ralf W. Grosse-Kunstleve
ace70b077f Render anyset as set | frozenset as suggested by @sizmailov:
https://github.com/pybind/pybind11/pull/4888#discussion_r1367785281
2023-10-21 12:43:08 -07:00
Ralf W. Grosse-Kunstleve
70a510c305 Adjust test_numpy_dtypes test_signature to new behavior. 2023-10-21 11:22:40 -07:00
Ralf W. Grosse-Kunstleve
7280380378 Fix handle_type_name<anyset> as suggested by @sizmailov:
https://github.com/pybind/pybind11/pull/4888#discussion_r1367775289

NOTE: This is actually a bug fix, in its own right.
2023-10-21 11:22:40 -07:00
Ralf W. Grosse-Kunstleve
199532e989 Reapply "Add struct handle_type_name<...> specializations for object, list, etc."
This reverts commit 794d97e54e.
2023-10-21 11:09:39 -07:00
Ralf W. Grosse-Kunstleve
bb8709a0d6 Remove cpp_name_needs_typing_annotated(). Preparation for bringing back commit 76b4a34aff. 2023-10-21 11:09:09 -07:00
Ralf W. Grosse-Kunstleve
90b3912b9f Merge branch 'master' into annotated_any 2023-10-21 11:05:07 -07:00
Alexander Grund
3414c56b6c
Workaround NVCC parse failure in cast_op (#4893)
* Workaround NVCC parse failure in `cast_op`

There is a bug in some CUDA versions (observed in CUDA 12.1 and 11.7 w/ GCC 12.2),
that makes `cast_op` fail to compile:
  `cast.h:45:120: error: expected template-name before ‘<’ token`

Defining the nested type as an alias and using it allows this to work
without any change in semantics.

Fixes #4606

* style: pre-commit fixes

* Add comments to result_t referencing PR

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-10-21 10:50:14 -07:00
Ralf W. Grosse-Kunstleve
272152e68b Annotated[Any, CppTypePybind11("cpp_namespace::UserType")] based on a suggestion by @sizmailov
https://github.com/pybind/pybind11/pull/4888#issuecomment-1773618327
2023-10-20 22:10:57 -07:00
Ralf W. Grosse-Kunstleve
ea00323beb Merge branch 'master' into annotated_any 2023-10-19 23:22:37 -07:00
Ralf W. Grosse-Kunstleve
7969049de4
Comment out failing job, with link to #4889 (#4890) 2023-10-19 23:12:37 -07:00
Ralf W. Grosse-Kunstleve
f6ae40bd07 clang-tidy compatibility 2023-10-19 21:54:15 -07:00
Ralf W. Grosse-Kunstleve
2cafdab279 Add cpp_name_needs_typing_annotated() 2023-10-19 16:18:24 -07:00
Ralf W. Grosse-Kunstleve
794d97e54e Revert "Add struct handle_type_name<...> specializations for object, list, etc."
This reverts commit 76b4a34aff.
2023-10-19 15:45:57 -07:00