From 720893a62151d00223478072d504f6102cf2866b Mon Sep 17 00:00:00 2001
From: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
Date: Fri, 2 Jun 2023 08:09:22 +0100
Subject: [PATCH 01/59] update PR template to detail state of licensing
---
.github/pull_request_template.md | 6 +++++-
README.md | 3 ++-
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md
index 4473a007e8f..f9877a1ca40 100644
--- a/.github/pull_request_template.md
+++ b/.github/pull_request_template.md
@@ -1,4 +1,8 @@
-Thank you for contributing to pyo3!
+Thank you for contributing to PyO3!
+
+By submitting these contributions you agree for them to be licensed under PyO3's [Apache-2.0 license](https://github.com/PyO3/pyo3#license).
+
+PyO3 is currently undergoing a relicensing process to match Rust's dual-license under `Apache-2.0` and `MIT` licenses. While that process is ongoing, if you are a first-time contributor please add your agreement as a comment in [#3108](https://github.com/PyO3/pyo3/pull/3108).
Please consider adding the following to your pull request:
- an entry for this PR in newsfragments - see [https://pyo3.rs/main/contributing.html#documenting-changes]
diff --git a/README.md b/README.md
index 594fbc7f519..cbfe3306e25 100644
--- a/README.md
+++ b/README.md
@@ -244,7 +244,8 @@ If you don't have time to contribute yourself but still wish to support the proj
## License
-PyO3 is licensed under the [Apache-2.0 license](https://opensource.org/licenses/APACHE-2.0).
+PyO3 is licensed under the [Apache-2.0 license](https://opensource.org/licenses/APACHE-2.0). (The PyO3 project is in the process of collecting permission from past contributors to additionally license under the [MIT license](https://opensource.org/license/mit/), see [#3108](https://github.com/PyO3/pyo3/pull/3108). Once complete, PyO3 will additionally be licensed under the MIT license, the same as the Rust language itself is both Apache and MIT licensed.)
+
Python is licensed under the [Python License](https://docs.python.org/3/license.html).
From 4f5ee5f03d4251289740e7b0f6cf3130c34fcd4d Mon Sep 17 00:00:00 2001
From: Jake Lishman
Date: Wed, 31 May 2023 16:51:40 +0100
Subject: [PATCH 02/59] Add `PyAny::lookup_special`
`PyAny::lookup_special` is an approximate equivalent to the CPython
internal `_PyObject_LookupSpecial`, which is used to resolve lookups of
"magic" methods. These are only looked up from the type, and skip the
instance dictionary during the lookup. Despite this, they are still
required to resolve the descriptor protocol.
Many magic methods have slots on the `PyTypeObject` or respective
subobjects, but these are not necessarily available when targeting the
limited API or PyPy. In these cases, the requisite logic can be worked
around using safe but likely slower APIs.
Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
Fix up lookup-special
---
src/types/any.rs | 120 ++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 119 insertions(+), 1 deletion(-)
diff --git a/src/types/any.rs b/src/types/any.rs
index afdeb6ab573..a545d9b2ac1 100644
--- a/src/types/any.rs
+++ b/src/types/any.rs
@@ -124,6 +124,51 @@ impl PyAny {
}
}
+ /// Retrieve an attribute value, skipping the instance dictionary during the lookup but still
+ /// binding the object to the instance.
+ ///
+ /// This is useful when trying to resolve Python's "magic" methods like `__getitem__`, which
+ /// are looked up starting from the type object. This returns an `Option` as it is not
+ /// typically a direct error for the special lookup to fail, as magic methods are optional in
+ /// many situations in which they might be called.
+ ///
+ /// To avoid repeated temporary allocations of Python strings, the [`intern!`] macro can be used
+ /// to intern `attr_name`.
+ #[allow(dead_code)] // Currently only used with num-complex+abi3, so dead without that.
+ pub(crate) fn lookup_special(&self, attr_name: N) -> PyResult