Commit graph

5078 commits

Author SHA1 Message Date
bors[bot] 064e52ab66
Merge #2976
2976: Update Example projects r=adamreichold a=kngwyu

Interestingly, it may be used for ChatGPT 😅 
Also I removed my old project because it's way too outdated (around pyo3 0.10?)



Co-authored-by: Yuji Kanagawa <yuji.kngw.80s.revive@gmail.com>
2023-02-22 06:15:21 +00:00
Yuji Kanagawa dd7ac28b11
Update Example projects
Interestingly, it may be used for ChatGPT 😅 
Also I removed my old project because it's way too outdated (around pyo3 0.10?)
2023-02-22 14:31:44 +09:00
bors[bot] bd07ecc91d
Merge #2952
2952: Fix allow_threads segfault r=davidhewitt a=OliverBalfour

Please see the corresponding issue **#2951** for details. This PR adds the failing test from the issue and then a fix for it. The fix simply calls `ReferencePool::update_counts` at the end of `allow_threads` to ensure objects aren't accidentally deleted too soon.

Co-authored-by: Oliver Balfour <oliver.leo.balfour@gmail.com>
2023-02-21 08:46:06 +00:00
Oliver Balfour 83f5fa2902 update reference pool counts at the end of allow_threads to avoid use-after-free 2023-02-21 08:44:48 +00:00
bors[bot] b6d3627c91
Merge #2964
2964: Update `README.md` by adding datafusion, ballista and delta-rs r=adamreichold a=iajoiner

Add Python bindings of datafusion, ballista and the official Rust implementation of Delta Lake (delta-rs). The former two are Apache projects under Arrow and the last is from Delta Lake itself so all three projects are notable and need to be added as examples.

Co-authored-by: Ian Alexander Joiner <14581281+iajoiner@users.noreply.github.com>
2023-02-20 16:14:17 +00:00
Ian Alexander Joiner 7a0cca5a90 Fix description to match maturin and reorder examples 2023-02-20 10:46:29 -05:00
bors[bot] 2082cdc63e
Merge #2966
2966: Correct documentation for `Py::borrow_mut()`. r=adamreichold a=Enyium

Closes #2958.


Co-authored-by: Enyium <123484196+Enyium@users.noreply.github.com>
2023-02-19 20:20:45 +00:00
Enyium d700754917
Correct documentation for Py::borrow_mut(). 2023-02-19 21:12:06 +01:00
Ian Alexander Joiner 64227bf5a4
Update README.md by adding datafusion, ballista and delta-rs 2023-02-19 12:38:08 -05:00
bors[bot] f5f688dd68
Merge #2961
2961: docs: fix typo in method name r=adamreichold a=lycantropos

There's no `PyFunction::new_closure`, but there is [`PyCFunction::new_closure`](3b2c175f8d/src/types/function.rs (L50-L104)), so I guess it's a typo in docs.

Co-authored-by: Azat Ibrakov <azatibrakov@gmail.com>
2023-02-18 21:07:25 +00:00
Azat Ibrakov 9f7368922f docs: fix typo in method name 2023-02-18 22:02:05 +01:00
bors[bot] 3b2c175f8d
Merge #2947
2947: change PyModule::add_class to return an error if class creation fails r=adamreichold a=davidhewitt

Related to #2942 

At the moment there are panics deep in the `#[pyclass]` machinery when initialising the type fails. This PR adjusts a number of these functions to return `PyResult` instead, so that we can handle the error more appropriately further down the pipeline.

For example, take the following snippet:

```rust
#[pyclass(extends = PyBool)]
struct ExtendsBool;

#[pymodule]
fn pyo3_scratch(_py: Python, m: &PyModule) -> PyResult<()> {
    m.add_class::<ExtendsBool>()?;
    Ok(())
}
```

Currently, importing this module will fail with a panic:

```
TypeError: type 'bool' is not an acceptable base type
thread '<unnamed>' panicked at 'An error occurred while initializing class ExtendsBool', /Users/david/Dev/pyo3/src/pyclass.rs:412:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/david/.virtualenvs/pyo3/lib/python3.10/site-packages/pyo3_scratch/__init__.py", line 1, in <module>
    from .pyo3_scratch import *
pyo3_runtime.PanicException: An error occurred while initializing class ExtendsBool
```

After this PR, this import still fails, but with a slightly cleaner, more Pythonic error:

```
TypeError: type 'bool' is not an acceptable base type

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/david/.virtualenvs/pyo3/lib/python3.10/site-packages/pyo3_scratch/__init__.py", line 1, in <module>
    from .pyo3_scratch import *
RuntimeError: An error occurred while initializing class ExtendsBool
```

Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
Co-authored-by: Adam Reichold <adam.reichold@t-online.de>
2023-02-18 16:12:17 +00:00
Adam Reichold 577570e8c4 Reduce visibility of CaptureStdErr type to avoid warnings on older toolchains. 2023-02-18 17:11:40 +01:00
David Hewitt c7cc48f8e4 use PyO3 types within LazyTypeObject 2023-02-18 09:06:36 +00:00
bors[bot] c858ced8d4
Merge #2944
2944: optimize sequence conversion for list and tuple r=adamreichold a=davidhewitt

closes #2943 

Avoid using `PyObject_IsInstance` for checking if lists or tuples are sequences, as we know they are always sequences.

Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2023-02-15 23:16:35 +00:00
bors[bot] 18e7094ccc
Merge #2954
2954: optimize mapping conversion for dict r=davidhewitt a=davidhewitt

Equivalent of #2944 for dicts -> mapping.

The benchmark diff is not as significant as in #2944. Still something like 80ns -> 2ns on my machine.

Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2023-02-15 22:27:36 +00:00
bors[bot] 03ecb805ad
Merge #2955
2955: add pydantic's use of Rust to README r=davidhewitt a=davidhewitt

Adding links to Pydantic to PyO3's readme - if you're ok with this `@samuelcolvin` ? :)

Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2023-02-15 08:32:08 +00:00
David Hewitt 4a41917365 add benchmarks for sequence conversions 2023-02-15 08:28:29 +00:00
David Hewitt ff48b0f18e optimize sequence conversion for list and tuple 2023-02-15 08:28:29 +00:00
David Hewitt 59630beb51 add benchmark for mapping conversion from dicts 2023-02-15 08:27:18 +00:00
David Hewitt 40709db801 optimize mapping conversion for dict 2023-02-15 08:27:18 +00:00
David Hewitt d15b768a6f add pydantic's use of Rust to README 2023-02-15 08:21:25 +00:00
David Hewitt 00ddd21535 change PyModule::add_class to return an error if class creation fails 2023-02-14 22:08:35 +00:00
bors[bot] d0d944cab4
Merge #2953
2953: set csv minimal package version for 1.48 CI r=davidhewitt a=davidhewitt

New `csv 1.2.0` requires Rust 1.60.

Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2023-02-14 19:37:36 +00:00
David Hewitt 54f8322125 set csv minimal package version for 1.48 CI 2023-02-14 19:32:37 +00:00
bors[bot] 0c3bfd2d9a
Merge #2948
2948: don't parse doc attributes unnecessarily r=davidhewitt a=davidhewitt

While working on #2866 I found that for all `#[pymethods]` we process the `#[doc]` attributes and build a Python docstring. However we don't always emit this doc - e.g. for class attributes and `__dunder__` methods.

This is just a small adjustment to move the `#[doc]` processing slightly later in the macro code to avoid the wasted work. (It also helps for the #2866 implementation later.)

Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2023-02-13 21:43:24 +00:00
David Hewitt 201964ce3b don't parse doc attributes unnecessarily 2023-02-13 21:05:44 +00:00
bors[bot] 0820c95cb5
Merge #2945
2945: move some private internals out of public implementation r=davidhewitt a=davidhewitt

This runs some quick cleanups on private stuff:
- Remove `#[doc(hidden)]` trait `TryFromPyCell` which is unused.
- Move `#[doc(hidden)]` struct `pyo3::type_object::LazyStaticType` to `pyo3::impl_::pyclass::LazyStaticType`.
- Move `pub(crate)` function `pyo3::pyclass::create_type_object` into submodule, to clean up main `pyclass.rs` implementation for readers.

As this is no behaviour change and separates stuff out slightly better, I'm just going to proceed to merge this. If anyone reading this wants to suggest a different way to factor out, happy to write a follow-up PR.

Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2023-02-11 21:33:45 +00:00
David Hewitt dbeb3b4453 move some private internals out of public implementation 2023-02-11 21:28:27 +00:00
bors[bot] 6757391918
Merge #2939
2939: Disable default features of `chrono` r=adamreichold a=messense

To avoid bringing `time` v0.1.x into dependency graph, see https://github.com/time-rs/time/issues/293

Co-authored-by: messense <messense@icloud.com>
2023-02-09 13:48:07 +00:00
messense 2ac6006ec8
Disable default features of chrono
To avoid bringing `time` v0.1.x into dependency graph, see https://github.com/time-rs/time/issues/293
2023-02-09 21:27:31 +08:00
bors[bot] 5d1e2198a3
Merge #2938
2938: release notes for 0.18.1 r=davidhewitt a=davidhewitt

Update for `main` following release of new patch release.

Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2023-02-07 21:39:18 +00:00
David Hewitt 92cca896de release notes for 0.18.1 2023-02-07 21:38:07 +00:00
bors[bot] 9e5c845dee
Merge #2934
2934: guide: add documentation for trailing option arguments r=davidhewitt a=davidhewitt

Following the increased clarity around PyO3's handling of function signatures of 0.18.0, I wanted to add a section to the guide documenting the default-to-none behaviour for trailing `Option<T>` arguments.

Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2023-02-07 08:15:57 +00:00
bors[bot] 2db351bf18
Merge #2937
2937: link against pythonXY_d.dll for debug Python on Windows r=davidhewitt a=davidhewitt

Closes #2780 

Note that upstream Python issue https://github.com/python/cpython/issues/101614 means linking against `python3_d.dll` is useless, so I've set this to always use the version-specific builds for now.

The heuristic for detecting a Windows debug build is... not great. I check if the `EXT_SUFFIX` starts with `_d.`, which is the only thing that I could see in the sysconfig which suggested a debug build. If this proves to be brittle, we may wish to ask upstream for something better to be added to `sysconfig`.

Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2023-02-07 07:23:58 +00:00
David Hewitt d67a8dc0a1 link against pythonXY_d.dll for debug Python on Windows 2023-02-07 07:23:17 +00:00
bors[bot] 1e4dc54c97
Merge #2936
2936: bump maturin version in getting_started.md r=messense a=jmhodges

Latest maturin is 0.14.x, so reference that in the docs

Co-authored-by: Jeff Hodges <jeff@somethingsimilar.com>
2023-02-04 08:13:28 +00:00
Jeff Hodges bc1a33f9fe
bump maturin version in getting_started.md
Latest maturin is 0.14.x
2023-02-04 00:09:04 -08:00
bors[bot] 4d80475008
Merge #2929
2929: docs: Precise the abscense of `py: Python` for the #[pyo3(signature)] r=davidhewitt a=jjerphan

Hi,

First, thank you for working on PyO3!

I think this adds a precision which was not obvious when migrating to 0.18.0 conventions.

What do you think? Also, should something be added to [the migration guide](https://pyo3.rs/main/migration) in this regard?

Thank you!

Co-authored-by: Julien Jerphanion <git@jjerphan.xyz>
2023-02-03 21:40:45 +00:00
Julien Jerphanion 9306d56b27 docs: Precise the abscense of py: Python for the #[pyo3(signature)] 2023-02-03 20:57:23 +00:00
David Hewitt c709f30638 guide: add documentation for trailing option arguments 2023-02-03 20:54:51 +00:00
bors[bot] 806eed5b07
Merge #2914
2914: correct ffi definition of PyIter_Check r=davidhewitt a=davidhewitt

Closes #2913 

It looks like what is happening is that PyO3 was relying on an outdated macro form of `PyIter_Check` which is now a CPython implementation detail, which would explain why it was behaving inconsistently on different platforms (likely due to differences in linkers / implementations).

The test I've pushed succeeds, but fails to compile due to a hygiene bug! I'm done for tonight so I'll take a look at that soon and then rebase this after.

Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2023-02-03 20:51:15 +00:00
bors[bot] 864aee0916
Merge #2930
2930: add better error message for Python in signature r=adamreichold a=davidhewitt

Inspired by #2929, this just adds a better error message when `Python` arguments are accidentally included in the signature.

Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2023-02-03 09:11:26 +00:00
David Hewitt 5bab0e9409 use simplified PyIter_Check on CPython 3.7 2023-02-03 07:55:44 +00:00
bors[bot] 97712a1dce
Merge #2933
2933: changelog: add missing entry for frozen r=davidhewitt a=davidhewitt

After discussion in https://github.com/PyO3/rust-numpy/pull/367#issuecomment-1409283700 I noticed we were missing a CHANGELOG entry for frozen. This doesn't help past users but does help document when the feature was released (in 0.17.0).

Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2023-02-03 07:39:18 +00:00
David Hewitt 96efb0eda9 add better error message for Python in signature 2023-02-03 06:57:30 +00:00
David Hewitt 26cf9b7163 changelog: add missing entry for frozen 2023-02-03 06:35:53 +00:00
bors[bot] 141cbeaa2c
Merge #2912
2912: Add `PyDict.update()` and `PyDict.update_if_missing()` r=davidhewitt a=samuelcolvin

Fix #2910

Note, I'd also be happy to remove the `override_` argument from merge and perhaps rename it to `update_missing` or similar to give a cleaner API. LMK what you think.

Please consider adding the following to your pull request:
 - [x] an entry for this PR in newsfragments
 - [x] docs to all new functions and / or detail in the guide
 - [x] tests for all new or changed functions


Co-authored-by: Samuel Colvin <s@muelcolvin.com>
2023-02-03 06:32:52 +00:00
Samuel Colvin c09dfcd4e0 add PyDict.update() and PyDict.update_if_missing() 2023-02-03 06:32:01 +00:00
bors[bot] cb38ff0111
Merge #2889
2889: Added support for PyErr_WriteUnraisable r=davidhewitt a=mitsuhiko

Fixes #2884

Co-authored-by: Armin Ronacher <armin.ronacher@active-4.com>
2023-01-29 20:28:00 +00:00