Commit graph

1193 commits

Author SHA1 Message Date
Sebastian Pütz 6395c86de4 Gate PyModuleGetNameObject on PyPy. 2020-09-03 14:47:13 +02:00
Yuji Kanagawa 4a05f2782c
Merge pull request #1129 from alex/limit-tuples
Use CPython stable APIs for implementing tuples.
2020-08-31 22:15:58 +09:00
Alex Gaynor 958ce796e9 Use CPython stable APIs for implementing tuples.
Refs #1125

Reduces the number of compilation failures with `--features abi3` from 56 to 53.
2020-08-31 08:46:50 -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
David Hewitt 3151c4876e
Merge pull request #1127 from alex/limit-buffers
Do not include PyBuffer APIs when building for abi3
2020-08-31 09:39:56 +01:00
Yuji Kanagawa 10d83bf7dd
Merge pull request #1124 from davidhewitt/module-constant
Use IntoPy<PyObject> for PyModule::add
2020-08-31 17:39:26 +09:00
Alex Gaynor 3e32b75284 Do not include PyBuffer APIs when building for abi3
Refs #1125

Reduces the number of compilation failures with `--features abi3` from 87 to 56.
2020-08-30 15:29:14 -04:00
Alex Gaynor d93a5e308f Reduce the direct access to tp_name which is not part of the limited API
Refs #1125
2020-08-30 14:36:21 -04:00
David Hewitt 82cb815afa Use IntoPy<PyObject> for PyModule::add 2020-08-30 16:24:20 +01:00
Sebastian Pütz 7168309464 Derive FromPyObject 2020-08-30 10:22:01 +02: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
Ivan Enderlin fee01a125b
doc(pyclass_init) Fix typos 2020-08-27 13:27:16 +02:00
Matthew Treinish dfa917c775
Add optional support for conversion from Hashbrown types
This commit adds optional support for conversion from hashbrown's [1]
HashMap [2] and HashSet [3] types. The HashMap and HashSet implementation
in std::collections is a copy from HashBrown, but Hashbrown still
provides some features over the std::collections version. Primarily this
is rayon support and also using a default hasher which is faster
(although not DOS resistent). The hashbrown versions provide a drop in
replacement over std::collections to get these features. To take
advantage of native type conversion in PyO3 this commit adds hashbrown
as an optional dependency and when the feature is enabled the traits for
going between python and hashbrown::HashMap and hashbrown::HashSet are
available. This is handy for users of hashbrown which have to inline
these conversions manually in functions that take dicts as args.

[1] https://github.com/rust-lang/hashbrown
[2] https://docs.rs/hashbrown/0.8.2/hashbrown/struct.HashMap.html
[3] https://docs.rs/hashbrown/0.8.2/hashbrown/struct.HashSet.html
2020-08-25 06:42:56 -04:00
kngwyu 3e958bf607 Encapsule slot_setter's behavior to an iterator 2020-08-20 14:41:51 +09:00
kngwyu 71a7a76227 More tests for RHS 2020-08-20 14:33:47 +09:00
kngwyu 554ccb9bee Remove macro_export from macros in class/macros.rs 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
Moritz Langenstein e6dc4b2d4d Merge remote-tracking branch 'upstream/master' into fallible_py_bytes_bytearray_new_with 2020-08-11 20:52:49 +00:00
David Hewitt 6b3c6fdeee Improve docs for Py::as_ref() and Py::into_ref()
Co-authored-by: Georg Brandl <georg@python.org>
2020-08-11 08:36:31 +01:00
David Hewitt 7d0b3b386a Add Py::into_ref 2020-08-09 23:00:34 +01:00
David Hewitt 77ed6d6d69 Remove AsPyRef for just Py::as_ref 2020-08-09 22:47:54 +01:00
David Hewitt be239d405f Rework Py methods and documentation 2020-08-09 12:29:25 +01:00
David Hewitt 20959ecc92 Rewrite documentation for FromPy and PyObject changes 2020-08-09 12:29:25 +01:00
David Hewitt f29e6bae7a Replace PyObject with type alias for Py<T> 2020-08-09 12:28:21 +01:00
David Hewitt 7901890974 Remove FromPy 2020-08-09 12:28:21 +01:00
David Hewitt e0376d24aa Experimental support for PyPy 3.6
Co-authored-by: Yuji Kanagawa <yuji.kngw.80s.revive@gmail.com>
2020-08-08 14:54:34 +01:00
David Hewitt 616067230a Only use #[link] for static mut 2020-08-07 06:21:39 +01:00
Moritz Langenstein 4b3422e3b4 Simplified fallible PyBytes::new_with and PyByteArray::new_with API 2020-08-06 14:08:43 +00:00
David Hewitt 1f37dbc1a7 Various fixes to edge cases with GILGuard 2020-08-06 14:32:59 +01:00
Moritz Langenstein aeceb18603 Changed PyByte::new_init and PyByteArray::new_init such that init can fail 2020-08-06 08:48:06 +00: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
Moritz Langenstein a877300f72
Added Rust initialisation of Python-allocated bytes (#1074)
* Added Rust initialisation of Python-allocated bytes

* Added unsafe PyBytes::new_with_unit constructor

* Added examples to PyBytes::new_with and PyBytes::new_with_uninit (now with MaybeUninit<u8>)

* Fixed doc test imports for PyBytes::new_with and PyBytes::new_with_uninit

* Fixed clippy error in PyBytes::new_with_uninit test

* Added PyByteArray::new_with and Removed PyBytes::new_with_uninit

* Small doc fixes + FnOnce init closure for PyBytes::new_with and PyByteArray::new_with

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

* Fixed where clause formatting in PyBytes::new_with and PyByteArray::new_with

Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2020-08-03 09:04:06 +01:00
David Hewitt 09aef5d299 Make PyErr: Send + Sync 2020-07-25 11:59:44 +01:00
Yuji Kanagawa b05eb4814b
Merge pull request #1060 from sebpuetz/memoffset
Calculate offsets for weakreflist and dict in PyCell.
2020-07-21 18:53:29 +09:00
Sebastian Puetz 43d1f43c72 Calculate offsets for weakreflist and dict in PyCell. 2020-07-21 10:38:20 +02:00
David Hewitt 4cf0db0476
Merge pull request #1058 from sebpuetz/dict-unsendable
Move the ThreadChecker field in front of dict and weakref.
2020-07-20 19:21:30 +01: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 0764362d17 Remove hidden PyErr::restore_and_minus1 and PyErr::restore_and_null 2020-07-19 22:39:41 +01:00
Sebastian Puetz 77d03d01f3 Remove explicit matches in conversions.
Don't explicitly match Options and Results if only one of the
variants is changed.
2020-07-19 13:26:59 +02:00
David Hewitt a058eb5201
Remove redundant lifetimes 2020-07-19 11:23:07 +01:00
Sebastian Puetz 63d6d4c0e2 Add type info to conversion errors. 2020-07-19 12:08:14 +02:00
David Hewitt 602080d397 Change PyIterator::from_object` to return underlying TypeError 2020-07-18 09:39:49 +01: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
Simonas Kazlauskas 496c626835 Proto #1: Exception instances as Py<BaseException>
This prototype implements use of Py<BaseException> as the instance to
use for exception instances. These instances integrate reasonably well
with the Rust’s standard error mechanisms by implementing the `Display`
and `Error` traits. These error types can also be stored into e.g.
`failure::Fail`s or other error types as a cause of some greater error.
2020-07-18 01:57:39 +01:00
David Hewitt 264e8854c6
Merge pull request #1048 from davidhewitt/fix-from-type-ptr-doc
Fix doc for PyType::from_type_ptr
2020-07-18 12:01:05 +01:00
Yuji Kanagawa 8bbdbc4937
Merge pull request #1047 from davidhewitt/cast-to-ptr-is-safe
Functions which cast reference to pointer are not unsafe.
2020-07-18 19:52:06 +09:00
David Hewitt 9f3e13ef4d Fix doc for PyType::from_type_ptr 2020-07-17 19:53:20 +01:00
David Hewitt 3341d10e7f Functions which cast reference to pointer are not unsafe. 2020-07-17 19:52:32 +01:00
David Hewitt 45533d6f96 Replace internal uses of (*o).ob_type with Py_TYPE(o) 2020-07-17 19:51:56 +01:00