David Hewitt
5bab0e9409
use simplified PyIter_Check on CPython 3.7
2023-02-03 07:55:44 +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]
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
mejrs
cadcabaf04
Feedback
2023-01-28 15:35:31 +01: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
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
Samuel Colvin
3c9ace03d8
add Ellipsis() and is_ellipsis() methods, fix #2906
2023-01-27 06:40:02 +00:00
David Hewitt
5667a095d6
hygiene: fix `#[pymethods(crate = "...")]`
2023-01-27 06:34:12 +00: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
mejrs
fe7b1eed04
Update `downcast` documentation
2023-01-24 19:15:32 +01:00
David Hewitt
255d9bacce
tidy up implementation of pyclass `tp_dealloc`
2023-01-19 21:31:59 +00:00
bors[bot]
dbb108c2c5
Merge #2893
...
2893: rename `wrap_pyfunction` impl to `wrap_pyfunction_impl` r=messense a=davidhewitt
I mistyped the other day and wrote `wrap_pyfunction(f, py)` without the `!` to invoke the macro, and `rust-analyzer` imported the hidden symbol `pyo3::impl_::pyfunction::wrap_pyfunction`. Took me a moment to realise the compilation failure was because I'd forgotten the `!`.
This PR just renames that hidden symbol to `pyo3::impl_::pyfunction::wrap_pyfunction_impl` so it doesn't clash with the user-facing macro.
Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2023-01-19 20:08:59 +00:00
David Hewitt
586fed2c4b
send errors in `__releasebuffer__` to `sys.unraisablehook`
2023-01-19 19:10:06 +00:00
David Hewitt
89d4ae1dbf
rename `wrap_pyfunction` impl to `wrap_pyfunction_impl`
2023-01-19 08:51:44 +00:00
bors[bot]
72c561ce13
Merge #2882
...
2882: inspect: gate behind `experimental-inspect` feature r=davidhewitt a=davidhewitt
This is the last thing I want to do before preparing 0.18 release.
The `pyo3::inspect` functionality looks useful as a first step towards #2454 . However, we don't actually make use of this anywhere within PyO3 yet (we could probably use it for better error messages). I think we also have open questions about the traits which I'd like to resolve before committing to these additional APIs. (For example, this PR adds `IntoPy::type_output`, which seems potentially misplaced to me, the `type_output` function probably wants to be on a non-generic trait e.g. `ToPyObject` or maybe #2316.)
As such, I propose putting these APIs behind an `experimental-inspect` feature gate for now, and invite users who find them useful to contribute a finished-off design.
Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2023-01-17 07:31:09 +00:00
David Hewitt
20ca3be659
inspect: gate behind `experimental-inspect` feature
2023-01-15 12:41:23 +00:00
David Hewitt
8f48d157d6
deprecate required arguments after option arguments without signature
2023-01-15 10:17:20 +00:00
bors[bot]
8af48bbb53
Merge #2796
...
2796: Forward cfgs on pyclass fields to the method defs r=davidhewitt a=mejrs
With this and the cfg_attr PR, I don't need cfg_eval at all anymore :)
- [x] needs some more tests
Co-authored-by: mejrs <>
2022-12-29 16:28:26 +00:00
bors[bot]
cedb5aecb2
Merge #2843
...
2843: remove functionality deprecated in 0.16 r=davidhewitt a=davidhewitt
Simple cleanup to remove all functionality marked deprecated in the 0.16 releases.
Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2022-12-28 12:24:59 +00:00
David Hewitt
f2608a923c
remove functionality deprecated in 0.16
2022-12-28 12:23:53 +00:00
bors[bot]
c2adf14f69
Merge #2842
...
2842: Stop leaking in `new_closure` r=adamreichold a=davidhewitt
This is a rebase of #2690 which simplifies the `MaybeLeaked` abstraction from that PR with just `Cow<'static, CStr>`.
This enabled me to annotate with `FIXME` all the places where we still leak; I wonder if we could potentially use `GILOnceCell` in future and statics to avoid those. As those callsities are in `#[pyclass]` and `#[pyfunction]` these are effectively in statics anyway, but it would be nice to tidy up.
Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2022-12-28 08:13:58 +00:00
David Hewitt
1e8206c0b8
Stop leaking in `new_closure`
2022-12-28 07:51:50 +00:00
David Hewitt
24032fe110
pypy: re-enable PyFunction on 3.8+
2022-12-27 14:32:43 +00:00
David Hewitt
30c66fdb8b
ci: fix flaky test_pyobject_drop_without_gil_doesnt_decrease_refcnt
2022-12-27 00:49:54 +01:00
David Hewitt
a47079d858
move GILOnceCell initialization detail to the type-level docs
2022-12-26 20:38:25 +00:00
Benoît du Garreau
01fcfedbe5
Add `GILOnceCell::get_or_try_init`
2022-12-26 20:28:18 +00:00
David Hewitt
010dd509d7
pypy: enable `PyList::get_item_unchecked`
2022-12-25 08:45:36 +00:00
David Hewitt
33871b7aea
allow **kwargs to take arguments which conflict with positional-only parameters
2022-12-17 07:22:28 +00:00
mejrs
44310ec7e0
Forward cfgs on pyclass fields to the method defs
2022-12-06 22:38:32 +01:00
David Hewitt
3295e35a4b
accept any iterator for `PySet::new` and `PyFrozenSet::new`
2022-12-04 09:54:34 +00:00
Shantanu
95f041281f
Mention `into_py` in docs for PyTuple::new
...
I'm new to Rust / PyO3, and it took me a little bit to figure this out :-)
2022-11-23 16:34:59 -08:00
Georg Brandl
717e09be13
Fix coding style in docstrings.
2022-11-23 07:42:17 +01:00
bors[bot]
40340062b2
Merge #2769
...
2769: PySlice: fix isize->long truncation in initialization r=davidhewitt a=birkenfeld
Co-authored-by: Georg Brandl <georg@python.org>
2022-11-22 19:04:30 +00:00
Georg Brandl
cbae47d171
PySlice: fix isize->long truncation in initialization
...
Fixes #2768
2022-11-22 12:04:32 +01:00
Georg Brandl
99c8dea30e
Use Python::get_type() instead of PyTypeInfo::type_object()
...
The former needs one less import and uses a familiar object.
2022-11-20 15:16:18 +01:00
Georg Brandl
21fd1a91d0
Make `downcast()` methods inline
2022-11-20 13:14:54 +01:00
Georg Brandl
249c0209fd
Add {Py,PyAny}::downcast_unchecked to replace try_from_unchecked calls
2022-11-18 07:00:40 +01:00
Georg Brandl
d6ac4d51b7
Replace explicit `try_from` usage by `downcast`
2022-11-18 07:00:40 +01:00
Georg Brandl
7d4dfc32b3
PyAny::downcast(): relax lifetime bounds
2022-11-18 07:00:40 +01:00
Georg Brandl
c489809938
Py/PyAny: deprecate cast_as() in favor of downcast()
...
They are (practically) identical on PyAny, and `downcast()` is the more
useful name.
2022-11-18 07:00:40 +01:00
Georg Brandl
1d20f2a531
Export warning classes and add PyErr::warn_explicit() ( #2742 )
2022-11-17 19:30:48 +01:00
Adam Reichold
f5735614fb
Merge pull request #2744 from PyO3/chrono-expect-value-error
...
Replace hidden panics on invalid values passed to chrono by ValueError.
2022-11-17 06:47:19 +01:00
Georg Brandl
62e2d6094e
crate doc: add missing links to chrono subpage/crate doc ( #2743 )
2022-11-16 20:39:59 +00:00
Adam Reichold
f8ce3408f4
Replace hidden panics on invalid values passed to chrono by ValueError.
2022-11-16 20:23:00 +01:00
Adam Reichold
4ffe0963b8
Make Clippy happy again by avoid deprecated constructors from chrono.
2022-11-15 22:06:02 +01:00
Adam Reichold
694ef1ea39
Make Clippy happy again by removing supposedly unnecessary casts.
2022-11-15 21:50:29 +01:00
Chih Wang
d060a19303
Add support for std::num::NonZero integer types ( #2730 )
2022-11-13 10:54:55 +00:00
Alex Gaynor
f7a487b809
Use a TypeError, rather than a ValueError, when refusing to treat a str as a Vec
...
This is far more consistent with how these exceptions are usually used
2022-11-07 07:48:13 -05:00
Bruno Kolenbrander
6766d9f93b
Merge pull request #2686 from dalcde/closure-name-doc
...
Support passing name and doc to new_closure.
2022-11-06 17:35:20 +01:00
messense
736e97556d
Disable `PyModule::filename` on PyPy
2022-10-31 15:45:50 +08:00
Dexter Chua
9201a7dd48
Support passing name and doc to PyCFunction::new_closure. Fixes #2665
2022-10-29 12:26:09 +08:00
David Hewitt
8e8b484169
add `#[pyo3(signature = (...))]` attribute ( #2702 )
2022-10-25 07:23:21 +01:00
David Hewitt
747d791f1f
introduce trampolines for methods ( #2705 )
2022-10-25 07:22:36 +01:00
David Hewitt
1c3c5f2c5f
Merge pull request #2661 from davidhewitt/std-conversions
...
refactor: move std conversions into common module
2022-10-20 07:58:02 +01:00
David Hewitt
39a68cf7ac
Merge pull request #2687 from saethlin/main
...
Avoid calling slice::from_raw_parts with a null pointer
2022-10-20 07:34:39 +01:00
David Hewitt
fb34ed1694
add more coverage
2022-10-20 07:29:42 +01:00
David Hewitt
c76916a084
refactor: move std conversions into common module
2022-10-19 21:36:39 +01:00
Ben Kimock
7ff5ab770a
Avoid calling slice::from_raw_parts with a null pointer
2022-10-18 17:09:27 -04:00
Georg Brandl
676227d2a1
Make `is_instance()` and `is_subclass()` take `&PyAny` ( #2695 )
2022-10-18 19:22:23 +02:00
Bruno Kolenbrander
4a04603c2c
Don't use intocallback in method macros ( #2664 )
...
* Don't use intocallback in method macros
Co-authored-by: mejrs <>
2022-10-16 10:35:58 +01:00
David Hewitt
125af9b7de
Merge pull request #2676 from PyO3/exact-iter
...
Add more implementations of ExactSizeIterator when iterating built-in Python data structures.
2022-10-13 21:28:04 +01:00
Adam Reichold
f456ed7586
Also relax the PySequence check when extracting fixed-sized arrays.
2022-10-13 09:43:45 +02:00
Adam Reichold
9847530cc8
Fix code blocks containing HTML-related characters missing backticks.
2022-10-13 07:33:11 +02:00
Adam Reichold
cd361dc5cc
Add more implementations of ExactSizeIterator when iterating built-in Python data structures.
2022-10-11 18:21:02 +02:00
David Hewitt
372176630e
guide: doctest function/ subpages
2022-09-27 07:52:14 +01:00
smheidrich
bc00e9ff12
Improve PyLong/PyFloat doc links to PyAny::extract
2022-09-24 20:59:04 +02:00
smheidrich
9572220f6c
Fix links to ToPyObject in types docs
2022-09-24 20:08:43 +02:00
Federico Dolce
eced1593f5
Fixed wrong proptest in chrono conversion module
2022-09-22 14:48:55 +02:00
Federico Dolce
63f7df905d
Add chrono 0.4 integration ( #2612 )
...
Co-authored-by: Ivan Tham <pickfire@riseup.net>
Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2022-09-22 09:00:09 +02:00
David Hewitt
81a79778a2
Merge pull request #2631 from PyO3/relax-extract-sequence-pre-0.17
...
Relax extract_sequence to the status quo before 0.17 was released
2022-09-21 11:52:34 +02:00
David Hewitt
a0be791577
Merge pull request #2630 from davidhewitt/option-pyclass-arg
...
pyfunction: fix compile error for Option<&T> argument with a default
2022-09-21 11:44:55 +02:00
Adam Reichold
b6c6f7f2b6
Fix #2615 by relaxing the type check in extract_sequence.
...
This allows us to handle types like one-dimensional NumPy arrays which implement
just enough of the sequence protocol to support the extract_sequence function
but are not an instance of the sequence ABC.
2022-09-21 09:47:05 +02:00
David Hewitt
c445eba28d
pyfunction: fix compile error for Option<&T> argument with a default
2022-09-20 15:44:55 +02:00
Mario Rugiero
d72989f986
Enable BigInt conversion for PyPy ( #2626 )
...
* Enable bigint conversion for PyPy
* Update src/conversions/num_bigint.rs
* Add a changelog entry for PyPy `num-bigint` support
Co-authored-by: messense <messense@icloud.com>
2022-09-20 18:55:14 +08:00
David Hewitt
ab8f940e46
docs: require docs on all public APIs
2022-09-07 07:42:23 +01:00
Ivan “CLOVIS” Canet
453e3559d3
Python types: use Cow instead of bare references
2022-09-06 21:30:39 +02:00
Ivan “CLOVIS” Canet
0e6ae6489f
Declare the Python type of Rust collections
2022-09-06 21:30:38 +02:00
Ivan “CLOVIS” Canet
2ffc4bb6f6
Declare the Python type of Rust primitives
2022-09-06 21:30:38 +02:00
Ivan “CLOVIS” Canet
d7c1a2906a
IntoPy and FromPyObject allow the retrieval of the type information
2022-09-06 21:30:36 +02:00
Ivan “CLOVIS” Canet
8898bc9900
Represent Python types
...
The TypeInfo structure represents Python types used in hints. Its Display implementation converts it to the exact syntax for it to appear in a type hint.
2022-09-06 21:30:16 +02:00
David Hewitt
5718adeec7
pyproto: remove deprecated feature
2022-09-06 08:38:44 +01:00
Eric Jolibois
611ecc15fa
fix: export new dict views types ( #2590 )
...
* fix: export new dict views types
* fix exposed PyDictItems
Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
* add changelog entry
Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2022-08-25 09:03:57 +01:00
David Hewitt
f7ebda8ce3
docs: note with_gil auto-creates thread state
2022-08-23 20:49:14 +01:00
David Hewitt
af60a359c5
guide: don't use `::pyo3`
2022-08-23 20:49:14 +01:00
mejrs
ae50da1e3e
Mention a concrete pyo3 version
2022-08-22 21:14:07 +02:00
mejrs
db8b55a3fc
pyproto is no longer enabled by default
2022-08-21 17:51:11 +02:00
David Hewitt
d0492b7c72
Merge pull request #2570 from davidhewitt/pyclass-frozen-tidy
...
pyclass: tidy up frozen implementation
2022-08-21 09:35:51 +01:00
David Hewitt
24456f3f41
pyclass: tidy up frozen implementation
2022-08-21 08:21:06 +01:00
David Hewitt
fd8026c7bb
pyclass: add `sequence` option to implement `sq_length`
2022-08-20 07:14:26 +01:00
David Hewitt
5d44c5225c
rebase of #2553 - created a builder for creating types, allowing for more flexibility ( #2565 )
...
* Rewrote `create_type_object_impl` to use a builder, allowing for more flexibility.
* Fixed clippy warning about complex type
* Removed `with_` prefix from `PyTypeBuilder`
* Fixed misnamed function call
Co-authored-by: Aidan Grant <mraidangrant@gmail.com>
2022-08-19 11:33:04 +01:00
mejrs
fc6121eafe
Deprecate acquire_gil
2022-08-15 03:34:47 +02:00
David Hewitt
a3f093d7f0
safety: abort on uncaught panics
2022-08-14 13:47:46 +01:00
David Hewitt
de8fa18946
clippy: fixes flagged by beta toolchain
2022-08-14 07:44:11 +01:00
David Hewitt
c58ff7758c
pypy: disable PyFunction
2022-08-13 17:51:10 +01:00
Ashley Anderson
5d88e1d1c4
Update PyTryFrom for PyMapping and PySequence to more accurately check types ( #2477 )
...
Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2022-08-10 21:03:18 +01:00
David Hewitt
78ba70d2b4
pymodule: only allow initializing once per process
2022-08-09 19:52:25 +01:00
dswij
480fe7ef05
Expose `PyDict_GetItemWithError` on `PyDict` object ( #2536 )
...
* Expose `PyDict_GetItemWithError` on `PyDict` object
* Expose only on non-pypy
* use `unwrap_err` on `GetItemWithError` test
* Add changes info to changelog
* Ignore import for pypy ignored test
2022-08-07 00:19:02 +08:00
David Hewitt
2aa44b5c16
types: rework PyCapsule for soundness
2022-07-23 20:54:31 +01:00
mejrs
984fdf57c7
Use Python:;with_gil in tests
2022-07-19 19:34:23 +02:00
David Hewitt
fa19f322d2
Merge pull request #2503 from davidhewitt/extract_argument_holder
...
pyfunction: use extract_argument with holder to avoid extractext
2022-07-17 07:14:53 +01:00
messense
a00e9d553d
Update Python to 3.11.0b4 in emscripten test ( #2507 )
...
* Update Python to 3.11.0b4 in emscripten test
* Print traceback when import exception failed
* Try `ALLOW_MEMORY_GROWTH=1`
2022-07-15 20:39:58 +01:00
David Hewitt
5ff494c855
Merge pull request #2283 from davidhewitt/0.15-deprecations
...
refactor: remove all 0.15 deprecations
2022-07-15 07:49:51 +01:00
David Hewitt
d5e99b635d
refactor: remove all 0.15 deprecations
2022-07-15 06:33:14 +01:00
David Hewitt
209c942277
pyfunction: use extract_argument with holder to avoid extractext
2022-07-14 08:42:22 +01:00
David Hewitt
2623ed5ac6
fix formatting in datetime tests
2022-07-14 08:35:24 +01:00
David Hewitt
7babd13830
datetime: support timezone bindings
2022-07-13 22:05:17 +01:00
Jérome Eertmans
308ffa25b0
Prevent `str` from converting to `Vec<&str>` and `Vec<String>` ( #2500 )
2022-07-13 21:44:44 +01:00
David Hewitt
c4a2c6c912
clippy: fix some warnings from beta toolchain
2022-07-12 23:02:47 +01:00
Ivan Krivosheev
1cd1dbfe8b
Add super object ( #2486 )
2022-07-03 19:21:15 +01:00
Bruno Kolenbrander
58d4ba833e
Rust 1.62 ( #2489 )
...
* Rust 1.62
* Make rust happy
* Just use a doctest instead
Co-authored-by: mejrs <>
2022-07-02 16:08:01 +01:00
Bruno Kolenbrander
8babae655e
Merge pull request #2468 from mejrs/frozen
...
Add frozen documentation
2022-06-30 14:45:45 +02:00
David Hewitt
d5ac565f33
security: fix use-after-free in PyCapsule implementation
2022-06-26 07:18:23 +01:00
David Hewitt
ab0bc95152
sanitizers: fix use-after-free in test
2022-06-26 07:16:23 +01:00
David Hewitt
4da9c3a55f
llvm-lines: use iterator to collect class items
2022-06-25 22:03:28 +01:00
David Hewitt
2bf2d49329
llvm-lines: use fn() pointers in extract_argument expansion
2022-06-25 22:03:28 +01:00
David Hewitt
2096e30bca
opt: fix generic code bloat in LazyStaticType::get_or_init
2022-06-25 22:03:28 +01:00
Andrew Burkett
3fd0c0e142
Fix PyObject_CallNoArgs python version cfg ( #2476 )
...
* Fix PyObject_CallNoArgs python version cfg
PyObject_CallNoArgs was added to python 3.9 but not to limited api until 3.10 per https://docs.python.org/3/c-api/call.html#c.PyObject_CallNoArgs
* Update change log
* Fix uses of PyObject_CallNoArgs
Co-authored-by: Andrew Burkett <andrew.burkett@crowdstrike.com>
2022-06-23 21:31:44 +01:00
Ashley Anderson
bde5102eb8
Increasing test coverage ( #2462 )
...
* cov: src/buffer.rs - add tests for debug and element from format
* cov: src/buffer.rs - add some fortran-specific calls in test_array_buffer
* fix issues in MSRV
* cov: src/types/function.rs - directly call PyCFunction::new and PyCFunction::new_with_keywords
* docs: clarify docs of PyCFunction::new and PyCFunction::new_with_keywords
* revert added rust-version for MSRV in Cargo.toml
* cov: src/types/slice.rs - simple tests for PySliceIndices::new
* fix for multi-platform
* Update src/types/function.rs
Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
* cov: src/buffer.rs - a better PyBuffer Debug test
Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2022-06-23 21:30:22 +01:00
David Hewitt
3d9b78062e
opt: remove some generic code bloat
2022-06-22 22:53:32 +01:00
mejrs
e4e7e6e51c
Add frozen documentation
2022-06-22 01:47:40 +02:00
Georg Brandl
53b83cccbf
add `CompareOp::matches` ( #2460 )
2022-06-21 15:36:20 +02:00
David Hewitt
2fd5364646
pycell: add more test coverage
2022-06-19 21:18:15 +01:00
David Hewitt
7725f17c46
pyclass: switch from immutable to frozen
2022-06-19 21:18:15 +01:00
mejrs
2d94cb4a2d
use memoffset instead
2022-06-12 18:28:21 +02:00
mejrs
2d3a5852ed
Avoid UB in *_offset methods
2022-06-12 15:11:39 +02:00
mejrs
56c218f70e
Fix annoying inference errors
2022-06-12 01:39:34 +02:00
Hood Chatham
da5b9814cc
Set up CI for wasm32-emscripten target ( #2436 )
...
* ci: test on emscripten target
This adds CI to build libpython3.11 for wasm32-emscripten and
running tests against it. We need to patch instant to work
around the emscripten_get_now:
https://github.com/sebcrozet/instant/pull/47
We also have to patch emscripten to work aroung the "undefined
symbol gxx_personality_v0" error:
https://github.com/emscripten-core/emscripten/issues/17128
I set up a nox file to download and install emscripten,
download and build cpython, set appropriate environment variables
then run cargo test. The workflow just installs python, rust,
node, and nox and runs the nox session.
I xfailed all the test failures. There are problems with datetime.
iter_dict_nosegv and test_filenotfounderror should probably be
fixable. The tests that involve threads or asyncio probably can't
be fixed.
* Some cleanup
* Remove instant patch
* Add explanations for xfails
2022-06-08 05:59:18 +01:00
David Hewitt
866ddaca8a
ffi: tidy descrobject.rs
2022-06-07 19:45:36 +01:00
David Hewitt
cdf86482d8
ffi: many fixes to pypy definitions
2022-06-04 12:47:40 +01:00
David Hewitt
a746411b24
Merge pull request #2422 from davidhewitt/frompyobject-fixes
...
frompyobject: improve error messages of derived impls
2022-06-02 13:30:03 +01:00
David Hewitt
f50406a034
Merge pull request #2413 from davidhewitt/simpler-interned
...
macros: simpler expansion for `intern!`
2022-06-02 12:54:11 +01:00
David Hewitt
0aa4f95a98
frompyobject: improve error messages of derived impls
2022-06-02 11:13:35 +01:00
David Hewitt
261c0c5f56
macros: simpler expansion for `intern!`
2022-06-02 09:57:58 +01:00
David Hewitt
6a9f5fd705
ffi: remove PyArena on 3.10 and up
2022-06-02 09:35:35 +01:00
David Hewitt
e4ec720d51
frompyobject: tidy up generated code
2022-06-02 08:54:20 +01:00
David Hewitt
cfb91057af
frompyobject: improve error message for tuple case
2022-06-02 08:54:20 +01:00
Alex Gaynor
f6a24972e9
Added new PyCode and PyFrame objects.
...
They currently do not expose any APIs, but are significantly easier to work with than raw pointers :-)
2022-05-31 16:57:10 -04:00
Bruno Kolenbrander
4f9d3d7306
Protect iterators against concurrent modification ( #2380 )
2022-05-31 20:13:04 +01:00
David Hewitt
eafbbc5417
Merge pull request #2399 from davidhewitt/avoid-duplicate-pymethods
...
pymethods: prevent methods sharing the same name
2022-05-24 22:22:31 +01:00
David Hewitt
a306365db8
pymethods: prevent methods sharing the same name
2022-05-24 21:15:30 +01:00
David Hewitt
126bf49b8b
Merge pull request #2377 from herquan/herquan_cr1
...
Add macro append_to_inittab (issue #2359 )
2022-05-24 08:02:47 +01:00
herquan
2ec477344d
Add macro append_to_inittab
...
Sometimes we need to debug in a real environment with our module installed. `append_to_inittab` will be a wrapper for PyImport_AppendInittab (https://docs.python.org/3/c-api/import.html#c.PyImport_AppendInittab ) and help us to do this
2022-05-24 07:42:15 +01:00
David Hewitt
a21bd6f967
Merge pull request #2385 from davidhewitt/classattr-results
...
Allow `#[classattr]` methods to be fallible
2022-05-21 19:09:07 +01:00
David Hewitt
82b26b7cfa
datetime: remove reference to leap seconds
2022-05-17 21:21:15 +01:00
David Hewitt
0de0e3f8d6
Allow `#[classattr]` methods to be fallible
2022-05-17 21:19:41 +01:00
David Hewitt
570107d103
docs: fix nightly build
2022-05-17 19:48:40 +01:00
David Hewitt
7a9e70e2c7
wrap_x: change macros back to `macro_rules!`
2022-05-14 20:42:07 +01:00
David Hewitt
1482b526de
types: add dict views ( #2358 )
2022-05-11 20:34:22 +01:00
messense
76c09ac3ed
Remove `#[doc(hidden)]` from trait impl items ( #2365 )
...
See https://github.com/rust-lang/rust/pull/96008
2022-05-10 19:26:53 +01:00
Bruno Kolenbrander
c57e5098b8
Fix IntoPyCallbackOutput paper cuts ( #2326 )
...
* Implement IntoPy for arrays of IntoPy
* Improve `IntoPyCallbackOutput` compile error
2022-05-09 18:15:43 +01:00
David Hewitt
bc8641c790
Merge pull request #2350 from mejrs/ignore-less
...
Expand on AsPyPointer docs and un-ignore doc examples
2022-05-06 06:51:54 +01:00
mejrs
f1e5d4c9a1
Un-ignore and expand on doc examples
2022-05-03 00:47:09 +02:00
mejrs
f34b92a368
Expand conversions documentation
2022-05-03 00:46:53 +02:00
Alex Gaynor
c6055c03f1
fixed comment in string.rs
2022-05-02 11:12:19 -06:00
Bruno Kolenbrander
dce4377eb4
Allow more methods to take interned arguments ( #2312 )
...
* Allow more methods to take interned arguments
* Changelog
* Unify name bounds
* Resolve merge conflict
* reduce use of py_decref
* Add some attr tests
* Update migration
2022-05-02 11:13:15 +02:00
David Hewitt
1596ab8a4b
Merge pull request #2333 from davidhewitt/remove-toborrowedobject
...
remove `ToBorrowedObject` trait
2022-04-26 06:23:35 +01:00
David Hewitt
71f9f18d54
remove toborrowedobject trait
2022-04-26 05:48:34 +01:00
David Hewitt
4168feed1b
opt: tidy some generic code bloat
2022-04-26 05:36:57 +01:00
cuishuang
19e32a0621
fix some typos
...
Signed-off-by: cuishuang <imcusg@gmail.com>
2022-04-24 22:06:32 +08:00
David Hewitt
e05cec01e4
cleanup: unused cls.rs
2022-04-24 09:20:20 +01:00
David Hewitt
7e2d3117ce
cleanup: deprecate PyTypeObject trait
2022-04-23 13:36:32 +01:00
David Hewitt
ca8958c347
Merge pull request #1979 from mejrs/immutable
...
Opt out of PyCell borrow tracking
2022-04-23 13:34:02 +01:00
David Hewitt
b196aa1d5a
remove some redundant traits
2022-04-23 06:27:55 +01:00
David Hewitt
e9bd41efb2
better mutability inheritance rules
2022-04-21 20:51:28 +01:00
David Hewitt
7118e94947
Merge branch 'main' into immutable
2022-04-19 19:00:33 +01:00
pigeon
dea9eb7af6
Implement ToPyObject for [T; N] ( #2313 )
2022-04-19 15:09:54 +02:00
Adam Reichold
0d0089ea29
Remove redundant use statements and add missing calls to add_function in datetime test.
2022-04-13 09:40:16 +02:00
Ivan Tham
a1f97f164d
Add PyTzInfoAccess
2022-04-13 00:00:08 +08:00
Bruno Kolenbrander
bc6bd6099c
Merge branch 'main' into immutable
2022-04-12 14:22:33 +02:00
mejrs
b7745dffc8
Fix everything
2022-04-12 14:19:02 +02:00
Adam Reichold
551db72b55
Merge pull request #2279 from PyO3/extract-error-is-slow
...
Add benchmark highlighting the costs of failed calls to FromPyObject::extract.
2022-04-10 17:10:50 +02:00
Adam Reichold
10c285b283
Add PyDowncastErrorArguments to delay formatting downcast errors.
2022-04-10 13:13:03 +02:00
David Hewitt
1d9d60a766
ffi: fix segfault in _GET_TZINFO methods
2022-04-10 10:27:50 +01:00
David Hewitt
1971dd7a8a
Merge pull request #2286 from RicoHageman/main
...
Gather test coverage with stable rust
2022-04-08 19:28:13 +01:00
Rico Hageman
c281275a29
Gather test coverage with stable rust
2022-04-08 14:24:10 +02:00
Adam Reichold
6a4ebbf2d7
Replace unhinted spin loops by sleeping events.
2022-04-08 11:16:40 +02:00
David Hewitt
9774a7c1c1
Merge pull request #2273 from PyO3/dog-food-intern
...
Make use of intern! macro for attribute names used internally
2022-04-05 00:41:35 +01:00
David Hewitt
d3ac71a42b
Merge pull request #2269 from PyO3/intern-macro
...
RFC: Add intern! macro which can be used to amortize the cost of creating Python objects by storing them inside a GILOnceCell.
2022-04-05 00:34:37 +01:00
Adam Reichold
f02a060a3d
Add a hint on using intern! to Py{,Any}::{set,get}attr.
2022-04-04 23:11:38 +02:00
Adam Reichold
5434bbc3f6
Intern the __all__ and __name__ identifiers used by PyModule.
2022-04-04 22:26:14 +02:00
Adam Reichold
821b28daff
Intern the __qualname__ identifier used by PyType::name.
2022-04-04 22:05:03 +02:00
Adam Reichold
89577a27d9
Isolate interned strings from their dynamic environment to avoid calling multiple times them with different text values yielding inconsistent results.
2022-04-04 22:04:46 +02:00
David Hewitt
981eb2d90e
Merge pull request #2265 from davidhewitt/pyclass-mapping
...
pyclass: mapping flag
2022-04-04 19:54:37 +01:00
Adam Reichold
7b99af9b34
Execute the example for intern macro to ensure it is correct.
2022-04-04 20:25:47 +02:00
Adam Reichold
30d414fd49
Add intern macro to hygiene tests and ensure it can handle stringified identifiers.
2022-04-04 18:53:31 +02:00
Adam Reichold
f777372eed
Limit the intern! macro to strings and intern the string contents in addition to the reference.
2022-04-04 10:11:52 +02:00
Adam Reichold
125bf416a2
Separate the fast and slow path of GILOnceCell::get_or_init.
2022-04-03 21:18:09 +02:00
Adam Reichold
db109867d3
Add intern! macro which can be used to amortize the cost of creating Python objects by storing them inside a GILOnceCell.
2022-04-03 21:16:42 +02:00
Adam Reichold
d3dcbd72ba
Add PyString::intern to enable access to Python's built-in string interning. ( #2268 )
2022-04-03 21:07:58 +02:00
David Hewitt
c16cc35b30
pyclass: mapping flag
2022-04-02 16:15:44 +01:00
mejrs
086424b88c
Merge branch 'main' of https://github.com/mejrs/pyo3 into immutable
2022-04-01 23:11:02 +02:00
mejrs
9ab1e6927a
Merge branch 'immutable' of https://github.com/mejrs/pyo3 into immutable
2022-04-01 22:59:59 +02:00
Bruno Kolenbrander
78efebd993
Expand some documentation ( #2256 )
...
* use `is` where appropriate
* Rework safety docs
2022-03-30 12:56:14 +02:00
mejrs
00ea040834
Feedback
2022-03-23 13:30:32 +01:00
mejrs
6f1cf1b662
Add more lints
2022-03-23 08:07:28 +01:00
Alex Gaynor
69655454c1
Added an as_bytes method for Py<PyBytes>
...
This allows for obtaining a slice that's not lexically bound to the GIL which can be helpful to avoid copying.
2022-03-19 13:28:06 -04:00
David Hewitt
88cd9152b2
pypy: support 7.3.8
2022-03-08 21:09:16 +00:00
David Hewitt
2bd64c4962
guide: tidy up doctests
2022-03-04 22:50:12 +00:00
Bruno Kolenbrander
39534ba96d
Make gil tests not racy ( #2190 )
...
* Make tests not racy
* be a bit more resilient to other tests
2022-03-03 12:33:21 +01:00
David Hewitt
ddf13ea98f
clippy: enable some more lints
2022-03-03 07:23:28 +00:00
David Hewitt
b59ee9b54b
misc: tidy ups pre 0.16
2022-02-27 10:02:28 +00:00
Georg Brandl
dc4f114d67
Address review comments
2022-02-26 20:10:33 +01:00
Georg Brandl
0678f11266
Protocols: implement __getattribute__
...
converting tp_getattro to a shared slot
Fixes #2186
2022-02-26 20:05:50 +01:00
Georg Brandl
03dc96bff1
Py/PyAny: remove PartialEq impl and add is() ( #2183 )
2022-02-25 19:39:45 +00:00
Tommaso Thea Cioni
487345979b
Added `eq`, `ne`, `gt` etc. methods. ( #2175 )
2022-02-25 18:52:20 +01:00
mejrs
39bd9991e8
Add some underscores
2022-02-25 07:28:22 +00:00
mejrs
071c31f140
Undo rename
2022-02-25 07:28:22 +00:00
David Hewitt
f98f116131
pypy: support released 3.9
2022-02-25 07:28:22 +00:00
David Hewitt
7c865fcc25
Merge pull request #2173 from davidhewitt/deprecate-pyproto
...
pyproto: deprecate protocol traits
2022-02-24 23:54:40 +00:00
David Hewitt
3d7080b0b5
Merge pull request #2184 from davidhewitt/rust-1.59
...
rust: clippy fixes 1.59
2022-02-24 21:21:04 +00:00
David Hewitt
642fe5bb56
rust: clippy fixes 1.59
2022-02-24 20:17:05 +00:00
mejrs
be84e0fbb9
Add numeric and object protocol examples
2022-02-23 10:09:45 +01:00
David Hewitt
253507b5dd
migration: add note on pymethods -> pyproto
2022-02-23 07:50:55 +00:00
David Hewitt
24445df633
pyproto: deprecate protocol traits
2022-02-23 07:50:52 +00:00
David Hewitt
d8ee35e19c
Merge pull request #2165 from mejrs/auto_trait
...
Implement Auto trait
2022-02-23 07:16:17 +00:00
mejrs
ec275d49cb
Explicitly (un)implement Ungil
2022-02-22 22:43:40 +01:00
mejrs
90281f88d3
Make conversion from String private
2022-02-22 22:43:40 +01:00
mejrs
97205bd11a
Update docs
2022-02-22 22:43:40 +01:00
mejrs
9e29c1058c
Gut specialization and implement auto trait
...
Implement auto trait
Implement auto trait
Undo oopsie
Fix versions
Fix CI errors
Fix CI
Remove more specialization remnants
2022-02-22 22:43:23 +01:00
Rico Hageman
3fbdc863cb
Include the causes when throwing a PyTypeError when argument parsing failed
2022-02-22 09:48:41 +01:00
Rico Hageman
597e3e17a9
Pass detailed error message to python when parsing an argument fails
2022-02-21 23:22:40 +01:00
Bruno Kolenbrander
01788b7220
Merge pull request #2172 from mejrs/addr
...
Use addr_of_mut in pyo3-ffi
2022-02-19 17:56:09 +01:00
David Hewitt
79123b396c
pyclass: deprecate gc option
2022-02-15 08:01:46 +00:00
David Hewitt
676295b8de
pymethods: support gc protocol
2022-02-15 08:01:23 +00:00
David Hewitt
7851e865ae
Merge pull request #2166 from mejrs/union
...
Implement ml_meth as an union.
2022-02-15 07:55:24 +00:00
mejrs
e5000e470a
Use addr_of_mut instead
2022-02-14 23:18:22 +01:00
mejrs
718b0fd02f
Remove options and rename struct
2022-02-14 15:14:49 +01:00
mejrs
dadbc22b2e
Implement nl_meth as an union.
2022-02-14 00:03:33 +01:00
Jacob Zhong
9a775c4380
Update src/conversions/num_bigint.rs
...
Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2022-02-12 13:27:40 -05:00
Jacob Zhong
d99a001b7d
Fix the signature of _PyLong_NumBits
2022-02-12 13:27:40 -05:00
David Hewitt
c5ef24bbea
fix: memory leak in Option<T>::as_ptr
2022-02-11 22:18:11 +00:00
David Hewitt
c93ee00130
refactor: inline handle_panic into macro output
2022-02-10 20:20:03 +00:00
David Hewitt
f5b2a88a70
refactor: include __new__ as slot
2022-02-09 08:07:14 +00:00
David Hewitt
75e44585de
refactor: pass tp_alloc and tp_free via slots
2022-02-09 08:07:14 +00:00
David Hewitt
4d471077b4
refactor: inline pyclass_default_items trait
2022-02-08 19:39:37 +00:00
David Hewitt
6f39deaa37
finish off implementation
2022-02-08 18:17:44 +00:00
mejrs
7520b49ac1
Implement opt-in immutable pyclasses
2022-02-08 18:08:18 +00:00
mejrs
3c1a0c6b7e
Rename python.rs to marker.rs
2022-02-08 14:59:36 +01:00
b05902132
78f5afc82e
Finish implementation for pyclass enums
2022-02-07 22:17:11 +00:00
David Hewitt
9def53317f
Merge pull request #2153 from davidhewitt/simplify-intrinsic-items
...
refactor: inline pyclass_intrinsic_items
2022-02-07 00:05:30 +00:00
David Hewitt
e39881c208
refactor: inline pyclass_intrinsic_items
2022-02-06 23:26:57 +00:00
David Hewitt
f75579a489
python-3.11: support buffer API on abi3
2022-02-06 22:46:45 +00:00
James Hilton-Balfe
b2f9e28331
Add Mapping::contains ( #2133 )
...
* Add Mapping::contains
* Fix typo
* Add a changelog entry
* Use PyAny::contatins instead
* Update mapping.rs
2022-02-06 00:35:43 +00:00
David Hewitt
ecfd2c2434
pyclass: simplify generated code for PyClassImpl
2022-02-05 16:58:01 +00:00
David Hewitt
558549e1c2
pyproto: split into new feature
2022-02-05 16:51:31 +00:00
David Hewitt
53c170078d
pymethods: seq methods from mapping methods
2022-02-05 15:59:22 +00:00