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
David Hewitt
ad76a8a5ce
Change unsendable test to use Rust thread
2020-08-08 17:45:41 +01:00
David Hewitt
e72b682038
Remove redundant iter test
2020-08-07 13:49:52 +01:00
David Hewitt
1f37dbc1a7
Various fixes to edge cases with GILGuard
2020-08-06 14:32:59 +01:00
Manuel Vázquez Acosta
f2ba3e6da7
#1064 : Comparisons with __eq__ should not raise TypeError ( #1072 )
...
* Add (failing) tests for issue #1064
* Return NotImplemented when richcmp doesn't match the expected type.
* Fix tests that expect TypeError when richcmp returns NotImplemented.
- The python code 'class Other: pass; c2 {} Other()' was raising a NameError:
c2 not found
- eq and ne never raise a TypeError, so I split the those cases.
* Return NotImplemented for number-like binary operations.
* Add dummy impl PyNumberProtocol for the test struct.
* Rework tests of NotImplemented.
* Make py_ternary_num_func return NotImplemented when type mismatches.
* Return NotImplement for type mismatches in binary inplace operators.
* Reduce boilerplate with `extract_or_return_not_implemented!`
* Extract common definition 'Other' into a function.
* Test explicitly for NotImplemented in the __ipow__ test.
* Add entry in CHANGELOG for PR #1072 .
* Add the section 'Emulating numeric types' to the guide.
* Ensure we're returning NotImplemented in tests.
* Simplify the tests: only test we return NotImplemented.
Our previous test were rather indirect: were relying that Python
behaves correctly when we return NotImplemented.
Now we only test that calling a pyclass dunder method returns NotImplemented
when the argument doesn't match the type signature. This is the expected
behavior.
* Remove reverse operators in tests of NotImplemented
The won't be used because of #844 .
* Apply suggestions from code review
Co-authored-by: Yuji Kanagawa <yuji.kngw.80s.revive@gmail.com>
* Add a note about #844 below the list of reflected operations.
Co-authored-by: Yuji Kanagawa <yuji.kngw.80s.revive@gmail.com>
2020-08-05 22:53:16 +09:00
kngwyu
f5f2e84f4b
Enable &Self in #[pymethods] again
2020-07-28 20:55:38 +09:00
Yuji Kanagawa
4563e00a67
Add testcase for unsendable, dict, weakref pyclass.
2020-07-21 10:42:36 +02:00
Sebastian Puetz
e75f768ea8
Move the ThreadChecker field in front of dict and weakref.
...
Offsets for dict and weakref are calculated from the end of the
PyCell struct. When using the non-dummy ThreadChecker, the offsets
were invalid since the `ThreadCheckerImpl` is not zero-sized.
2020-07-20 19:37:38 +02:00
David Hewitt
4ed9748b45
Rename exceptions to PyException etc; reintroduce deprecated ones
2020-07-18 06:02:57 +01:00
David Hewitt
a7e0c6bfa7
Make exceptions proper native types.
2020-07-18 01:57:39 +01:00
kngwyu
3ae1caa55a
Skip panic_unsendable test if -Cpanic=abort is given
2020-06-30 17:58:31 +09:00
kngwyu
d76fe7835a
Introduce #[pyclass(unsendable)]
2020-06-30 12:30:17 +09:00
David Hewitt
c3e993e5a6
Apply suggestions from code review
...
Co-authored-by: Yuji Kanagawa <yuji.kngw.80s.revive@gmail.com>
2020-06-27 14:56:15 +01:00
David Hewitt
e140b729fc
Allow #[getter] and #[setter] functions to take PyRef
2020-06-27 14:55:22 +01:00
kngwyu
a78a832431
Refactor around the nightly feature
2020-06-26 19:29:37 +09:00
scalexm
f49478619f
Re-enable recursive class attributes
...
Use some kind of two-stage initialization as described in #975 , by
being very cautious about when to allow the GIL to be released.
2020-06-23 22:40:29 +02:00
David Hewitt
a9c7e12be0
Allow skipping the return type completely for `#[pyproto]` methods returning `()`.
2020-06-23 11:51:02 +01:00
David Hewitt
c7a4b4770f
Refactor `#[pyproto]` Result types
2020-06-23 11:08:36 +01:00
kngwyu
b70ee9a5ad
Use subclass correctly in tp_new
2020-06-22 01:38:13 +09:00
Yuji Kanagawa
7075827a03
Merge pull request #969 from PyO3/poc-stable-rust
...
Stable Rust
2020-06-21 16:54:59 +09:00
kngwyu
a63e426f6f
Some doc and test cleanups mainly around specialization
2020-06-20 12:59:56 +09:00
David Hewitt
a1dbfa8c8c
Add pyo3::once_cell::GILOnceCell
2020-06-18 18:53:32 +01:00
kngwyu
a840ebbb5a
Support Rust 1.39.0
2020-06-18 19:59:40 +09:00
kngwyu
654ab4c819
Enable tests for --features nighly on travis
2020-06-18 18:16:01 +09:00
kngwyu
0f709d6edc
Use paste instead of nightly concat_idents in datetime tests
2020-06-18 18:15:36 +09:00
konstin
6798fe9da7
Fix tests on stable
2020-06-18 17:23:49 +09:00
konstin
3180e5cc06
POC stable rust (2 tests failing)
2020-06-18 17:21:09 +09:00
Yuji Kanagawa
a044f3c322
Merge branch 'master' into slot-provider
2020-06-18 15:49:56 +09:00
kngwyu
1207c2d03a
Make test_await more robust
2020-06-18 01:58:01 +09:00
kngwyu
2e1ed2c3c8
Descr get/set now take receiver
2020-06-15 13:43:46 +09:00
David Hewitt
a85d157111
Cleanups to ensure GIL-safety of Py<T> and PyObject methods
2020-06-14 16:37:34 +01:00
kngwyu
8c4162dfeb
Async methods now takes Receiver
2020-06-14 22:43:07 +09:00
kngwyu
f32277163a
Move nb_bool under PyObjectProtocol again
2020-06-13 15:25:04 +09:00
kngwyu
7967874177
Remove specialization from basic/buffer/descr/iter protocols
2020-06-13 15:24:56 +09:00
David
33617bfffc
Require Send for #[pyclass]
2020-06-08 02:06:15 +01:00
Yuji Kanagawa
d674b5ff34
Merge pull request #952 from kngwyu/typed-pybuffer
...
Typed PyBuffer
2020-06-05 23:08:07 +09:00
Alexander Niederbühl
bcf48c0bd2
Fix clippy lints
2020-06-05 13:53:01 +02:00
Yuji Kanagawa
5939362e72
Fix docs and comments based on the review
...
Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2020-06-05 17:48:43 +09:00
kngwyu
688021315e
Typed PyBuffer
2020-06-04 22:03:53 +09:00
David Hewitt
29c93c87c7
Remove GetPropertyValue
2020-05-21 18:06:24 +01:00
Yuji Kanagawa
7fd35b2fb6
Merge pull request #937 from davidhewitt/doc-conversion-table
...
Add conversion table to guide
2020-05-21 16:18:46 +09:00
David Hewitt
2813d2e6c9
Add conversion table to guide
2020-05-19 22:22:38 +01:00
David Hewitt
5c5527dfec
Fix passing explicit None to pyfunction with default
2020-05-17 19:19:33 +01:00
kngwyu
69dba08b01
Use PyMethodsImpl instead of *ProtocolImpl::methods
2020-05-11 20:08:21 +09:00
scalexm
f6ac9a0212
Allow `#[classattr]` on associated constants
2020-05-08 22:30:49 +02:00
Yuji Kanagawa
d5eb8f0544
Merge pull request #911 from davidhewitt/remove-objectprotocol
...
Remove ObjectProtocol
2020-05-08 18:56:52 +09:00
David Hewitt
a5ebef4b2e
Remove ObjectProtocol; Add methods to PyAny and use Deref
2020-05-08 10:05:19 +01:00
scalexm
d3d68eafb4
Add a test with class attrs returning `PyClass` instances
2020-05-07 21:25:27 +02:00
scalexm
8f22d10a14
Add a test showing that class attrs are immutable
2020-05-07 21:24:36 +02:00
scalexm
7b5a076680
Add `#[classattr]` methods to define Python class attributes
2020-05-07 21:23:47 +02:00
David Hewitt
9a2d908342
Simplify callback code using callback_body! macro
2020-05-05 00:27:50 +01:00
David Hewitt
dfbe22bb56
Thread-safe release pools
2020-05-02 13:16:22 +01:00
David Hewitt
3008528fa6
Allow use of `#[pyo3(get, set)]` with `Py<T>`
2020-04-22 22:21:27 +01:00
Mara Bos
dcab478d66
Fix lifetime safety bug of AsPyRef::as_ref(). ( #876 )
...
* Fix lifetime safety bug of AsPyRef::as_ref().
Fixes #875 .
* Add test for AsPyRef's lifetimes.
2020-04-20 18:44:31 +01:00
Martin Larralde
ed63902eeb
Modify existing `PyIteratorProtocol` tests to use `PyRef` where possible
2020-04-18 03:57:17 +02:00
Yuji Kanagawa
ae81865232
Apply suggestions from David
...
Co-Authored-By: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2020-04-13 11:05:48 +09:00
kngwyu
2cd466dc46
Bound 'py lifetime by GILPool when it's possible
2020-04-12 23:55:23 +09:00
Yuji Kanagawa
5e285fda78
Fix synchronization of datetime tests ( #867 )
...
* Fix synchronization of datetime tests
* Use Mutex instead of RawMutex
2020-04-11 19:10:16 +09:00
kngwyu
9dc3f9dc1a
Lock other threads before import datetime to avoid test failure
2020-04-09 22:11:03 +09:00
Martin Larralde
1e8e6fd827
Fix clippy warning about unused arguments in `tests/test_gc.rs`
2020-04-09 02:06:19 +02:00
Martin Larralde
5f2ec47bea
Add proper test for GC double borrow issue in `tp_traverse` wrapper
2020-04-09 00:52:49 +02:00
kngwyu
8d1678e28e
Separate examples and tooling section in README and the guide
2020-04-02 23:56:19 +09:00
David Hewitt
1efe142566
Fix clippy warning
2020-03-30 11:48:01 +09:00
kngwyu
ac418ce020
Inhibit __ipow__ to take Modulo
2020-03-30 03:01:44 +09:00
kngwyu
25eda36353
Speficy METH_COEXIST for some number methods except
2020-03-30 02:02:57 +09:00
kngwyu
a76bd7c4e3
Add a test that shows __add__ overrides __radd__
2020-03-29 00:26:11 +09:00
kngwyu
970e393bb9
Make __r*__ methods work by slot fallback
2020-03-28 18:17:40 +09:00
kngwyu
c234476693
chmod -x for test files
2020-03-27 00:41:01 +09:00
kngwyu
5280a281c9
Remove GILPool::new_no_pointer
2020-03-26 19:45:32 +09:00
Yuji Kanagawa
3b8af93aea
Merge pull request #826 from kngwyu/pyclass-err-improve
...
More ergonomic error messages for invalid #[pyclass] args
2020-03-23 18:51:16 +09:00
Yuji Kanagawa
3b17ab0529
Apply suggestions from code review
...
Co-Authored-By: Georg Brandl <georg@python.org>
2020-03-23 13:18:38 +09:00
kngwyu
1e39071c04
Retrieve FromPyObject implementation for &PySequence
2020-03-22 20:00:21 +09:00
kngwyu
9b5ea3f46b
More ergonomic error messages for invalid #[pyclass] args
2020-03-22 17:13:02 +09:00
kngwyu
02ee7a5afc
Expose PyAny to lib.rs and prelude
2020-03-18 13:38:18 +09:00
kngwyu
40077245ea
Fix PyModule::dict
2020-03-16 15:45:54 +09:00
kngwyu
cea707dd1c
Inhibit positional args after *
2020-03-06 14:01:27 +09:00
kngwyu
25069baef4
Fix the interpretation of '*'
2020-03-04 23:48:46 +09:00
kngwyu
96115eaaaa
Refactor some tests in test_methods
2020-03-04 20:35:46 +09:00
kngwyu
bbe4393b1e
Add more tests in method_with_pyclassarg
2020-03-04 20:25:30 +09:00
kngwyu
e63e0cbf5a
Make it enable to take &PyClass as arguments as pyfunctions/methods
2020-03-04 13:37:26 +09:00
kngwyu
6c652dff8c
Merge branch 'master' into pycell
2020-02-25 20:15:17 +09:00
kngwyu
18957159f4
Add tests for inheriting class with dict or weakref
2020-02-25 20:02:27 +09:00
kngwyu
3d0ee2a28d
Use AsRef/AsMut instead of as_super/as_super_mut
2020-02-21 20:37:35 +09:00
Andrew Whitehead
ca6cb99a4b
Implement buffer release for PyBufferProtocol; change callback signatures to pass PyClassShell
...
Signed-off-by: Andrew Whitehead <cywolf@gmail.com>
2020-02-20 12:48:22 -08:00
kngwyu
1f5cb83ef8
Add tests for mutability checking
2020-02-18 15:28:04 +09:00
kngwyu
4b746af11b
Rename unchecked_refmut -> unchecked_mut
2020-02-18 12:55:06 +09:00
kngwyu
2fd2185052
Merge branch 'master' into pycell
2020-02-17 00:07:15 +09:00
kngwyu
8f8b42591a
Fix PySelf and AsPyRef
2020-02-16 23:54:55 +09:00
David Hewitt
d5509424b2
Make #[pymethods] aware of #[cfg]
2020-02-15 14:07:48 +00:00
kngwyu
da4ed398bb
Fix PyCell to share BorrowFlag with parents
2020-02-15 18:13:39 +09:00
Yuji Kanagawa
0eb4eb4e58
Merge branch 'master' into property-fixes
2020-02-10 15:13:19 +09:00
kngwyu
a6fed34e23
Fix clippy warnings in build.rs and tests
2020-02-10 14:53:13 +09:00
David Hewitt
6c25f6aacc
Bump minimum Rust version to 1.42.0-nightly
2020-02-09 10:54:00 +00:00
David Hewitt
cea8a9a2b0
Refactor to clean up property descriptor macros
2020-02-08 18:57:30 +00:00
kngwyu
a2408cacbb
Rename PyClassShell with PyCell
2020-02-08 15:05:13 +09:00
David Hewitt
f8c8b8effd
Fix for PyObject with `#[pyo3(get)]`
2020-02-07 19:31:13 +00:00
Yuji Kanagawa
14980d742d
Merge pull request #755 from davidhewitt/property-doc
...
Fix docstrings generated by `[pyo3(get, set)]`
2020-02-03 18:14:54 +09:00
David Hewitt
dfb7d7c58d
Fix docstrings generated by `[pyo3(get, set)]`
2020-02-03 08:01:30 +00:00
David Hewitt
7531b9fb07
Remove even more uses of `static mut`
2020-01-30 13:24:55 +00:00
David Hewitt
a8ec946fc3
Fix usage of raw idents with #[pyo3(set)]
2020-01-27 10:29:14 +00:00
Yuji Kanagawa
c57e5f1830
Merge pull request #744 from Hywan/patch-2
...
test: Fix a typo in an error message
2020-01-25 12:42:49 +09:00
David Hewitt
fdf407e045
FromPyObject for #[pyclass] with T: Clone
2020-01-24 08:57:28 +00:00
Ivan Enderlin
8ed2662251
test: Fix a typo in an error message
...
Thank for the awesome project!
2020-01-24 08:44:23 +01:00
Alexander Niederbühl
cffefa4fa8
Add debug output for flaky test
2020-01-12 15:44:42 +01:00
Alexander Niederbühl
0a84c201f7
Revert "Disable segfaulty subclassing by default"
...
This reverts commit 5096f936dc
.
2020-01-12 01:22:32 +01:00
kngwyu
302b3bb088
Merge branch 'master' into pyclass-new-layout
2020-01-11 15:03:25 +09:00
Alexander Niederbühl
1f675dcaa7
Clear error indicator when the exception is handled on the Rust side
...
Leaving Python's global exception state is misleading, e.g. subsequent
calls of `py.eval` will fail.
2020-01-11 00:44:11 +01:00
kngwyu
c57177a169
Refine tests and documents around pyclass.rs
2020-01-08 22:44:50 +09:00
kngwyu
b602b4bf6c
Enhance documentation and tests around #[new]
2020-01-07 12:49:36 +09:00
kngwyu
18e565fab5
New PyClassInitializer
2020-01-05 16:01:05 +09:00
kngwyu
58590393c5
Fix accidently changed file permission
2019-12-24 12:27:22 +09:00
kngwyu
ea51756933
Resolve some clippy complains
2019-12-23 18:05:06 +09:00
kngwyu
e2dc843de5
Fix a corner case for PyClassInitializer
2019-12-22 23:54:41 +09:00
kngwyu
6b84401126
Make it enable to safely inherit native types
2019-12-21 23:28:55 +09:00
kngwyu
8175d6f36a
Merge branch 'master' into pyclass-new-layout
2019-12-19 16:12:45 +09:00
David Hewitt
b245e71c14
Address comments from PR#692
2019-12-18 14:26:25 +00:00
David Hewitt
0032508c3c
Format code
2019-12-17 22:58:34 +00:00
David Hewitt
4b18830f1e
Add `#[name]` attribute support for `#[pyfunction]`
2019-12-17 22:14:28 +00:00
David Hewitt
7702395b3d
Add #[name = "foo"] attribute to #[pymethods]
2019-12-17 17:45:53 +00:00
kngwyu
b86de9376d
Introduce PyClassInitializer
2019-12-15 21:04:36 +09:00
kngwyu
a6639076b9
Introduce PyInternalCaster
2019-12-14 23:16:39 +09:00
kngwyu
4b5fa7e977
Introduce PyClass trait and PyClassShell
2019-12-07 17:56:49 +09:00
Jacob Lifshay
af8c0d2531
switch text_signature to arguments only & add tests
2019-11-29 12:19:56 -08:00
Sebastian Puetz
3b707c8511
Remove contains and iter from PyMappingProtocol.
...
The methods are not expected by CPython and are only explicitly
callable. To get iteration support, PyIterProtocol should be
implemented and to get support for `x in mapping`,
PySequenceProtocol's __contains__ should be implemented.
https://github.com/PyO3/pyo3/issues/611
2019-10-25 17:20:44 +02:00
Alexander Niederbühl
7a4909bdc7
Guard against PyUnicode_AsUTF8AndSize returning null
2019-10-23 00:39:47 +02:00
Alexander Niederbühl
69cbf1a494
Remove test_get_pybytes
2019-10-20 15:12:17 +02:00
Alexander Niederbühl
b0925e1109
Add conversion traits for PyBytes
2019-10-20 14:42:12 +02:00
Yuji Kanagawa
f6f607ef68
Merge pull request #624 from kngwyu/seq-setitem
...
Fix PySequenceProtocol::set_item
2019-10-19 13:44:49 +09:00
Alexander Niederbühl
e91d969e17
Make tests for optional arguments more consistent
2019-10-13 23:17:57 +02:00
Alexander Niederbühl
c7a53611e0
Enable to give None as default value for an argument
2019-10-12 20:16:25 +02:00
kngwyu
d57f2423c8
Fix PySequenceProtocol::set_item
2019-10-12 21:03:21 +09:00