Commit Graph

597 Commits

Author SHA1 Message Date
David Hewitt aa0b5d8488 buffer: tidy up exceptions 2021-04-12 01:21:48 +01:00
David Hewitt ac0bd0c0f1 clippy: tidy up allow lints 2021-04-12 01:20:04 +01:00
David Hewitt ce851ad7d9 1506: fixes to macro hygiene 2021-03-28 11:01:51 +01:00
messense 90c5ffbd04 Fix clippy warnings in Rust 1.51.0 2021-03-26 13:21:38 +08:00
David Hewitt 246335bee2
Merge pull request #1505 from scalexm/macro
Ignore `syn::Type::Group` in `is_python`
2021-03-20 11:09:04 +00:00
David Hewitt e34e87ad4a 1505: add CHANGELOG and test 2021-03-20 08:36:19 +00:00
Yuji Kanagawa f0763f069e
Merge pull request #1507 from scalexm/getter-name
Allow `#[name]` with `#[getter]` and `#[setter]`
2021-03-20 16:23:07 +09:00
Yuji Kanagawa acff3b1f3e
Merge pull request #1504 from PyO3/pyclass
Add tuple and unit struct support for pyclass macro
2021-03-20 16:14:15 +09:00
messense acd4601d2f Remove __doc__ from module's __all__ 2021-03-20 11:25:36 +08:00
messense 1c57294214 Use Python::with_gil and py_assert
Co-authored-by: Yuji Kanagawa <yuji.kngw.80s.revive@gmail.com>
2021-03-19 10:17:06 +08:00
messense 2cec240b0e Ban pyo3(get, set) on tuple struct field 2021-03-19 10:17:06 +08:00
messense 773a371ba5 Add tuple and unit struct support for pyclass macro 2021-03-19 10:17:06 +08:00
scalexm b27ee3fd64 Allow `#[name]` with `#[getter]` and `#[setter]` 2021-03-18 19:35:17 +01:00
Yuji Kanagawa acf7271879
Merge pull request #1494 from PyO3/enhance-py-run
Extend py_run! to take locals dict and refactor tests using it
2021-03-17 12:52:33 +09:00
kngwyu 9b88a452e2 Refactor tests to use shorter macros 2021-03-14 23:43:53 +09:00
David Hewitt b10cefdca2 pymodule: remove call_function etc. 2021-03-14 11:19:55 +00:00
kngwyu 7ec1fed798 Extend py_run! macro to take dict as *d syntax 2021-03-14 16:33:49 +09:00
David Hewitt 66b3022d0e
Merge pull request #1483 from davidhewitt/macros-tidy-ups
pymethods: macros tidy-ups
2021-03-14 00:09:23 +00:00
David Hewitt 9613228a0c pyfunction: reject generic functions 2021-03-09 23:47:47 +00:00
David Hewitt 78080ebbd2 macros-backend: support noargs for pyproto py_methods 2021-03-08 23:56:08 +00:00
David Hewitt d75d109aee
Merge pull request #1472 from davidhewitt/nightly-warnings
ci: fix nightly warnings
2021-03-06 23:10:48 +00:00
David Hewitt e19c083a81 ci: fix nightly warnings 2021-03-06 09:42:50 +00:00
David Hewitt 977735db20 pymethods: make inventory optional 2021-03-04 19:52:58 +00:00
Yuji Kanagawa 21b26fcf3a
Merge pull request #1440 from davidhewitt/fix-multiple-kw-only-arg
pyfunction: refactor argument extraction
2021-03-04 00:15:34 +09:00
David Hewitt 29a525b327 pyfunction: refactor argument extraction 2021-03-01 17:49:46 +00:00
David Hewitt ffd5874c3a pyfunction: fix args conflicting with keyword only arg 2021-03-01 17:49:46 +00:00
konstin f97c3a9479 Convert callback_body_without_convert function to handle_panic function 2021-03-01 12:42:19 +01:00
Daniil Konovalenko 554cffd60d
add #[pyo3(from_py_with="...")] attribute (#1411)
* allow from_py_with inside #[derive(FromPyObject)]
* split up FnSpec::parse
2021-02-21 00:15:20 +09:00
David Hewitt 7b99e391fa pyclass-impl: merge implementation traits 2021-02-18 08:19:07 +00:00
David Hewitt b2675b11fe rust 1.50: clippy and lint fixes 2021-02-11 22:03:34 +00:00
Georg Brandl fa8d7518ca Restore compatibility with Rust 1.41.
This version is currently supported by Debian stable and Alpine Linux.

Fixes #1420
2021-02-11 10:14:25 +01:00
David Hewitt 9807ef8ed4 macros-backend: fix raw idents in pymethods 2021-01-12 22:01:11 +00:00
David Hewitt 0729fb1e03
Merge pull request #1374 from davidhewitt/macros-error-handling
macros-backend: improve error handling ergonomics
2021-01-12 08:05:30 +00:00
Daniil Konovalenko abb5829e9c implement Serialize, Deserialize for Py<T> 2021-01-11 22:19:10 +00:00
David Hewitt 88872eba4f macros-backend: improve error handling ergonomics 2021-01-10 10:25:43 +00:00
David Hewitt b92441cd7c pyclass: fix reference count issue in subclass new 2021-01-08 00:13:49 +00:00
David Hewitt 22de3b4f44 pyclass: add !Send compile_error test 2021-01-05 23:25:28 +00:00
David Hewitt b1012ebb68 build: update for Rust 1.49 2020-12-31 18:16:02 +00:00
David Hewitt 7572962828 abi3: add support for dict and weakref from Python 3.9 2020-12-28 10:22:46 +00:00
David Hewitt db74cc85fa pypy: final fix 2020-12-20 13:50:39 +00:00
kngwyu dc2dbd6c19 Use #[cfg(not(Py_LIMITED_API))] for datetime API 2020-12-20 12:20:35 +00:00
David Hewitt fa8c93cfd1 pyclass #[new]: allow using custom error type 2020-12-13 23:50:03 +00:00
David Hewitt 5133f81e6d deprecate pyclass name without quotes 2020-12-12 11:11:11 +00:00
scalexm 7dadf59fde Do not include the double quotes in `#[pyclass(name = "literal")]` 2020-11-30 22:04:07 +01:00
scalexm 649b439463 Allow `#[pyclass(name = "string literal")]`
This is also more in line with the `#[name = "..."]` attribute on
methods.
2020-11-27 18:45:07 +01:00
roblabla d479b54b94 Fix #1285, text_signature and raw ident interaction 2020-11-19 17:21:02 +00:00
David Hewitt 8a8c098a2e rust-1.48: fix tests and warnings 2020-11-19 12:49:29 +00:00
David Hewitt 45599620b5 pyerr: improve debug & display impls 2020-11-15 16:22:45 +00:00
David Hewitt 9617edfca9 msrv: bump to 1.45 2020-11-12 11:33:08 +00:00
Alex Gaynor 90a825d0c2 Merge branch 'master' into abi3-merge-master 2020-10-19 14:32:49 -04:00
David Hewitt afd9b823d2 Drop support for Python 3.5 2020-10-18 19:02:27 +01:00
Alex Gaynor ba6f0ecdfa Merge branch 'master' into abi3-merge-master 2020-10-18 10:47:06 -04:00
Askaholic 6724783395
Change wording of PyDowncastError display implementation
Displays type(obj) instead of repr(obj) and uses `cannot` instead of
`can't`
to be more consistent with existing python error messages.

See discussion at #1212.
2020-10-14 17:32:00 -08:00
Askaholic 19889bc6b9
Add argument name to TypeError messages caused during argument conversion 2020-10-14 17:32:00 -08:00
Askaholic 007bfb7ab0
Refactor py_expect_exception to also verify error string representation 2020-10-13 14:02:14 -08:00
Alex Gaynor 9e34835b76 Merge branch 'master' into abi3-merge-master 2020-10-12 18:03:14 -04:00
David Hewitt 7b3dd68bfb Fix support for MSRV
Co-authored-by: Alex Gaynor <alex.gaynor@gmail.com>
2020-10-12 15:46:40 +01:00
Alex Gaynor aabad7cf7f Assorted updates to the abi3 branch from review 2020-10-11 19:51:27 -04:00
Alex Gaynor 140790b15f Merge branch 'master' into abi3-merge-master 2020-10-10 10:11:49 -04:00
kngwyu e7092fe630 Make PyCFunction more backward-compatible 2020-10-09 01:35:55 +09:00
kngwyu b42886a38a Change PyCFunction to take &'static str as a function name 2020-10-08 17:26:55 +09:00
dvermd df984ec8df
Keyword only arguments (#1209)
* allow keyword arguments without default value

* allow keyword-only arguments
2020-10-01 13:34:54 +09:00
Alex Gaynor c22dd6c54c Remove symbols not available in abi3 2020-09-23 22:30:07 -04:00
Yuji Kanagawa e33e58fc72
Merge pull request #1201 from alex/abi3-text-signature
Hack __text_signature__ back to working with abi3
2020-09-20 16:46:04 +09:00
kngwyu 869a5e2f20 Fix an abi3 ui test for the latest Rustc 2020-09-20 15:33:55 +09:00
Alex Gaynor 9d8559158b Hack __text_signature__ back to working with abi3 2020-09-19 11:43:57 -04:00
kngwyu 7644d67ad8 Inhibit subclassing native types with ABI3 set 2020-09-20 00:42:55 +09:00
Alex Gaynor ba1056006a Get all the tests building, everythign except doctests passes! 2020-09-16 08:42:22 -04:00
Alex Gaynor 5bfb4674b1 Merge branch 'master' into abi3-merge-master 2020-09-10 17:01:13 -04:00
David Hewitt 151af7a0b7
Merge pull request #1115 from davidhewitt/std-py-err
Implement std::error::Error for PyErr
2020-09-10 21:17:11 +01:00
David Hewitt b9e95dc7c9 Implement std::error::Error for PyErr 2020-09-10 19:04:24 +01:00
kngwyu 7a4c5e2960 Merge branch 'master' into abi3 2020-09-10 00:48:20 +09:00
Sebastian Pütz 22881a3c2f Change add_function, ensure static docstrings.
Change add_function to take `&PyCFunction` instead of a wrapper
fn and ensure that dostrings of functions are `&'static str`.
2020-09-09 12:37:37 +02:00
Alex Gaynor 117f60bed0 Make PyType::name abi3 compatible
The implementation is more complex, because there's no equivalent to tp_name in the limited API
2020-09-08 12:22:59 -04:00
Sebastian Pütz be877d133f Add constructor for PyCFunction. 2020-09-08 14:26:08 +02:00
Sebastian Pütz 2e8010b5df Add native Function native types.
Add bindings for PyCFunction, PyFunction, PyClassMethod and
PyStaticMethod.
2020-09-08 09:51:31 +02:00
Sebastian Pütz 64b06ea9ec Change `add_submodule()` to take `&PyModule`.
The C-exported wrapper generated through `#[pymodule]` is only
required for the top-level module.
2020-09-05 15:54:57 +02:00
Sebastian Pütz e65b849ab6 Doc fixes, changelog and rename. 2020-09-05 10:20:22 +02:00
Sebastian Pütz 795c054511 Possible to pass PyModule as first arg.
This commit makes it possible to access the module of a function
by passing the `need_module` argument to the pyfn and pyfunction
macros.
2020-09-04 09:01:21 +02:00
Sebastian Pütz 3214249010 Make python function wrapper creation fallible.
Wrapping a function can fail if we can't get the module name.

Based on suggestion by @kngwyu
2020-09-03 15:48:32 +02:00
Sebastian Pütz 5bbca1a052 Set the module of `#[pyfunction]`s.
Previously neither the module nor the name of the module of
pyfunctions were registered. This commit passes the module and
its name when creating a new pyfunction.

PyModule::add_function and PyModule::add_module have been added and are
set to replace `add_wrapped` in a future release. `add_wrapped` is kept
for compatibility reasons during the transition.

Depending on whether a `PyModule` or `Python` is the argument for the
Python function-wrapper, the module will be registered with the function.
2020-09-03 14:49:28 +02:00
Alex Gaynor 400462063d Proof of concept of using PEP384s PyType_Spec 2020-09-02 16:54:39 -04:00
Yuji Kanagawa 729f2f42e7
Merge pull request #1065 from sebpuetz/union
FromPyObject derivation for structs and enums
2020-08-31 21:28:49 +09:00
Sebastian Pütz 0f32f886b8 More FromPyObject derive suggestions by @davidhewitt 2020-08-30 19:16:59 +02:00
David Hewitt 82cb815afa Use IntoPy<PyObject> for PyModule::add 2020-08-30 16:24:20 +01:00
Sebastian Pütz 7a9f4a1633 FromPyObject derive suggestions by @kngwyu 2020-08-30 15:33:50 +02:00
Sebastian Pütz a8c5379eff Add compile fail tests for FromPyObject derives + some fixes.
Fix some error messages and accidental passes.
2020-08-30 12:54:13 +02:00
Sebastian Pütz 7781bb78de Specify item key and attr name as arguments. 2020-08-30 10:22:01 +02:00
Sebastian Pütz 60fe4925f5 '#[derive(FromPyObject)]` changes suggested by @davidwhewitt. 2020-08-30 10:22:01 +02:00
Sebastian Pütz 7168309464 Derive FromPyObject 2020-08-30 10:22:01 +02:00
David Hewitt 42296ea5c2 Update UI tests for Rust 1.46 2020-08-29 09:22:00 +01:00
Mario 608aea726c
Allow other Result types in `#[pyfunction]` (#1118)
* Added a couple basic tests

* Implemented suggested change

* Fixed type inference

* cargo fmt

* Finished tests and removed warnings

* Include in CHANGELOG.md

* Moved test into separate file

* &'static str and function rename

* Mention in the book
2020-08-29 08:25:20 +01:00
kngwyu 8cbfdd52b8 Simplify test cases where both __*__ and __r*__ are defined 2020-08-20 14:53:47 +09:00
kngwyu 71a7a76227 More tests for RHS 2020-08-20 14:33:47 +09:00
kngwyu f086f48499 Left-hand operands are fellback to RH ones for type mismatching 2020-08-20 14:33:47 +09:00
David Hewitt 565e36d989
Merge pull request #1098 from davidhewitt/py-as-into-ref
Py::as_ref and Py::into_ref (remove AsPyRef)
2020-08-11 20:44:53 +01:00
Yuji Kanagawa c4d9ab227e
Merge branch 'master' into iterator-example 2020-08-10 17:11:00 +09:00
kngwyu 093dda375f Improve lifetime insertions for #[pyproto] 2020-08-10 15:18:16 +09:00
David Hewitt 77ed6d6d69 Remove AsPyRef for just Py::as_ref 2020-08-09 22:47:54 +01:00
David Hewitt ffd6e562ab
Merge pull request #1090 from davidhewitt/unsendable-test-tidy
Change unsendable test to use Rust thread
2020-08-08 18:21:38 +01:00