Commit Graph

443 Commits

Author SHA1 Message Date
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
David Hewitt 6666c335e6 add PyState_*Module definitions for PyPy 2023-07-04 08:57:50 +01:00
David Hewitt 7d357ad992 release: 0.19.1 2023-07-03 16:18:24 +01:00
David Hewitt 0e9c041e97
Merge pull request #3289 from davidhewitt/pypy-3.10
support PyPy 3.10
2023-07-03 12:53:16 +00:00
David Hewitt 9f2176c126 support PyPy 3.10 2023-07-03 11:26:45 +01:00
Alex Gaynor 0b78bb851e
Allow `#[new]` to return existing instances
fixes #2384
2023-07-02 19:57:53 -04:00
Adam Reichold e006b34b5e Apparently, PySet_Add does not steal a reference, hence we should not forget to clean up ours. 2023-07-02 20:43:43 +02:00
Adam Reichold afc1d4cc42
Merge pull request #3281 from davidhewitt/set-discard
handle exceptions properly in `PySet::discard`
2023-06-28 17:09:01 +00:00
David Hewitt c0b9502c0e handle exceptions properly in `PySet::discard` 2023-06-28 08:54:06 +01:00
David Hewitt 4867ef8dd3 stop suppressing unrelated exceptions in `PyAny::hasattr` 2023-06-27 23:20:22 +01:00
Adam Reichold b5a1ca058d Extended range of supported versions of `indexmap` optional dependency to include version 2. 2023-06-26 23:23:12 +02:00
David Hewitt db91642bae add `PyDict::get_item_with_error` for PyPy 2023-06-25 19:26:08 +01:00
Grant Slatton b1e7ed8a58 Fix fixed offset timezone conversion bug.
See https://github.com/PyO3/pyo3/issues/3267
2023-06-25 11:06:46 -07:00
Adam Reichold d7e147509b Add Python::with_pool as a safer alternative to Python::new_pool. 2023-06-21 08:05:19 +02:00
Adam Reichold 71ed4e17c7
Merge pull request #3256 from PyO3/dependabot/cargo/unindent-0.2.1
Update unindent requirement from 0.1.4 to 0.2.1
2023-06-20 20:05:17 +00:00
Adam Reichold 430716ff4d Add changelog entry for bumping hashbrown dependency. 2023-06-20 19:41:45 +02:00
Adam Reichold 689033cd80 Extend changelog of indoc bump to include related unindent change as well. 2023-06-20 19:41:02 +02:00
David Hewitt bdf51ab241
Merge pull request #3248 from ijl/py312-exc
Add PyErr_GetRaisedException(), PyErr_SetRaisedException() to FFI
2023-06-18 21:45:14 +00:00
ijl 9e9a6e9ebd Add PyErr_GetRaisedException(), PyErr_SetRaisedException() to FFI
These are new and part of the stable API as of v3.12.0a6.

PyErr_Fetch(), PyErr_Restore(), and PyErr_NormalizeException()
were simultaneously deprecated in favor of these.

python/cpython@feec49c407
2023-06-16 14:49:22 +00:00
David Hewitt e55e1721a5
Merge pull request #3222 from krpatter-intc/getitem_example
simple getitem example
2023-06-16 06:58:49 +00:00
Patterson, Kevin R 4fab62545a simple getitem example 2023-06-15 16:39:25 -05:00
David Hewitt 527f3c286b
Merge pull request #3239 from alex/syn-2
Upgrade to syn 2
2023-06-14 16:49:25 +00:00
Alex Gaynor afbb1d435c
Upgrade to syn 2 2023-06-14 07:03:33 -04:00
Adam Reichold 4bfa5be616
Merge pull request #3238 from davidhewitt/version-bumps
add changelog for #3237
2023-06-14 06:08:22 +00:00
Adam Reichold ba0c7e15b3
Merge pull request #3156 from adriangb/frozenset-ops
Add `PyFrozenSetBuilder`
2023-06-14 06:06:32 +00:00
David Hewitt 80c66ecc95 add changelog for #3237 2023-06-13 22:41:24 +01:00
David Hewitt 4f3fcdbf0f remove all functionality deprecated in PyO3 0.18 2023-06-13 22:27:43 +01:00
Adrian Garcia Badaracco a28641af68
Add `PyFrozenSetBuilder` 2023-06-13 15:59:35 -05:00
David Hewitt 199261f436
Merge pull request #3197 from mhils/ipaddr
Add `IpAddr` <-> `ipaddress.IPv(4/6)Address` conversion
2023-06-12 04:00:43 +00:00
Maximilian Hils 980f05a88e Add `IpAddr` <-> `ipaddress.IPv(4/6)Address` conversion 2023-06-08 13:17:45 +02:00
bors[bot] dbf7b233aa
Merge #3203
3203: support ordering magic methods for `#[pyclass]` r=adamreichold a=davidhewitt

Closes #2089 

This adds `__lt__`, `__le__`, `__eq__`, `__ne__`, `__gt__`, and `__ge__` as per the Python implementations of what we call `__richcmp__`.

There's a UI test confirming that the user cannot implement split forms and `__richcmp__` simultaneously.

There's also a benchmark comparing implementing these split methods against using `__richcmp__`. I couldn't see a meaningful performance difference, so I'm tempted to deprecate `__richcmp__`, given that's not a magic method which exists in Python. Potentially we can provide options such as the opt-in `#[pyclass(eq, ord)]` to avoid boilerplate for people who don't want to implement six different methods.



Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2023-06-05 07:13:23 +00:00
Adam Reichold 5738edfdd4 Bump MSRV to 1.56 2023-06-04 23:02:30 +01:00
David Hewitt 8850d5d384 support ordering magic methods for `#[pyclass]` 2023-06-04 13:58:18 +01:00
bors[bot] fa949ff627
Merge #3198
3198: Add abi3 + num_bigint conversion r=davidhewitt a=youknowone

<!--
Please consider adding the following to your pull request:
 - an entry for this PR in newsfragments - see [https://pyo3.rs/main/contributing.html#documenting-changes]
 - docs to all new functions and / or detail in the guide
 - tests for all new or changed functions

PyO3's CI pipeline will check your pull request. To run its tests
locally, you can run ```cargo xtask ci```. See its documentation
 [here](https://github.com/PyO3/pyo3/tree/main/xtask#readme).
-->

Fix #3196

Co-authored-by: Jeong YunWon <jeong@youknowone.org>
2023-06-02 19:06:50 +00:00
Jake Lishman 8d98b4248e
Fix `abi3` conversion of `__complex__` classes
Python classes that were not `complex` but implemented the `__complex__`
magic would have that method called via `PyComplex_AsCComplex` when
running against the full API, but the limited-API version
`PyComplex_RealAsDouble` does not attempt this conversion.  If the input
object is not already complex, we can call the magic before proceeding.
2023-06-02 10:09:45 +01:00
Jeong YunWon 6d830e05cd Add abi3 + num_bigint conversion 2023-06-02 16:17:49 +09:00
David Hewitt 2500e22e13 release: 0.19.0 2023-05-31 13:53:37 +01:00
bors[bot] 32c335e072
Merge #3168 #3176
3168: Do not apply deferred ref count updates and prevent the GIL from being acquired inside of __traverse__ implementations. r=davidhewitt a=adamreichold

Closes #2301
Closes #3165


3176: Prevent dropping unsendable classes on other threads. r=davidhewitt a=adamreichold

Continuing the discussed from https://github.com/PyO3/pyo3/pull/3169#issuecomment-1556571504 and https://github.com/PyO3/pyo3/pull/3169#issuecomment-1556661723:

We already have checks in place to avoid borrowing these classes on other threads but it was still possible to send them to another thread and drop them there (while holding the GIL).
    
This change avoids running the `Drop` implementation in such a case even though Python will still free the underlying memory. This might leak resources owned by the object, but it avoids undefined behaviour due to access the unsendable type from another thread.
    
This does assume that the object was not unsafely integrated into an intrusive data structures which still point to the now freed memory. In that case, the only recourse would be to abort the process as freeing the memory is unavoidable when the tp_dealloc slot is called. (And moving it elsewhere into a new allocation would still break any existing pointers.)

Co-authored-by: Adam Reichold <adam.reichold@t-online.de>
2023-05-25 18:18:46 +00:00
Adam Reichold 810ad00a76 Do not apply deferred ref count updates and prevent the GIL from being acquired inside of implementations. 2023-05-25 20:01:35 +02:00
Adam Reichold 501ff8a17d Prevent dropping unsendable classes on other threads.
We already have checks in place to avoid borrowing these classes on other
threads but it was still possible to send them to another thread and drop them
there (while holding the GIL).

This change avoids running the `Drop` implementation in such a case even though
Python will still free the underlying memory. This might leak resources owned by
the object, but it avoids undefined behaviour due to access the unsendable type
from another thread.

This does assume that the object was not unsafely integrated into an intrusive
data structures which still point to the now freed memory. In that case, the
only recourse would be to abort the process as freeing the memory is unavoidable
when the tp_dealloc slot is called. (And moving it elsewhere into a new
allocation would still break any existing pointers.)
2023-05-25 19:10:42 +02:00
Kang Seonghoon 24343f2caa Fix a span site of `_slf` for custom receivers. 2023-05-23 10:25:57 +09:00
David Hewitt 82a879ff6b add `PyAny::is_exact_instance` and `PyAny::is_exact_instance_of` 2023-05-21 12:44:54 +02:00
David Hewitt 248230b8e4 refactor PyAny::is_instance_of for performance 2023-05-18 22:25:27 +01:00
Adam Reichold b9766cfa11 Add PyClass::get and Py::get for GIL-independent access to frozen classes. 2023-05-18 08:57:55 +02:00
Stu Hood 20c5618160
Add support for combining the `#[new]` and `#[classmethod]` method types. 2023-05-16 15:51:14 -07:00
Adam Reichold 91cdfe4f7d Fix patch version of our dependency on syn. 2023-05-10 22:31:15 +02:00
bors[bot] 4a0bea2e93
Merge #3062
3062: Stop panic on `fmt::Display` r=davidhewitt a=samuelcolvin

Closes #3060

Co-authored-by: Samuel Colvin <s@muelcolvin.com>
2023-05-10 05:52:40 +00:00
Adrien 1676100dfd Added a few lines to document the main difference between maturin and setuptools-rust as far as building manylinux-compliant wheels is concerned.
Added newfragment
2023-05-09 14:54:30 +02:00
Samuel Colvin 5aff2ccc9e stop panic on to_string, report using write_unraisable instead 2023-05-09 12:54:56 +02:00
bors[bot] c27a6333d6
Merge #3029
3029: use dynamic trampoline for all getters and setters r=adamreichold a=davidhewitt

This is an extension to the "trampoline" changes made in #2705 to re-use a single trampoline for all `#[getter]`s (and similar for all `#[setters]`). It works by setting the currently-unused `closure` member of the `ffi::PyGetSetDef` structure to point at a new `struct GetSetDefClosure` which contains function pointers to the `getter` / `setter` implementations.

A universal trampoline for all `getter`, for example, then works by reading the actual getter implementation out of the `GetSetDefClosure`.

Advantages of doing this:
- Very minimal simplification to the macro code / generated code size. It made a 4.4% reduction to `test_getter_setter` generated size, which is an exaggerated result as most code will probably have lots of bulk that isn't just the macro code.

Disadvantages:
- Additional level of complexity in the `getter` and `setter` trampolines and accompanying code.
- To keep the `GetSetDefClosure` objects alive, I've added them to the static `LazyTypeObject` inner.
- Very slight performance overhead at runtime (shouldn't be more than an additional pointer read). It's so slight I couldn't measure it.

Overall I'm happy to either merge or close this based on what reviewers think!

Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2023-05-09 08:50:45 +00:00
bors[bot] 7b443cf813
Merge #2981
2981: Remove 0.17 deprecations r=adamreichold,davidhewitt a=davidhewitt

Since #2980 starts a breaking change for 0.19, let's also clean up all 0.17's deprecations.

I've removed `Python::acquire_gil` in its own commit, as that was a reasonably chunky removal.

Co-authored-by: Adam Reichold <adam.reichold@t-online.de>
Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2023-05-09 08:08:06 +00:00
David Hewitt 77eb9bd480 news entry for 0.17 deprecations removals 2023-05-09 09:39:23 +02:00
bors[bot] c9f383a735
Merge #3142
3142: Do not store return values in locals so that holders benefit from lifetime extension for temporaries. r=davidhewitt a=adamreichold

Closes #3138

Co-authored-by: Adam Reichold <adam.reichold@t-online.de>
2023-05-09 07:23:55 +00:00
David Hewitt 1ea57cb9ad use dynamic trampoline for all getters and setters 2023-05-09 08:09:59 +01:00
bors[bot] 6281b47954
Merge #3004
3004: Unwrap dynamic error types when inner is simple `PyErr` r=davidhewitt,adamreichold,mejrs a=BlueGlassBlock

This is the first part of suggested improvements in #2998.

This change will make bubbled `PyErr` wrapped in `eyre::Report` / `anyhow::Error` bubble up unchanged, instead of being wrapped in a `PyRuntimeError`.

Co-authored-by: BlueGlassBlock <blueglassblock@outlook.com>
2023-05-09 06:18:33 +00:00
BlueGlassBlock fdd43d0685 feat: unwrap dyn Err when inner is simple PyErr 2023-05-09 07:17:10 +01:00
Adrian Garcia Badaracco 16d333f9d0
Add BaseExceptionGroup for Python >= 3.11 2023-05-07 15:08:43 -05:00
Adam Reichold a60945faa2 Do not store return values in locals so that holders benefit from lifetime extension for temporaries. 2023-05-06 16:26:18 +02:00
bors[bot] 1cdac4fde4
Merge #2980
2980: support `text_signature` on `#[new]` r=adamreichold a=davidhewitt

Closes #2866 

This is a breaking change for 0.19.0, because it starts autogenerating `text_signature` for `#[new]`. This could affect runtime behaviour if the user is relying on the class docs at runtime for some reason.

Guide & tests all updated accordingly.

`#[pyclass(text_signature = "...")]` is deprecated by this PR, however if it's set, it will be used in preference to `#[new]`.

(The signature / `text_signature` from `#[new]` will simply be ignored in this case. I figure that when users fix their deprecation warnings by removing `#[pyclass(text_signature = "...")]` then the `#[new]` signatures will start flowing properly, and this is good enough.)

Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
Co-authored-by: Adam Reichold <adam.reichold@t-online.de>
2023-05-04 16:51:54 +00:00
bors[bot] 22e77b0213
Merge #3131
3131: Extend lifetime of GIL token associated with PyRef(Mut). r=mejrs a=adamreichold



Co-authored-by: Adam Reichold <adam.reichold@t-online.de>
2023-05-04 11:46:09 +00:00
David Hewitt 8bd17f02c7 support `text_signature` on `#[new]` 2023-05-04 07:15:11 +01:00
Adam Reichold 63a9093510 Extend lifetime of GIL token associated with PyRef(Mut). 2023-05-01 20:57:08 +02:00
BlueGlassBlock 1d6ab21781
fix: change to from_item_all 2023-04-26 19:47:07 +08:00
BlueGlassBlock f58f55dab4
doc: add news frags 2023-04-25 19:40:59 +08:00
Doug Goldstein 8e0bde14c9 implement Decimal to rust_decimal conversions
Implement conversion between rust_decimal::Decimal and decimal.Decimal
from Python's stdlib. The C API does not appear to be exposed on the
Python side so we need to call into it via Python.
2023-04-22 19:55:21 +02:00
David Hewitt eb4ba53251 Rename sequence `.list()` and `.tuple()` to `.to_list()` and `.to_tuple()` 2023-04-18 20:52:49 +01:00
David Hewitt bfcc1f8c27 update release notes for 0.18.3 2023-04-13 22:47:55 +01:00
bors[bot] a0e285b497
Merge #3066 #3098
3066: Improve default value for `None` in `text_signature` r=davidhewitt a=messense

xref #2863

3098: readme: add new pyo3 article r=adamreichold a=davidhewitt

With thanks to `@ohadravid` for the great piece!

Co-authored-by: messense <messense@icloud.com>
Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2023-04-12 07:40:50 +00:00
ijl 6ee2174fec Define _PyDict_Contains_KnownHash() FFI for CPython 3.10 or later 2023-04-09 14:36:42 +00:00
messense 57dbc94293
Improve default value for `None` in `text_signature` 2023-03-29 10:14:44 +08:00
Solomon Ucko 7e2f732d7a fix typo DateType -> DateTimeType, fixes #3069 2023-03-28 18:45:39 +02:00
bors[bot] ba6261c8e7
Merge #3015
3015: Implement wrapper for `PyASCIIObject.state` bitfield accesses r=davidhewitt a=decathorpe

This is a first draft of my attempt to fix #1824 "properly" by writing a C wrapper for the `PyASCIIObject.state` bitfield accesses, as proposed here: https://github.com/PyO3/pyo3/issues/1824#issuecomment-1406909504

---

The original argument for making these functions `unsafe` is still valid, though - bitfield memory layout is not guaranteed to be stable across different C compilers, as it is "implementation defined" in the C standard. However, short of having CPython upstream provide non-inlined public functions to access this bitfield, this is the next best thing, as far as I can tell.

I've removed the `#[cfg(target_endian = "little")]` attributes from all things that are un-blocked by fixing this issue on big-endian systems, except for three tests, which look like expected failures considering that they do not take bit/byte order into account (for example, when writing to the bitfield).

- `ffi::tests::ascii_object_bitfield`
- `types::string::tests::test_string_data_ucs2_invalid`
- `types::string::tests::test_string_data_ucs4_invalid`

All other tests now pass on both little-endian and big-endian systems.

---

I am aware that some parts of this PR are probably not in a state that's acceptable for merging as-is, which is why I'm filing this as a draft. Feedback about how to better integrate this change with pyo3-ffi would be great. :)

In particular, I'm unsure whether the `#include` statements in the C files are actually correct across different systems. I have only tested this on Fedora Linux so far.

I'm also open to changing the names of the C functions that are implemented in the wrapper. For now I chose the most obvious names that shouldn't cause collisions with other symbols.

Co-authored-by: Fabio Valentini <decathorpe@gmail.com>
2023-03-28 07:27:02 +00:00
Fabio Valentini 40d6d4797f
Add wrapper for PyASCIIObject state bitfield accesses based on bindgen 2023-03-26 17:11:01 +02:00
bors[bot] ebedcfb8b2
Merge #3050
3050: Improve default values for str, numbers and bool in `text_signature` r=davidhewitt a=messense

xref #2863

Co-authored-by: messense <messense@icloud.com>
2023-03-25 07:07:06 +00:00
bors[bot] e2bcca4771
Merge #3063
3063: update release notes for 0.18.2 r=davidhewitt a=davidhewitt

Changelog entry & cargo.toml changes from 0.18.2 

Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2023-03-24 21:44:48 +00:00
David Hewitt e7e58ba51e update release notes for 0.18.2 2023-03-24 20:40:06 +00:00
bors[bot] e5e8c7a6d0
Merge #2975 #3022 #3023
2975: RFC: Add GILProtected synchronization primitive and use it for LazyTypeObjectInner. r=davidhewitt a=adamreichold

I would also like to use that type in rust-numpy and it seems we can avoid ~~both a manual unsafe impl and~~ a full blown mutex if we apply it to `LazyTypeObjectInner`.

One downside might be that it ties us closer to the GIL when we want to enable nogil experimentation, but on the other hand, it may also help by reifying the GIL usage. (This is currently limited to comments in unsafe code in rust-numpy for example.)

3022: Fix function name shadowing r=davidhewitt a=mejrs

Fixes https://github.com/PyO3/pyo3/issues/3017

3023: Emit a better error for bad argument names r=davidhewitt a=mejrs

This will emit a better error for code like 
```rust
#[pyfunction]
fn output([a,b,c]: [u8;3]) {}
```



Co-authored-by: Adam Reichold <adam.reichold@t-online.de>
Co-authored-by: mejrs <59372212+mejrs@users.noreply.github.com>
2023-03-23 08:04:11 +00:00
mejrs 4966d93494 Fix function name shadowing 2023-03-23 07:33:14 +00:00
bors[bot] 28814f2978
Merge #3055
3055: Fix compile error when trying to use static slot methods, fixes: #3039 r=davidhewitt a=willstott101

Whilst having static slot methods is of dubious value in the first place, there's little reason not to support it by bringing the different function call macros more in-line with each other.

I had no idea which test file to use so I just made a new one... `test_methods.rs` has no slots in and the test files that do use slots seem to be specific to their protocol. Let me know if you'd like the test somewhere else.

Thanks!

Co-authored-by: Will Stott <willstott101@gmail.com>
2023-03-23 07:23:38 +00:00
bors[bot] ebd417c9cc
Merge #3044
3044: Add `PyTuple::to_list` r=davidhewitt a=davidhewitt

Companion to #3043. I've included benchmarks which suggests that this method is indeed about 25% faster on my machine.

Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2023-03-18 21:43:37 +00:00
David Hewitt 2c11b25fee Add `PyTuple::to_list` 2023-03-18 14:44:45 +00:00
Will Stott bcdb17db5b Fix compile error when trying to use static slot methods 2023-03-18 11:16:52 +00:00
messense 79a70f3923
Improve default values for str, numbers and bool in `text_signature` 2023-03-16 11:06:51 +08:00
David Hewitt d3f5fed416 `PyList::as_tuple()` -> `PyList::to_tuple()` 2023-03-12 16:27:15 +00:00
Samuel Colvin b388f79a5f
add fragment 2023-03-12 12:46:59 +00:00
David Hewitt fbebc285c0 fix const-ness of some FFI name & doc members 2023-03-10 16:02:52 +00:00
bors[bot] 550473fb1d
Merge #3031
3031: mangle exported functions for PyPy r=davidhewitt a=mattip

I run HEAD of PyO3 with HEAD of some PyPy branches, and noticed that the py3.10 branch (which implements python3.10) [fails to properly build](https://github.com/pypy/binary-testing/actions/runs/4334873617/jobs/7569059852#step:6:179). The failure was a missing export:
```
 /home/runner/work/binary-testing/binary-testing/pyo3/src/exceptions.rs:715: \
    undefined reference to `PyExc_EncodingWarning'
          collect2: error: ld returned 1 exit status
```

So I grepped around in the code for `Py_3_10` to see what new functions were added and found a few that needed PyPy-specific exports.

Co-authored-by: Matti Picus <matti.picus@gmail.com>
2023-03-10 09:39:54 +00:00
Matti Picus 232f9fb8ab add newsfragment 2023-03-10 10:16:24 +11:00
Antoine Romero-Romero a629e8267a feat: add #[pyo3(get, set)] for Cell 2023-03-09 23:09:30 +00:00
Adam Reichold 39d19113fa Remove stale references to tox.ini from template substitution scripts. 2023-03-05 09:17:34 +01:00
David Hewitt 7a2b1f0e13 fix `non_snake_case` lint for `#[pyfunction]` generated code 2023-02-28 08:44:17 +00:00
David Hewitt 226bf97ec0 Fix `clippy::redundant_closure` lint firing for pyfunction defaults 2023-02-27 22:10:06 +00:00
Adam Reichold 9534749d8b Add GILProtected synchronization primitive replacement and use it for LazyTypeObjectInner. 2023-02-23 09:38:02 +01:00
bors[bot] bbaceb88b4
Merge #2899
2899: RFC: Provide a special purpose FromPyObject impl for byte slices r=davidhewitt a=adamreichold

This enables efficiently and safely getting a byte slice from either bytes or byte arrays.

The main issue I see here is discoverability, i.e. should this be mention in the docs of `PyBytes` and `PyByteArray` or in the guide?

It is also not completely clear whether this really _fixes_ the issue.

Closes #2888 

Co-authored-by: Adam Reichold <adam.reichold@t-online.de>
2023-02-22 22:13:56 +00:00
Adam Reichold de79ebc5f8 Provide a special purpose FromPyObject impl to efficiently and safely get a byte slice from either bytes or byte arrays. 2023-02-22 22:07:59 +01:00
David Hewitt f239d2d075 allow `create_exception!` to place the exception in a `dotted.module` 2023-02-22 20:08:53 +00:00