Commit Graph

600 Commits

Author SHA1 Message Date
David Hewitt 49c1d22606 docs: for #2234 2022-03-22 10:38:36 +00:00
Mo Mirza 143b7d368f
Replace nbsp with space (#2237)
This fixes markdown heading rendering
2022-03-20 16:45:33 +01:00
Georg Brandl f084ceb9b1 guide: fix duplicated example for #[new]
The second one was probably intended to show a fallible `#[new]`.

Also show that the method does not need to be named `new()`, which
is nice because `new()` can be used for a Rust-level constructor
if they differ.
2022-03-06 10:57:49 +01:00
David Hewitt 0f1b8dd43f
Merge pull request #2207 from davidhewitt/tidy-doctests
guide: tidy up doctests
2022-03-05 16:18:43 +00:00
Alex Gaynor 01d8f1e696
added missing proc-macro invocation to migration guide (#2209) 2022-03-05 15:46:36 +00:00
David Hewitt 2bd64c4962 guide: tidy up doctests 2022-03-04 22:50:12 +00:00
Jerzy Spendel eaa82b2856 Remove typying 2022-03-04 16:24:49 +01:00
Georg Brandl 6bc8943df5 changelog/guide: visibility is also important for wrap_pyfunction! now
Fixes #2202
2022-03-04 07:48:41 +01:00
David Hewitt b59ee9b54b misc: tidy ups pre 0.16 2022-02-27 10:02:28 +00: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
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 424644181b pymethods: add support for inplace concat & repeat 2022-02-24 23:07:24 +00:00
Rico Hageman ed698c4b43 Add documentation related to from_py_with for the FromPyObject trait 2022-02-24 22:54:30 +01:00
Bruno Kolenbrander af0cef0e59
Merge branch 'main' into object 2022-02-23 10:13:29 +01: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
Georg Brandl a21cf677e3 docs: remove/deprecate pyproto 2022-02-23 07:50:55 +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 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
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 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
mejrs 7520b49ac1 Implement opt-in immutable pyclasses 2022-02-08 18:08:18 +00:00
b05902132 78f5afc82e Finish implementation for pyclass enums 2022-02-07 22:17:11 +00:00
David Hewitt 4fd01c3cd6
fix: guide example for pyclass expansion 2022-02-07 07:46:12 +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
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
mejrs 463543ad58 Annotate Rust blocks with "rust" 2022-01-29 01:03:57 +01:00
Jakub Kołodziejczak d1542a8a79
docs(guide): example of loading python file from path at runtime in a way that it sees its dependencies (#2109)
* docs(guide): example of loading python file from path at runtime in a way that it sees its dependencies

* docs: editorial fixes

suggested by @mejrs

Co-authored-by: Bruno Kolenbrander <59372212+mejrs@users.noreply.github.com>

Co-authored-by: Bruno Kolenbrander <59372212+mejrs@users.noreply.github.com>
2022-01-24 11:03:47 +01:00
Jakub Kołodziejczak 020488efee
docs: example how to include multiple Python files into the binary and at runtime (#2095) 2022-01-17 10:57:39 +01:00
messense ce80b7e0f3 Switch from tox to nox 2022-01-17 00:24:33 +08:00
David Hewitt 2cee7feaaf
Merge pull request #2083 from aviramha/magic_methods
verify py method args count
2022-01-07 00:13:05 +00:00
Aviram Hassan 50659b6b02
`__ipow__` now supports modulo argument on Python 3.8+.
`pyo3-macros-backend` is now compiled with PyO3 cfgs to enable different magic method definitions based on version.
Add check for correct number of arguments on magic methods.
2022-01-03 09:53:56 +02:00
David Hewitt cf965155f4 pymethods: support buffer protocol 2021-12-30 15:48:55 +00:00
David Hewitt e33b3e6a5b opt: don't emit T::dict_offset and T::weakref_offset without attributes 2021-12-30 14:57:27 +00:00
Bruno Kolenbrander 4d1d859a64
Merge branch 'main' into aliases 2021-12-24 22:28:22 +01:00
James Hilton-Balfe a5511b8f8a
Fix markdown link (#2071) 2021-12-22 16:51:03 +00:00
mejrs 9512ce4e87 Fix call example 2021-12-22 12:12:16 +01:00
Bruno Kolenbrander 39cac9075b
Organize examples + add __call__ example (#2043)
* Add decorator example crate and split off chapter

* Move not-examples to their own folder

* Add some readme's

* Make black happy

* Make clippy happy

* Add decorator example crate and split off chapter

* Fix ci

* Add empty workspace key

* Try fix ci

* fix ci

* reuse target dir for examples CI

* add pytests folder to makefile recipes

* fix ci, try 2

* add missing pyproject.toml

* remove TOX_TESTENV_PASSENV from Makefile

Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2021-12-15 00:45:26 +00:00
Georg Brandl a5b76bc365 pyo3_path, part 4: rename to `crate` to keep consistent with serde 2021-12-09 07:36:48 +01:00
Georg Brandl e4f608f605 pyo3_path, part 2: add pyo3_path options and use them. 2021-12-09 07:24:18 +01:00
David Hewitt 2ac30ec411 err: tweak names, inlining and docs 2021-11-27 08:26:04 +00:00
David Hewitt e9b46f76da
Merge pull request #1985 from PyO3/is_instance_of
add PyType::is_subclass_of and PyAny::is_instance_of
2021-11-20 14:56:36 +00:00
David Hewitt ded44eebfb
Merge pull request #2006 from davidhewitt/drop-py36
python: drop support for 3.6
2021-11-20 14:04:31 +00:00
Georg Brandl 43893158b1 switch is_instance/is_instance_of, is_subclass/is_subclass_of 2021-11-20 13:18:43 +00:00
David Hewitt cc91a7c574
Merge pull request #2007 from davidhewitt/remove-0.14-deprecations
deprecations: remove items deprecated in PyO3 0.14
2021-11-20 13:09:04 +00:00
David Hewitt 70030f130d python: drop support for 3.6 2021-11-20 13:02:42 +00:00
David Hewitt c9a4cd1f87 deprecations: remove items deprecated in PyO3 0.14 2021-11-19 16:33:29 +00:00
David Hewitt b9cc10f3fb pyo3-build-config: don't enable resolve-config by default 2021-11-19 14:19:24 +00:00
Dan Svoboda d9a3f67287
Fix broken relative markdown link in guide
This link needs to point up one dir to the location of class.md
2021-11-15 14:04:53 -05:00
Gertjan van Zwieten 0e40277112 add missing annotation to PyCounter.__call__
This patch annotates the `__call__` method of `PyCounter` in example: callable
objects with `#[args(args="*", kwargs="**")]`. Without it (at least in PyO3
0.15.0) the example fails with `TypeError: counter.__call__() missing 1
required positional argument: 'args'`.
2021-11-15 09:01:05 +01:00
David Hewitt a978b0875a
Merge pull request #1968 from KRunchPL/guide-python-typing-hints
#1959 - Add Python Typing Hints to the Guide
2021-11-11 23:00:53 +00:00
David Hewitt 20091826a5
Merge pull request #1976 from davidhewitt/pyo3-build-config-docs
docs: pyo3 config files
2021-11-11 08:53:36 +00:00
David Hewitt 2784b31bea
Merge pull request #1971 from davidhewitt/disable-unwanted-protos
pymethods: test and document opt-out of protos
2021-11-11 08:52:58 +00:00
David Hewitt 23778f5386 pymethods: test and document opt-out of protos 2021-11-10 23:28:01 +00:00
David Hewitt b0af3ec25f docs: pyo3 config files 2021-11-10 08:34:54 +00:00
David Hewitt 3d1bcae3aa guide: document `#[pyo3(from_py_with)]` 2021-11-07 12:57:40 +00:00
KRunchPL a0716ce519 Description of simple solution implemented in Maturin guide 2021-11-06 17:29:02 +01:00
KRunchPL 1531ac8d7e #1959 - Add Python Typing Hints to the Guide 2021-11-06 15:34:30 +01:00
Georg Brandl 9ce363a125 guide: add hints for the signature of pymethods protos 2021-11-03 08:00:09 +01:00
David Hewitt 3ab32ff01f guide: magic methods in pymethods 2021-10-24 15:59:22 +01:00
David Hewitt dc0e29af1c
Merge pull request #1929 from davidhewitt/call-proto
pymethods: support __call__ proto
2021-10-23 22:55:30 +01:00
David Hewitt 4b2345fe80 pymethods: support __call__ proto 2021-10-23 00:06:46 +01:00
Nikita Sobolev 5ae9178781 Fixes typo in docs 2021-10-23 00:03:41 +01:00
Ashley Anderson bf26daec2d
Positional-only args (#1925)
* Add support for positional-only args

* Update changelog. Add a few more tests. Run rust-fmt.

* Fix test.

* Fix tests again.

* Update CHANGELOG.md to link PR instead of issue

* Update guide to mention positional-only params

* Add unreachable!() per code review

* Update and expand tests for pos args.

* Fix tests, lint, add UI tests.

Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2021-10-19 23:13:27 +01:00
Chris Laplante 3b94f4b70c
Add `anyhow-integration` feature which implements From<anyhow::Error> for PyErr (#1822)
* Add 'anyhow' feature which provides simple From<anyhow::Error> for PyErr impl

This makes it possible to use anyhow::Result<T> as the return type for
methods and functions exposed to Python.

The current implementation just stringifies the anyhow::Error before
shoving it into a PyRuntimeError. Conversion back to the anyhow::Error
is not possible, but it is better than nothing.

Signed-off-by: Chris Laplante <chris.laplante@agilent.com>

* Document `anyhow` feature in the guide

Signed-off-by: Chris Laplante <chris.laplante@agilent.com>

* update changelog to document anyhow feature

* WIP adding tests

* Finish up anyhow feature

* Fix formatting

* Fix tests

* Fix tests

* Apply review suggestions

Co-authored-by: Bruno Kolenbrander <59372212+mejrs@users.noreply.github.com>
Co-authored-by: mejrs <brunokolenbrander@hotmail.com>
2021-10-17 07:54:29 +01:00
Bruno Kolenbrander 8a57fe2d20
Clean up doctests, deny some lints (#1900)
* Clean up doctests, deny some lints

* Apply suggestions from review.

* replace \" with '

* Fix some more doc examples

* Fix formatting

* Fix some more things

* Remove unused parentheses

* Only test class sig on supported abi/platforms

* Only test class signature on correct versions

* Fix tests to compile on msrv

* msrv strikes yet again

* Add feedback

* Pin `half` to 1.7.1 on msrv
2021-10-14 22:15:25 +01:00
Bruno Kolenbrander ae873698d4
Implement `eyre` feature (#1893)
* Implement `eyre` feature

* Punctuation

* Add `eyre` entry in changelog

* Add `eyre` feature entry to guide

* Set eyre upper bound and move comment back

* Add eyre feature to docs.rs metadata

* Finish up review suggestions

* Update CHANGELOG.md

Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2021-10-13 22:36:06 +00:00
David Hewitt c986b5d4ae
Merge pull request #1889 from davidhewitt/py310
packaging: formal support for Python 3.10
2021-09-29 19:36:52 +01:00
David Hewitt a5d0aa777c py310: add abi3-py310 feature 2021-09-26 16:21:35 +01:00
David Hewitt 16ac7d481d
Merge pull request #1844 from davidhewitt/mapping-type
types: add PyMapping
2021-09-26 14:55:59 +01:00
David Hewitt d929916071 types: add PyMapping 2021-09-26 13:57:33 +01:00
David Hewitt 9e80f3dfdd pep 604: use `T | U` instead of `Union[T, U]` in messaging 2021-09-24 22:46:25 +01:00
David Hewitt a551b005b4 pymethods: finish support for number protocol 2021-09-18 12:59:25 +01:00
Gregory Szorc 1e951d5d8b pyo3-build-config: add a crate feature to control build script
I have a use case in PyOxidizer where I want to use the
pyo3-build-config crate as a library crate so I can access the
`InterpreterConfig` struct so I can read/write config files without
reinventing the wheel.

This is doable before this commit. But it requires that the
build environment have a Python interpreter. This is undesirable
for library usage.

This commit introduces a cargo feature flag to control whether the
build script does anything. The feature flag must be present for
the build script to resolve a config. The feature flag is enabled
by default for backwards compatibility. The pyo3 and pyo3-macros-backend
crates use this feature by default, for backwards compatibility and
because it is the reasonable default.

This is probably room to conditionalize some APIs and other behavior
based on this feature flag. But we stop short of doing that for
the time being.
2021-09-01 19:44:54 -07:00
David Hewitt 4a50a26c87 changelog: remove function parentheses 2021-08-26 18:59:07 +01:00
David Hewitt a2375f336f
Merge pull request #1832 from mejrs/decorator
guide: add decorator example
2021-08-26 18:55:59 +01:00
mejrs 76179967f3 use &mut self receiver and py args. 2021-08-26 15:28:52 +02:00
David Hewitt f20079bf78
Merge pull request #1829 from davidhewitt/slice-index
list,tuple,sequence: add slice indexing
2021-08-26 08:30:30 +01:00
David Hewitt 3a90ff77f4 list,tuple,sequence: add slice indexing 2021-08-26 07:57:12 +01:00
David Hewitt f2ff6cad37 guide: add "Optional Dependencies" section
Co-authored-by: mejrs <59372212+mejrs@users.noreply.github.com>
2021-08-26 07:22:54 +01:00
mejrs eaf5e6de9c add decorator example 2021-08-26 04:18:49 +02:00
Georg Brandl 54e7da515a migration: add guide entry for sequence indexing 2021-08-24 08:32:19 +02:00
Benjamin Kay ac4613eb9f
Improve documentation about when we free memory, resolves #311 (#1807)
* Improve API docs regarding when we free memory, resolves #311

* Add chapter to guide about when we free memory, resolves #311

* Fix typos in documentation

Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>

* Add links from guide to docs.rs

* Update guide/src/memory.md

Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2021-08-21 09:23:10 +01:00
David Hewitt 37d39aa83a
Merge pull request #1751 from davidhewitt/pyany-py
pyany: add PyAny::py()
2021-08-17 14:10:16 +01:00
Gregory Szorc 410c9f13c9 macros: raise AttributeError on property deletion requests
The setter function will receive a NULL value on deletion requests.
This wasn't properly handled before, leading to a panic.

The new code raises AttributeError in this scenario instead.

A test for the behavior has been added. Documentation has also
been updated to reflect the behavior.
2021-08-13 21:01:00 -07:00
David Hewitt ebada76ae3 pyany: add PyAny::py() 2021-08-13 08:00:13 +01:00
Sanskar Jethi aac3d1da6e Add documentation to call async python from rust 2021-08-12 00:22:10 +01:00
David Hewitt 290ded4d4e guide: don't bother doctesting async guide 2021-08-10 07:56:36 +01:00
Andrew J Westlake f4975c6e1d Fixed broken link in async-await.md 2021-08-09 09:07:57 -05:00
Andrew J Westlake bf23f8bda7 Shortened the async/await guide 2021-08-08 14:58:46 -05:00
Andrew J Westlake 9037697bed
Update guide/src/ecosystem/async-await.md
Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2021-08-08 10:15:01 -05:00
Andrew J Westlake d578f37f70
Removed "auto-initialize" feature from uvloop example
Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2021-08-08 10:13:47 -05:00
Andrew J Westlake 92c3af5088
Forgot to bump another pyo3 version
Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2021-08-08 09:59:17 -05:00