Commit Graph

443 Commits

Author SHA1 Message Date
David Matos c66ed292ec
Disable PyUnicode_DATA on PyPy (#4116)
* Disable PYUNICODE_DATA on PyPy

* Add newsfragment

* Adjust import on PyString
2024-04-26 06:00:13 +00:00
Georg Brandl c2ac9a98e2
fix vectorcall argument handling (#4104)
Fixes #4093

- Make PY_VECTORCALL_ARGUMENTS_OFFSET a size_t like on CPython
- Remove the assert in PyVectorcall_NARGS and use checked cast
2024-04-22 08:56:39 +00:00
David Hewitt 947b372dcc
change `PyAnyMethods::dir` to be fallible (#4100) 2024-04-19 19:35:52 +00:00
David Hewitt cd28e1408e
add `#[track_caller]` to all `Py`/`Bound`/`Borrowed` methods which panic (#4098) 2024-04-19 11:44:36 +00:00
dependabot[bot] b11174e96d
Update heck requirement from 0.4 to 0.5 (#3966)
* Update heck requirement from 0.4 to 0.5

---
updated-dependencies:
- dependency-name: heck
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>

* newsfragment

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: David Hewitt <mail@davidhewitt.dev>
2024-04-18 10:22:34 +00:00
David Hewitt 2c205d4586
release notes for 0.21.2 (#4091) 2024-04-18 08:59:02 +00:00
dependabot[bot] e64eb72903
build(deps): update chrono-tz requirement from >= 0.6, < 0.9 to >= 0.6, < 0.10 (#4061)
* build(deps): update chrono-tz requirement from >= 0.6, < 0.9 to >= 0.6, < 0.10

Updates the requirements on [chrono-tz](https://github.com/chronotope/chrono-tz) to permit the latest version.
- [Release notes](https://github.com/chronotope/chrono-tz/releases)
- [Changelog](https://github.com/chronotope/chrono-tz/blob/main/CHANGELOG.md)
- [Commits](https://github.com/chronotope/chrono-tz/compare/v0.6.0...v0.9.0)

---
updated-dependencies:
- dependency-name: chrono-tz
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>

* newsfragment

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: David Hewitt <mail@davidhewitt.dev>
2024-04-18 08:58:51 +00:00
Jacob Zhong 03c50a1839
Change the types of `PySliceIndices` and `PySlice::indices (#3761)
* Change the type of `PySliceIndices::slicelength` and `PySlice::indices()`

* Fix example

* Fix fmt
2024-04-18 07:33:07 +00:00
Icxolu 03f59eaf45
fix declarative module compile error with `create_exception!` (#4086)
* fix declarative module compile error with `create_exception!`

* add newsfragment
2024-04-16 20:12:18 +00:00
David Hewitt a5201c04af
Deprecate the `PySet::empty` gil-ref constructor (#4082)
* Deprecate the `PySet::empty` gil-ref constructor

* add newsfragment
2024-04-14 21:38:40 +00:00
David Matos 8ed5c17b93
Allow use of scientific notation on rust decimal (#4079)
* Allow use of scientific notation on rust decimal

* Add newsfragment

* Pull out var

* Fix clippy warning

* Modify let bindings location
2024-04-14 20:07:17 +00:00
messense 30348b4d3f
Link libpython for AIX target (#4073) 2024-04-13 07:43:06 +00:00
Icxolu ee5216f406
fix declarative-modules compile error (#4054)
* fix declarative-modules compile error

* add newsfragment
2024-04-12 06:34:27 +00:00
Icxolu c8b59d7117
add `#[doc(hidden)]` to the Rust module created by `#[pymodule]` (#4067)
* add `#[doc(hidden)]` to the Rust module created by `#[pymodule]`

* add newsfragment
2024-04-12 06:34:08 +00:00
Icxolu 7a00b4d357
add descriptive error msg for `__traverse__` receivers other than `&self` (#4045)
* add descriptive error msg for `__traverse__` receivers other than `self`

* add newsfragment

* improve error message
2024-04-04 19:08:51 +00:00
David Hewitt a4aea230ed
fix compile error for multiple async method arguments (#4035) 2024-04-02 17:43:51 +00:00
David Hewitt c1f11fb4bd
release: 0.21.1 (#4032) 2024-04-01 18:51:58 +00:00
Icxolu 63ba371db0
added various std traits for `PyBackedStr` and `PyBackedBytes` (#4020)
* added various std traits for `PyBackedStr` and `PyBackedBytes`

* add newsfragment

* add tests
2024-04-01 07:10:40 +00:00
David Hewitt 336b1c982b
add `import_exception_bound!` macro (#4027)
* add `import_exception_bound!` macro

* newsfragment and tidy up
2024-03-31 19:55:31 +00:00
David Hewitt 9d932c1061
add `#[inline]` hints on many `Bound` and `Borrowed` methods (#4024) 2024-03-30 22:10:21 +00:00
Weijie Guo 74d9d23ba0
async method should allow args not only receiver (#4015)
* async method should allow args not only receiver

* add changelog md
2024-03-30 08:48:19 +00:00
Alex Gaynor ae3ac7d872
Fixed error string when failing to import an exception (#4012) 2024-03-29 15:49:50 +00:00
David Hewitt cf74624de9
refactor to remove add_to_module functions from generated code (#4009)
* refactor to remove add_to_module functions from generated code

* mrsv, newsfragment

* clippy
2024-03-29 11:54:33 +00:00
David Hewitt b053e83c08
implement `Send` and `Sync` for `PyBackedStr` and `PyBackedBytes` (#4007) 2024-03-29 11:28:42 +00:00
Icxolu dd1710256d
use `extract_argument` for `#[setter]` extraction (#3998)
* use `extract_argument` for `#[setter]` extraction

* add newsfragment
2024-03-27 15:41:04 +00:00
Icxolu 35faeff6f1
handle `#[pyo3(from_py_with = "")]` in `#[setter]` methods (#3995)
* handle `#[pyo3(from_py_with = "")]` in `#[setter]` methods

* add newsfragment
2024-03-26 18:53:11 +00:00
David Hewitt 1be2fad9bf
release: 0.21.0 (#3983) 2024-03-25 23:36:08 +00:00
Tim Felgentreff 9a38e709bb
Basic GraalPy Support (#3247)
* graalpy: recognize graalpy implementation when building

* graalpy: global Ellipse, None, NotImplemented, True, and False are only available as pointers

* graalpy: PyObject struct is opaque, use functions for everything

* graalpy: missing many of the same functions as pypy

* graalpy: do not have 128bit conversion functions

* graalpy: add functions for datetime accessor macros

* graalpy: add implementations for list macro functions

* graalpy: skip tuple macros

* graalpy: always use extern Py_CompileString function

* graalpy: disable assertion that does not apply to graalpy

* graalpy: floatobject structure is opaque on graalpy

* graalpy: ignore gc dependent test

* graalpy: add CI config

* graalpy: run rust fmt

* graalpy: add changelog entry

* graalpy: discover interpreter on PATH

* graalpy: interpreter id is not applicable to graalpy (just like pypy)

* graalpy: skip tests that cannot work on GraalPy

* graalpy: fix constructing normalized Err instances

Co-authored-by: David Hewitt <mail@davidhewitt.dev>

* graalpy: correct capi library name, but skip rust tests due to missing symbols

* graalpy: no support for C extensions on windows in latest release

* graalpy: declare support versions

* graalpy: frame, code, method, and function objects access from C API is mostly missing

* graalpy: take care only to expose C structure that GraalPy allocates

* graalpy: Bail out if graalpy version is less than what we support

---------

Co-authored-by: David Hewitt <mail@davidhewitt.dev>
2024-03-25 18:54:52 +00:00
Icxolu 54ffaecd65
add `AsRef` impls for `PyBackedStr` and `PyBackedBytes` (#3991)
* add `AsRef` impls for `PyBackedStr` and `PyBackedBytes`

* add newsfragment
2024-03-25 16:21:27 +00:00
Lily Foote 009cd32a44
Add into_mapping and into_sequence methods to Bound types (#3982)
* Add Bound<'py, PyDict>.into_mapping method

* Add Bound<'py, PyTuple>.into_sequence method

* Add Bound<'py, PyList>.into_sequence method

* Add newsfragment

* Add tests for into_mapping and into_sequence
2024-03-23 01:13:24 +00:00
David Hewitt caf80eca66
handle clippy `new_without_default` warnings (#3971)
* handle clippy `new_without_default` warnings

* add newsfragment
2024-03-19 21:41:27 +00:00
Icxolu da24f0cf93
exposes `Borrowed::to_owned` as public API (#3963)
* exposes `Borrowed::to_owned` as public API

* add newsfragment
2024-03-17 09:17:09 +00:00
David Hewitt dcba984b51
deprecate `GILPool` (#3947)
* deprecate `GILPool`

* review: adamreichold

* fix deprecation warnings in tests
2024-03-15 10:25:27 +00:00
David Hewitt 67b1b35013
release: 0.21.0-beta.0 (#3944) 2024-03-10 22:16:18 +00:00
David Hewitt 770d9b7f01
add `FromPyObjectBound` trait for extracting `&str` without GIL Refs (#3928)
* add `FromPyObjectBound` adjustment for `&str` without GIL Refs

* review: alex, Icxolu feedback

* add newsfragment

* add newsfragment for `FromPyObject` trait change

* make some examples compatible with abi3 < 3.10

* seal `FromPyObjectBound`

* fixup chrono_tz conversion
2024-03-08 07:43:48 +00:00
Thomas Tanon 0f7ddb19a5
PyPy: remove PyCode (PyCode_Type does not exist) (#3934) 2024-03-06 18:19:43 +00:00
David Hewitt 57bbc32e7c
add `experimental-async` feature (#3931)
* add `experimental-async` feature

* gate async doctests on feature
2024-03-06 00:54:45 +00:00
Matthew Neeley a15e4b1a11
Allow pymodule functions to take a single Bound<'_, PyModule> arg (#3905) 2024-02-27 22:24:14 +00:00
David Hewitt 8e2219b0d9
silence non-local-definitions nightly lint (#3901)
* silence non-local-definitions nightly lint

* add newsfragment

* add FIXMEs for `non_local_definitions`

* also allow `non_local_definitions` in doctests
2024-02-26 20:28:04 +00:00
Thomas Tanon e0e3981e17
#[pymodule] mod some_module { ... } v3 (#3815)
* #[pymodule] mod some_module { ... } v3

Based on #2367 and #3294

Allows to export classes, native classes, functions and submodules and provide an init function

See test/test_module.rs for an example

Future work:
- update examples, README and guide
- investigate having #[pyclass] and #[pyfunction] directly in the #[pymodule]

Co-authored-by: David Hewitt <mail@davidhewitt.dev>
Co-authored-by: Georg Brandl <georg@python.org>

* tests: group exported imports

* Consolidate pymodule macro code to avoid duplicates

* Makes pymodule_init take Bound<'_, PyModule>

* Renames #[pyo3] to #[pymodule_export]

* Gates #[pymodule] mod behind the experimental-declarative-modules feature

* Properly fails on functions inside of declarative modules

---------

Co-authored-by: David Hewitt <mail@davidhewitt.dev>
Co-authored-by: Georg Brandl <georg@python.org>
2024-02-24 13:50:18 +00:00
David Hewitt 11d143d0c9
release: 0.20.3 (#3890) 2024-02-23 12:30:38 +00:00
David Hewitt c4f66657c5
fix `either` feature conditional compilation, again (#3834)
* fix `either` feature conditional compilation, again

* test feature powerset in CI

* install `rust-src` for feature powerset tests

* review: adamreichold feedback

* Fix one more case of redundant imports.

* just check feature powerset for now

---------

Co-authored-by: Adam Reichold <adam.reichold@t-online.de>
2024-02-22 08:05:37 +00:00
Juniper Tyree 885883bf68
Add `Py::drop_ref` method (#3871)
* add Py::drop_ref method

* add changelog entry

* fix ffi import

* integrate review feedback

* Add a test

* Fix some build errors

* Fix some more build errors
2024-02-21 22:56:03 +00:00
David Hewitt eb90b81d44
always use a Python iterator for sets and frozensets (#3849)
* always use a Python iterator for sets and frozensets

* add newsfragment
2024-02-17 10:57:53 +00:00
David Hewitt dc8b948201
add `PyBackedStr` and `PyBackedBytes` (#3802)
* add `PyBackedStr` and `PyBackedBytes`

* review: adamreichold feedback

* use `NonNull<[u8]>`

* clippy and newsfragment

* drop binding unused after refactoring

---------

Co-authored-by: Adam Reichold <adam.reichold@t-online.de>
2024-02-15 07:58:20 +00:00
David Hewitt f5eafe23f2
add maximum Python version check (#3821)
* add maximum Python version check

* restore dependency of `pyo3-macros-backend` on `pyo3-build-config`

* fix clippy-all noxfile job
2024-02-13 21:52:53 +00:00
David Hewitt 55488d3880
Merge pull request #3818 from davidhewitt/datetime-segv
fix segmentation fault when `datetime` module is invalid
2024-02-11 09:04:32 +00:00
David Hewitt 5b1104131f fix segmentation fault when `datetime` module is invalid 2024-02-11 02:44:31 +00:00
David Hewitt 662eecfb44 add `PyStringMethods::encode_utf8` 2024-02-05 13:28:46 +00:00
David Hewitt 76d1b34cd5 Revert "Merge pull request #3578 from davidhewitt/typed-helpers"
This reverts commit 7b07d6d21b, reversing
changes made to 99858236bd.
2024-02-03 20:56:23 +00:00
David Hewitt 8f8d4d33fa
Merge pull request #3776 from davidhewitt/bound-extract
migrate `FromPyObject` for `Bound` and `Py` to new APIs
2024-02-02 23:10:47 +00:00
David Hewitt 57735540e8
Merge pull request #3736 from Tpt/tpt/systemtime
Adds conversion between SystemTime and datetime
2024-02-01 14:05:51 +00:00
David Hewitt 4437e8f616 add `Py::as_any` and `Py::into_any` 2024-02-01 09:07:36 +00:00
David Hewitt a3eb328378 migrate `FromPyObject` for `Bound` and `Py` to `extract_bound` 2024-01-29 13:46:46 +00:00
David Hewitt 595ca4b3c1 Add `extract_bound` method to `FromPyObject` 2024-01-28 07:22:51 +00:00
Tpt f83544910f Adds conversion between SystemTime and datetime 2024-01-27 17:43:51 +01:00
David Hewitt 11b5ae7f5f update ffi structures for PyPy 7.3.15 2024-01-23 20:34:19 +00:00
David Hewitt d1b072222a
Merge pull request #3582 from mkovaxx/pyclass_complex_enum
Full ADT support with pyclass for complex enums
2024-01-19 14:17:28 +00:00
Mate Kovacs 3ed5ddb0ec feat: support pyclass on complex enums 2024-01-18 22:04:42 +09:00
David Hewitt 43504cd15a
Merge pull request #3742 from samuelcolvin/int-extraction-performance
improve performance of successful int extract by ~30% by avoiding calls to `__index__` where redundant
2024-01-16 17:14:39 +00:00
Samuel Colvin 0e876d94d6
improve performance of successful int extract by ~30%
add newsfragment

formatting

skip slow path on 3.8+

formatting

cfg if,else

formatting again

dedicated macro, change int_convert_u64_or_i64 too

add float tests

force index call for PyLong_AsUnsignedLongLong

perform PyLong check for 3.8 too

perform PyLong check for <3.10
2024-01-16 13:51:19 +00:00
David Hewitt 7366b1a386
Merge pull request #3730 from Tpt/chrono-tz
Conversion between chrono_tz::Tz and zoneinfo.ZoneInfo
2024-01-15 14:48:27 +00:00
jadedpasta 83f0f22efe ffi: Add definition for PyType_GetModuleByDef
This API is available starting in 3.11. It is not part of the Stable ABI.

PyType_GetModuleByDef searches the MRO of the given type for a module
matching the given module spec. It can be useful for users use that
`pyo3_ffi` directly and want to support multiple interpreters/per
interpreter GIL. It is useful to obtain access to the module state from
special methods like `tp_new` that can't use the METH_METHOD calling
convention.

This API is not supported on PyPy yet, but guess the symbol name for the future.
2024-01-12 22:13:33 -06:00
Tpt 72f0c73925 Conversion between chrono_tz::Tz and zoneinfo.ZoneInfo 2024-01-08 15:19:49 +01:00
David Hewitt 8fa5294d93 release notes for 0.20.1 2023-12-30 21:34:45 +00:00
Alex Gaynor 339660c117 add PyAnyMethods for binary operators
also pow

fixes #3709
2023-12-29 18:45:18 -05:00
David Hewitt 3da1aac2dd add `gil-refs` feature to aid migration 2023-12-29 14:42:31 +00:00
David Hewitt 1b61cb015a Add `.as_borrowed()` conversion from gil-refs to `Bound<T>` 2023-12-26 09:49:03 +00:00
David Hewitt f5b18468bc partially revert changes to `PyTzInfoAccess` trait 2023-12-24 15:07:42 +00:00
Adam Reichold e99058a442
Merge pull request #3679 from davidhewitt/datetime2
implement datetime traits for `Bound`
2023-12-23 14:54:30 +00:00
David Hewitt 6832bf88f2 implement datetime traits for Py2 2023-12-23 15:34:07 +01:00
Adam Reichold 4dc6c1643e Turn calls of __traverse__ into no-ops for unsendable pyclass if on the wrong thread
Adds a "threadsafe" variant of `PyCell::try_borrow` which will fail instead of
panicking if called on the wrong thread and use it in `call_traverse` to turn GC
traversals of unsendable pyclasses into no-ops if on the wrong thread.

This can imply leaking the underlying resource if the originator thread has
already exited so that the GC will never run there again, but it does avoid hard
aborts as we cannot raise an exception from within `call_traverse`.
2023-12-23 15:01:08 +01:00
Adam Reichold a115877bba
Merge pull request #3686 from davidhewitt/bound
make Bound and Borrowed types public API
2023-12-21 16:25:01 +00:00
Alex Gaynor d92792f8ad Fixes #3645 -- added `abi3-py312` feature 2023-12-21 10:40:14 -05:00
David Hewitt a09b9f8834 make `Bound` and `Borrowed` types public API 2023-12-21 12:20:33 +00:00
David Hewitt 43827e39ee
Merge pull request #3677 from davidhewitt/string2
implement `PyStringMethods`
2023-12-20 22:04:23 +00:00
David Hewitt f4f3169cad implement `PyStringMethods` 2023-12-20 16:19:18 +00:00
Adam Reichold 1b3dc6d7ac
Merge pull request #3661 from PyO3/iter-output-type
Replace (A)IterNextOutput by autoref-based specialization to allow returning arbitrary value
2023-12-20 12:53:42 +00:00
Adam Reichold a605308cee Add change log and migration guide entries. 2023-12-20 13:07:14 +01:00
David Hewitt bc87b7bac6 deprecate `PyTryFrom` and `PyTryInto` 2023-12-20 11:28:24 +00:00
Tpt 8b614745cf Adds std::duration::Duration from/to Python conversions 2023-12-20 08:57:26 +01:00
Adam Reichold 8bb64377b8
Merge pull request #3638 from PyO3/call-op-bool
Try harder by looking for a __bool__ magic method when extracing bool values from Python objects.
2023-12-19 18:52:55 +00:00
Adam Reichold 4177dfcc81 Apply __bool__ conversion only to numpy.bool_ to avoid false positives. 2023-12-19 18:55:28 +01:00
Adam Reichold 8133aaa5d8 Try harder by looking for a __bool__ magic method when extracing bool values from Python objects.
I decided to not implement the full protocol for truth value testing [1] as it
seems confusing in the context of function arguments if basically any instance
of custom class or non-empty collection turns into `true`.

[1] https://docs.python.org/3/library/stdtypes.html#truth
2023-12-19 18:55:28 +01:00
David Hewitt e727640ef3
Merge pull request #3664 from Tpt/chrono-abi3
Chrono: compatibility with abi3
2023-12-19 17:53:30 +00:00
Adam Reichold 416d3c488f Rename name to qualname and full_name to name to better match Python 2023-12-19 16:51:24 +01:00
Adam Reichold 2fdd52003e Add PyType::full_name which is tp_name and has an abi3 fallback. 2023-12-19 15:47:21 +01:00
Tpt d7eac6527b Chrono: compatibility with abi3 2023-12-19 14:53:14 +01:00
Tpt 0d2387e858 Chrono: makes FromPyObject impl on DateTime generic
ToPyObject was already generic
2023-12-18 20:12:30 +01:00
Adam Reichold ced97f80d1 Transition is_true to is_truthy to clarify that the test is not based on identity with or equality to the True singleton. 2023-12-16 14:04:37 +01:00
David Hewitt ef8532b175 Add `AsRefSource` to `PyNativeType`. 2023-12-14 18:35:06 +00:00
messense c21a84d999
Add support for extracting Rust set types from `frozenset` 2023-12-07 20:25:31 +08:00
David Hewitt 07726aefc4
Merge pull request #3609 from wyfo/async_receiver
feat: allow async methods to accept `&self`/`&mut self`
2023-12-07 07:38:25 +00:00
Joseph Perez f34c70c2da
feat: allow async methods to accept `&self`/`&mut self` 2023-12-07 07:42:10 +01:00
Adam Reichold 4baf0235c3
Merge pull request #3616 from neachdainn/3615-gilprotected-pyvisit
Enable `GILProtected` access via `PyVisit`
2023-12-05 20:43:38 +00:00
Nathan Kent 3249feb85c
Enable `GILProtected` access via `PyVisit`
Closes #3615

This simply adds a new method which uses the existence of a `PyVisit`
object as proof that the GIL is held instead of a `Python` object. This
allows `GILProtected` to be used in instances where contained Python
objects need to participate in garbage collection. Usage in this
situation should be valid since no Python calls are made and this does
not provide any additional mechanism for accessing a `Python` object.
2023-12-05 11:10:00 -08:00
David Hewitt ed87637ebb replace `PyTryFrom` by splitting `PyTypeInfo` 2023-12-05 08:01:30 +03:00
David Hewitt e8f852bce7
Merge pull request #3599 from wyfo/coroutine_cancel
feat: add `coroutine::CancelHandle`
2023-12-04 12:44:36 +00:00
Joseph Perez 8a674c2bd3
feat: add `coroutine::CancelHandle` 2023-12-04 07:46:51 +01:00
Adam Reichold e6457c5e99 Use portable-atomic for targets which lack 64-bit atomics used to check interpreter ID.
I chose to make the dependency mandatory instead of optional as portable-atomic
itself just forwards to the native atomics when they are available so making
that choice part of our build system is not really necessary. Personally, I was
unable to perceive any noticeable compile-time hit from adding it.
2023-12-02 07:57:00 +01:00