Commit Graph

62 Commits

Author SHA1 Message Date
WÁNG Xuěruì e6b2216b04
Add several missing wrappers to PyAnyMethods (#4264) 2024-06-20 08:16:06 +00:00
Icxolu aef0a05719
deprecate implicit default for trailing optional arguments (#4078)
* deprecate "trailing optional arguments" implicit default behaviour

* add newsfragment

* generate individual deprecation messages per function

* add migration guide entry
2024-05-10 10:34:58 +00:00
David Hewitt 351c6a0a49
deprecate optional GIL Ref in function argument (#3975) 2024-03-21 07:24:40 +00:00
David Hewitt 870a4bb20d
deprecate GIL refs in function argument (#3847)
* deprecate GIL Refs in function arguments

* fix deprecated gil refs in function arguments

* add notes on deprecations limitations to migration guide

* Apply suggestions from code review

Co-authored-by: Icxolu <10486322+Icxolu@users.noreply.github.com>

* review: Icxolu

* fix proto method extract failure for option

* fix gil refs in examples

---------

Co-authored-by: Icxolu <10486322+Icxolu@users.noreply.github.com>
2024-03-20 22:35:08 +00:00
Icxolu 61bc02d927
deprecate `PyCell::new` in favor of `Py::new` or `Bound::new` (#3872)
* deprecate `PyCell::new` in favor of `Py::new` or `Bound::new`

* update deprecation warning

Co-authored-by: David Hewitt <mail@davidhewitt.dev>

---------

Co-authored-by: David Hewitt <mail@davidhewitt.dev>
2024-02-20 07:45:47 +00:00
David Hewitt 76d1b34cd5 Revert "Merge pull request #3578 from davidhewitt/typed-helpers"
This reverts commit 7b07d6d21b, reversing
changes made to 99858236bd.
2024-02-03 20:56:23 +00:00
Alex Gaynor 339660c117 add PyAnyMethods for binary operators
also pow

fixes #3709
2023-12-29 18:45:18 -05:00
David Hewitt bd0174aa5d Change return types of `py.None()`, `py.NotImplemented()` and `py.Ellipsis()` to typed singletons 2023-11-17 16:16:19 +00:00
David Hewitt 7d486bb72a tests/common.rs -> src/tests/common.rs 2023-09-24 13:34:53 +01:00
mejrs 984fdf57c7 Use Python:;with_gil in tests 2022-07-19 19:34:23 +02:00
mejrs 6f1cf1b662 Add more lints 2022-03-23 08:07:28 +01:00
David Hewitt 6af47c78f1 pymethods: more tests for magic methods 2022-02-16 07:42:25 +00:00
David Hewitt a9b98b7433 pymethods: __ipow__ always receive None on Python 3.7 2022-01-04 22:59:08 +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 6433d884fc dev: remove self dev dependency 2021-12-08 07:48:58 +00:00
David Hewitt 0e0e6f8bf5 pymethods: support protocols with `multiple-pymethods` feature 2021-10-23 00:07:35 +01:00
David Hewitt 212404bc23 pymethods: support __rtruediv__ and __rfloordiv__ 2021-10-17 08:33:46 +01:00
David Hewitt 592c98c722 pymethods: disable protocols with multiple-pymethods for now 2021-09-18 13:08:24 +01:00
David Hewitt a551b005b4 pymethods: finish support for number protocol 2021-09-18 12:59:25 +01:00
David Hewitt c2d78ca76e pymethods: faster compilation for protos, tidy ups 2021-09-18 09:49:05 +01:00
David Hewitt 92e2156161 pymethods: support inplace numerical operations 2021-09-17 08:13:54 +01:00
David Hewitt ebada76ae3 pyany: add PyAny::py() 2021-08-13 08:00:13 +01:00
David Hewitt 48823e22d6 pyproto: deprecate py_methods 2021-04-20 00:21:19 +01:00
Askaholic 007bfb7ab0
Refactor py_expect_exception to also verify error string representation 2020-10-13 14:02:14 -08: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 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
David Hewitt 4ed9748b45 Rename exceptions to PyException etc; reintroduce deprecated ones 2020-07-18 06:02:57 +01:00
David Hewitt a9c7e12be0 Allow skipping the return type completely for `#[pyproto]` methods returning `()`. 2020-06-23 11:51:02 +01:00
kngwyu 69dba08b01 Use PyMethodsImpl instead of *ProtocolImpl::methods 2020-05-11 20:08:21 +09: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 02ee7a5afc Expose PyAny to lib.rs and prelude 2020-03-18 13:38:18 +09:00
kngwyu 58590393c5 Fix accidently changed file permission 2019-12-24 12:27:22 +09:00
kngwyu a344999526 [DOC] Add Python from Rust section in the guide 2019-09-23 21:44:42 +09:00
hengchu 149163e059 commenting out one of the rhs arithmetics test case for now... 2019-07-24 16:27:07 -04:00
hengchu 3596cc65c0 adding a small testcase for rhs arithmetics 2019-07-21 23:05:03 -04:00
kngwyu 0f9a3b1194 Expose py_run macro 2019-06-13 18:18:06 +09:00
ijl 2bb0d05a30 Drop support for python2 2019-03-29 12:37:26 +00:00
kngwyu 874d8a0835 Rename PyObjectRef with PyAny 2019-03-04 13:50:43 +09:00
konstin ad590bd158 Some api improvements 2019-02-23 18:01:22 +01:00
konstin 6cb098ee12 Replace py.init_[ref|mut] with Py[Ref|Mut]::new 2019-02-13 21:52:21 +01:00
konstin 1a489d2829 Make the init methods use a value instead of a function 2019-02-13 13:59:47 +01:00