Commit graph

5150 commits

Author SHA1 Message Date
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
Armin Ronacher 066880e7d5 Added support for PyErr_WriteUnraisable 2023-01-29 20:01:22 +00:00
David Hewitt f4953224d8 correct ffi definition of PyIter_Check 2023-01-29 19:43:33 +00:00
bors[bot] 3149a80416
Merge #2926
2926: Warn about unknown config keys in `PYO3_CONFIG_FILE` r=davidhewitt a=messense

`maturin` also read from `PYO3_CONFIG_FILE` to get `ext_suffix` config, `pyo3-build-config` currently denies unknown config keys makes it inconvenient.

See https://github.com/PyO3/maturin/issues/1430

Co-authored-by: messense <messense@icloud.com>
2023-01-29 10:40:11 +00:00
messense f8e2a26439
Warn about unknown config keys in PYO3_CONFIG_FILE 2023-01-29 10:49:27 +08:00
bors[bot] 165062e6bd
Merge #2907
2907: Update `downcast` documentation r=adamreichold a=mejrs

This was outdated (!)


Co-authored-by: mejrs <59372212+mejrs@users.noreply.github.com>
Co-authored-by: Adam Reichold <adam.reichold@t-online.de>
2023-01-28 17:46:34 +00:00
Adam Reichold edaba66c44 Pin trybuild to an MSRV-compatible version 2023-01-28 18:29:58 +01:00
mejrs cadcabaf04 Feedback 2023-01-28 15:35:31 +01:00
bors[bot] efb8a12414
Merge #2873
2873: A new example that shows how to integrate Python plugins that use pyclasses into a Rust app r=davidhewitt a=alexpyattaev

Example showing integration of a Python plugin into a Rust app while having option to test pyclass based API without the main app.  This also illustrates some aspects related to import of Python modules into a Rust app while also having an API module available for the Python code to be able to produce Rust objects. 

CI seems to fail on my local machine for reasons unrelated to the example just added:
```
error: unused macro definition: `check_struct`
  --> pyo3-ffi-check/src/main.rs:13:18
   |
13 |     macro_rules! check_struct {
   |                  ^^^^^^^^^^^^
   |
```

Co-authored-by: Alex Pyattaev <alex.pyattaev@gmail.com>
Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2023-01-27 21:12:59 +00:00
bors[bot] d118ee3a73
Merge #2923 #2924
2923: hygiene: fix `#[pymethods(crate = "...")]` r=davidhewitt a=davidhewitt

Got to the bottom of the hygiene issue in test of #2914 

Turns out that `#[pymethods] #[pyo3(crate = "...")]` works, but `#[pymethods(crate = "...")]` was ignoring the argument.

Added a tweak to fix this and a snippet in the hygiene test (which fails on `main`). 

2924: remove unneeded into_iter calls r=davidhewitt a=davidhewitt

Clippy complaining about these to me this morning locally.

Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2023-01-27 09:31:20 +00:00
David Hewitt d7601a4352 add cargo-generate template for plugin example 2023-01-27 08:34:09 +00:00
Alex Pyattaev 2228f584a1 added a plugin example that shows how to integrate a Python plugin into a Rust app while having option to test API without the main app 2023-01-27 08:34:09 +00:00
David Hewitt 1a4153f718 remove unneeded into_iter calls 2023-01-27 08:20:03 +00:00
bors[bot] 083dd5fe29
Merge #2904 #2921
2904: refactor docstring generation code r=mejrs a=davidhewitt

As a first step towards #2866 this is a tweak to the macro code which generates Python docstrings. This PR refactors the behaviour so that instead of always creating a `concat!` expression to generate a nul-terminated string, this will only happen if a Rust 1.54+ macro doc is present (e.g. `#[doc = include_str!(...)]`).

The default case now just collects all the `#[doc]` attributes into a single string.

This should make it easier to factor out the `text_signature` formatting, and avoids wasting compile time invoking the `concat!` macro when not necessary.

2921: Check to see if object is `None` before traversing r=davidhewitt a=neachdainn

Closes #2915

When using the C API directly, the intended way to call `visitproc` is via the `Py_VISIT` macro, which checks to see that the provided pointer is not null before passing it along to `visitproc`. Because PyO3 isn't using the macro, it needs to manually check that the pointer isn't null. Without this check, calling `visit.call(&obj)` where `let obj = None;` will segfault.


Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
Co-authored-by: Nate Kent <nate@nkent.net>
2023-01-27 07:52:03 +00:00
bors[bot] 794e19d796
Merge #2911
2911: add `Ellipsis()` and `is_ellipsis()` methods r=mejrs,davidhewitt a=samuelcolvin

fix #2906

Please consider adding the following to your pull request:
 - [x] an entry for this PR in newsfragments - see [https://pyo3.rs/main/contributing.html#documenting-changes]
 - [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-01-27 06:41:54 +00:00
Samuel Colvin 3c9ace03d8 add Ellipsis() and is_ellipsis() methods, fix #2906 2023-01-27 06:40:02 +00:00
David Hewitt e4a3d2893a refactor docstring generation code 2023-01-27 06:38:04 +00:00
David Hewitt 5667a095d6 hygiene: fix #[pymethods(crate = "...")] 2023-01-27 06:34:12 +00:00
Nate Kent f11290d314
Add additional unit test for GC traversal
Since we're just testing a bug during traversal, we don't actually have
to reap the object, we just have to make a reference cycle so that it's
traverse method is called.
2023-01-26 16:27:54 -08:00
Nate Kent f38841a8e2
Check to see if object is None before traversing
Closes #2915

When using the C API directly, the intended way to call `visitproc` is
via the `Py_VISIT` macro, which checks to see that the provided pointer
is not null before passing it along to `visitproc`. Because PyO3 isn't
using the macro, it needs to manually check that the pointer isn't null.
Without this check, calling `visit.call(&obj)` where `let obj = None;`
will segfault.
2023-01-26 15:55:58 -08:00
bors[bot] 98b12973fc
Merge #2922
2922: Update rust 1.67 r=mejrs a=mejrs



Co-authored-by: mejrs <59372212+mejrs@users.noreply.github.com>
2023-01-26 21:38:25 +00:00
mejrs 2052269aea Update rust 1.67 2023-01-26 21:44:05 +01:00
bors[bot] 9004bd2d9e
Merge #2919
2919: Fix link for #2879 r=mejrs a=qbx2

Fixes an incorrect link in changelog.

Co-authored-by: Sunyeop Lee <sunyeop97@gmail.com>
2023-01-26 14:09:53 +00:00
Sunyeop Lee e637b39abd
Fix link for #2879 2023-01-26 21:54:27 +09:00
mejrs fe7b1eed04 Update downcast documentation 2023-01-24 19:15:32 +01:00
bors[bot] 18081ba14e
Merge #2896
2896: make rust function benchmarks more similar to the Python ones r=adamreichold a=davidhewitt

We have some benchmarks in `pytests/tests/test_pyfunctions.py` which I occasionally peek at, which compares some `#[pyfunction]` performance with pure-Python equivalents. It's designed purely to measure the overheads.

The existing comparison wasn't exactly fair because it used Rust types such as i32 on the Rust side, meaning there was additional runtime type checking going on compared to the Python implementations.

I've removed that in this PR, making all the input types on the Rust side just `&PyAny` or `Option<&PyAny>`. This does reduce the gap between the Python and Rust ones where we're slower, however it shows there is still some wins we could yet find in overhead reduction.

Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2023-01-20 20:43:12 +00:00
bors[bot] 8f0a2bbf7b
Merge #2897
2897: add link on how to obtain GIL to guide r=birkenfeld a=davidhewitt

Closes #2164 

Most of that issue is already addressed with the new `#[pyo3(signature = (...))]` option and its guide page. The final suggestion to make it easier to find recommendations on how to acquire the GIL seems reasonable to me.

(EDIT: original issue link was wrong)

Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2023-01-20 12:29:13 +00:00
David Hewitt e83803e813 add link on how to obtain GIL to guide 2023-01-20 08:21:57 +00:00
David Hewitt 0362855773 make rust benchmarks more similar to the Python ones 2023-01-20 07:24:05 +00:00