Commit Graph

438 Commits

Author SHA1 Message Date
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
David Hewitt e62e6cad5d
Merge pull request #3603 from davidhewitt/0.19-deprecations
remove all functionality deprecated in 0.19
2023-11-28 06:47:30 +00:00
Alex Gaynor fae209419c fixes #3561 -- silence new clippy warning 2023-11-27 17:06:59 -05:00
David Hewitt 5c6d49084f remove all functionality deprecated in 0.19 2023-11-27 22:02:19 +00:00
David Hewitt d8002c4b2b
Merge pull request #3588 from wyfo/coroutine_name
feat: add coroutine `__name__`/`__qualname__`
2023-11-26 09:23:29 +00:00
Joseph Perez 781b9e3983
feat: add coroutine `__name__`/`__qualname__` and not-awaited warning 2023-11-25 21:51:20 +01:00
Adam Reichold 1203921d5c
Merge pull request #3456 from aldanor/feature/either
Add conversion support for `either::Either`
2023-11-25 09:37:49 +00:00
David Hewitt cd8526ecc6 Implement `PyTypeInfo` for `PyEllipsis`, `PyNone`, and `PyNotImplemented` 2023-11-24 22:31:39 +00:00
Ivan Smirnov a75464ee26 add conversion support for `either::Either` 2023-11-24 22:09:34 +00:00
David Hewitt 69870d2298
Merge pull request #3540 from wyfo/coroutine
feat: support `async fn` in macros with coroutine implementation
2023-11-22 19:52:15 +00:00
David Hewitt 3f0dfa9698
Merge pull request #3587 from wyfo/classmethod_into
feat: allow classmethods to receive `Py<PyType>`
2023-11-22 19:34:19 +00:00
Joseph Perez 627841f1e2
feat: support `async fn` in macros with coroutine implementation 2023-11-22 20:25:36 +01:00
Joseph Perez 744de3a142
feat: allow `classmethod`/`pass_module` to receive owned types
This is necessary for async functions
2023-11-22 07:45:59 +01:00
David Hewitt bd0174aa5d Change return types of `py.None()`, `py.NotImplemented()` and `py.Ellipsis()` to typed singletons 2023-11-17 16:16:19 +00:00
Joseph Perez f9107191f5 docs: add newsfragment 2023-10-29 13:54:10 +01:00
David Hewitt d895734499 change `PyDict::from_sequence` to take just `&PyAny` 2023-10-20 11:59:26 +01:00
David Hewitt f12f928bd5
Merge pull request #3514 from messense/memoryview
Add `PyMemoryView` type
2023-10-15 15:08:50 +00:00
David Hewitt aa28cec893
Merge pull request #3507 from orhun/feat/support_smallvec_conversion
Add support for `SmallVec` in conversion traits (#3440)
2023-10-15 14:43:55 +00:00
messense 5b94241bd7
Add `PyMemoryView` type 2023-10-15 17:32:09 +08:00
Adam Reichold 7ad122e7d9 Align chrono dev and runtime dependency version specifications. 2023-10-14 09:18:45 +02:00
Orhun Parmaksız dfeae473e5
Add support for `SmallVec` in conversion traits (#3440) 2023-10-11 17:14:23 +03:00
David Hewitt c77deee18e release: 0.20.0 2023-10-11 14:39:19 +02:00
David Hewitt 76bf521ed0
Merge pull request #3505 from davidhewitt/deprecate_dunder_new
deprecate undocumented `#[__new__]` form of `#[new]`
2023-10-10 21:35:10 +00:00
David Hewitt 6c90325a1c deprecate undocumented `#[__new__]` form of `#[new]` 2023-10-10 08:47:03 +01:00
David Hewitt c0b5004cfa
Merge pull request #3455 from davidhewitt/normalized-exceptions
also use `PyErr::SetObject` on Python versions before 3.12
2023-10-10 07:44:39 +00:00
Erle Carrara 0e0e6623f3
fix _PyFrameEvalFunction. Since python 3.11 it receives a `_PyInterpreterFrame` 2023-10-09 23:36:01 -03:00
Bruno Kolenbrander 36b4a79930
Merge pull request #3502 from mejrs/interpreterapi
add PyInterpreterConfig api
2023-10-08 21:22:01 +00:00
mejrs 0cccb9f64b add PyInterpreterConfig api 2023-10-08 22:38:11 +02:00
David Hewitt 1158c08f42 error on passing arguments to `#[new]` and similar attributes 2023-10-08 21:31:59 +01:00
David Hewitt cbd7370b20
Merge pull request #3490 from davidhewitt/ffi-marshal-limited
disable `marshal.rs` on `Py_LIMITED_API`
2023-10-04 19:05:01 +00:00
David Hewitt a4b79dc1e5
Merge pull request #3494 from mejrs/slots
Update PyModuleDef_Slot types
2023-10-04 06:10:25 +00:00
mejrs aa011f4a9d Update PyModuleDef_Slot types 2023-10-03 23:25:45 +02:00
David Hewitt 90cc69ba73
Merge pull request #3488 from davidhewitt/python-3.12
support python 3.12
2023-10-03 19:53:20 +00:00
David Hewitt a1d333a563 emit compile errors on macros inside `#[pymethods]`
Co-authored-by: Bruno Kolenbrander <59372212+mejrs@users.noreply.github.com>
2023-10-02 22:15:29 +01:00
David Hewitt c80a61ee30 disable `marshal.rs` on `Py_LIMITED_API` 2023-10-02 21:36:17 +01:00
David Hewitt 86fc62c5e7 support python 3.12 2023-10-02 20:57:41 +01:00
David Hewitt 2daddb4734 unify 3.12 and pre-3.12 exception handling pathways 2023-09-30 23:27:27 +01:00
David Hewitt f335f42197
Merge pull request #3446 from davidhewitt/relax-import-check
relax multiple-import check to only prevent subinterpreters
2023-09-29 16:35:31 +00:00
David Hewitt 50cb41dd0b
Merge pull request #3458 from davidhewitt/truncate-leap-seconds
truncate leap seconds on `chrono` to `datetime` conversions
2023-09-29 11:47:27 +00:00
David Hewitt 0459532f69 truncate leap seconds on `chrono` to `datetime` conversions 2023-09-24 20:28:43 +01:00
David Hewitt 1e8833e15e always normalize exceptions before raising 2023-09-24 13:38:23 +01:00
David Hewitt f17e703167 return existing module on Python 3.9 and up 2023-09-23 11:13:39 +01:00
David Hewitt 1338020511 relax multiple-import check to only prevent subinterpreters 2023-09-23 11:13:39 +01:00
David Hewitt 5798caf1f8 better `Some`-wrapping for default arguments 2023-09-21 21:14:44 +01:00
David Hewitt bcb01049cc
Merge pull request #3404 from davidhewitt/fix-dealloc
call PyObject_GC_Untrack before deallocating
2023-09-11 05:18:34 +00:00
David Hewitt e28403e772 call PyObject_GC_Untrack before deallocating 2023-09-09 22:29:58 +01:00
David Hewitt 16728c4da2 move PyDict::get_item_with_error to PyDict::get_item 2023-09-09 12:23:06 +01:00
David Hewitt e67b283b25
Merge pull request #3358 from alex/ptr-unsafe-trait
fixes #3325 -- mark `AsPyPointer` as `unsafe trait`
2023-09-04 05:05:56 +00:00
David Hewitt 9e089a5538 fix chrono deprecation warnings 2023-09-02 20:55:53 +01:00
Ryan Lowe b3cf61cea6 add types for built-in singletons 2023-08-26 08:57:34 -04:00
Adam Reichold 12183ad3ed
Merge pull request #3379 from iliya-malecki/main
BigInt speedup
2023-08-19 12:09:28 +00:00
David Hewitt 9336e5b605
Merge pull request #3403 from davidhewitt/ffi-objimpl
update definitions for objimpl.h
2023-08-19 12:02:32 +00:00
Adam Reichold e6293a9608
Merge pull request #3405 from davidhewitt/debug-3.11
fix compile warning on pre-3.12 debug builds
2023-08-19 05:25:57 +00:00
David Hewitt 69475b0a83 update definitions for objimpl.h 2023-08-18 22:17:53 +01:00
David Hewitt 7fce07935c fix compile warning on pre-3.12 debug builds 2023-08-18 22:15:29 +01:00
Adam Reichold 94f15679ab
Merge pull request #3402 from Tpt/io-err-unwrap
Unwrap the underlying PyErr when converting an io::Error back to a PyErr
2023-08-18 16:56:53 +00:00
David Hewitt 15388fd53b
Merge pull request #3401 from messense/fix-issue-3400
Fix memory leak in `PyTypeBuilder::build`
2023-08-18 14:28:36 +00:00
Alex Gaynor df5aa77800
fixes #3325 -- mark `AsPyPointer` as `unsafe trait` 2023-08-18 10:16:34 -04:00
Tpt 6d8e8b302f Unwrap the underlying PyErr when converting an io::Error back to a PyErr
Exposes it directly instead of loosing all information outside the message
2023-08-18 15:56:25 +02:00
messense 2dc1e9a2b7
Fix memory leak in `PyTypeBuilder::build` 2023-08-18 21:13:13 +08:00
David Hewitt c03c787a91
Merge pull request #3393 from alex/drop-other-trait
Remove usage of `AsPyPointer` in `IntoPy<PyObject>` trait implementation
2023-08-18 12:58:07 +00:00
David Hewitt 7f32ed96db
Merge pull request #3396 from Tpt/IntoInnerError
Uses io::Error code when converting io::IntoInnerError to PyErr
2023-08-18 08:27:35 +00:00
Tpt 1062f244ea Pick a relevant ErrorKind when building an io::Error from a OSError subclass 2023-08-17 18:33:51 +02:00
Tpt 7c366cb930 Uses io::Error code when converting io::IntoInnerError to PyErr 2023-08-17 18:25:36 +02:00
Alex Gaynor 9f1b56b659
Remove usage of `AsPyPointer` in `IntoPy<PyObject>` trait implementation 2023-08-17 07:05:52 -04:00
Iliya Malecki d1f0561036 added speedy BigInt extraction 2023-08-17 08:15:50 +01:00
Adam Reichold 9363491d54
Merge pull request #3384 from DataTriny/pyclass_rename_variants
Add  `rename_all` attribute to `#[pyclass]`
2023-08-16 19:06:37 +00:00
David Hewitt 0375d57989
Merge pull request #3391 from alex/drop-trait
Remove usage of `AsPyPointer` in traits for convergint to PyObject
2023-08-16 16:39:46 +00:00
Alex Gaynor c259e77ca2
Remove usage of `AsPyPointer` in traits for convergint to PyObject
Refs #3358
2023-08-16 07:03:57 -04:00
David Hewitt eba2c59778 tidy up some file locations after dual licensing 2023-08-16 08:22:51 +01:00
David Hewitt 82b1e55e2b
Merge pull request #3389 from alex/less-as-py-pointer
Migrate `PyIterator::from_object` and `PyByteArray::from` from `AsPyPointer` to `&PyAny`
2023-08-15 23:12:28 +00:00
Alex Gaynor 1a904a7429
Migrate `PyIterator::from_object` and `PyByteArray::from` from `AsPyPointer` to `&PyAny` 2023-08-15 18:03:56 -04:00
DataTriny b222dbbbcc Add a release note entry 2023-08-15 23:39:45 +02:00
DataTriny f02fe9478d
Make rename_all accept a renaming rule, allow applying it to classes as well 2023-08-15 10:15:48 +02:00
David Hewitt 43b37109de Revert "Fix the pydebug with trace refs and count_allocs for python > 3.7"
This reverts commit c780aa931d.
2023-08-15 08:41:22 +01:00
Alex Gaynor 5061b501a9
Remove IntoPyPointer
it wasn't used in any public APIs following #3359
2023-08-14 16:28:20 -04:00
DataTriny a9e9ec628d
Add attribute to 2023-08-13 18:25:07 +02:00
David Hewitt a541925f00
Merge pull request #3359 from davidhewitt/py-pointer-methods
add as_ptr and into_ptr inherent methods
2023-08-11 19:50:22 +00:00
David Hewitt 8031794f2a
Merge pull request #3378 from GoldsteinE/implicit-builtins
add `__builtins__` to globals in `py.run()` if they're missing
2023-08-11 14:11:31 +00:00
Goldstein 0be94a5442
add `__builtins__` to globals in `py.run()` if they're missing
Python code doesn't like to run without `__builtins__`, so adding them
if missing seems to be a good idea. Also that's what CPython >3.10 does.

See https://github.com/python/cpython/pull/24564
Resolves #3370
2023-08-11 15:48:05 +03:00
David Hewitt 5d7dfe2e95 update pydebug.rs for Python 3.12 2023-08-11 11:54:16 +01:00
David Hewitt 64adab1a76 add as_ptr and into_ptr inherent methods 2023-08-11 10:49:42 +01:00
Tpt dd04d2c4cc Fixes linking of `PyOS_FSPath` on PyPy. 2023-08-09 16:19:17 +02:00
Tpt 1e5a49557d Makes PathBuf FromPyObject implementation work on all os.PathLike
PyOS_FSPath is in abi3-py36
2023-08-08 22:15:56 +02:00
Adam Reichold a371fbe4f8 Implement DoubleEndedIterator for PyListIterator by caching the length while still validating it before access. 2023-08-07 21:37:50 +02:00
Adam Reichold 4ce3e9649f Implement DoubleEndedIterator for PyTupleIterator 2023-08-07 21:37:50 +02:00
David Hewitt 284c42d840 release: 0.19.2 2023-08-01 07:29:04 +01:00
David Hewitt 4e957e8bd4 update object.h definitions for Python 3.12 2023-07-30 15:37:06 +01:00
Juniper Tyree ab783234c8 Added newsfragment 2023-07-29 07:43:17 +00:00
David Hewitt e2c88d5a4e optimize `float` -> `f64` conversions on non-abi3 2023-07-28 20:45:37 +01:00
David Hewitt 34881fc952 add PyAny::downcast_exact 2023-07-28 15:11:56 +01:00
David Hewitt 7a2fc86186
Merge pull request #3342 from davidhewitt/3.12-ffi-check-fixes
fix ffi check failures for 3.12.0b4
2023-07-25 11:59:55 +00:00
David Hewitt 655de94749 fix ffi check failures for 3.12.0b4 2023-07-25 08:25:34 +01:00
Adam Reichold 8ce6c26c81
Merge pull request #3334 from davidhewitt/pyerr-display
add PyErr::display
2023-07-25 05:56:21 +00:00
David Hewitt a15614844d add PyErr::display 2023-07-24 22:14:55 +01:00
Marc Mueller f8ca456f5f Add PyType_GetDict for Python 3.12 2023-07-23 17:00:50 +02:00
David Hewitt ab078258d1 fix exception handling on Python 3.12 2023-07-19 22:33:25 +01:00
Zak Stucke 31b21a71b5 Combined changelog lines 2023-07-19 12:51:14 +03:00
Zak Stucke f2b7e86e2e Prevent traceback loss on conversion to and from PyErr 2023-07-19 12:07:41 +03:00
David Hewitt 2e2dde910a Preserve panic message after exception is normalized 2023-07-18 22:20:41 +01:00
David Hewitt 6f30215566 collect arrays of objects prior to filling tuple in fixed-size conversions 2023-07-16 20:17:02 +01:00
David Hewitt 92b724f64f normalize exception in `PyErr::matches` and `PyErr::get_type` 2023-07-14 13:18:30 +01:00
Adam Reichold ff78b92e77 Start adding a performance section to the guide. 2023-07-09 14:32:59 +02:00
David Hewitt f7f3ff8820 fix FFI definition `Py_EnterRecursiveCall` 2023-07-05 22:52:41 +01:00
David Hewitt 82712aed32 fix `SystemError` raised from `PyUnicodeDecodeError_Create` on PyPy 3.10 2023-07-05 11:10:02 +01:00
Adam Reichold 54ab9090be
Merge pull request #3269 from grantslatton/timezone-conversion-bugfix
Fix fixed offset timezone conversion bug.
2023-07-04 18:22:13 +00:00