Skip to content

Commit 3032224

Browse files
authored
Upgrade to pyo3 0.26, fixing all warnings (pyca#13366)
* Upgrade to pyo3 0.26, fixing all warnings * GHA
1 parent 1fba706 commit 3032224

File tree

18 files changed

+90
-82
lines changed

18 files changed

+90
-82
lines changed

Cargo.lock

Lines changed: 10 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ license = "Apache-2.0 OR BSD-3-Clause"
2222

2323
[workspace.dependencies]
2424
asn1 = { version = "0.22.0", default-features = false }
25-
pyo3 = { version = "0.25", features = ["abi3"] }
26-
pyo3-build-config = { version = "0.25" }
25+
pyo3 = { version = "0.26", features = ["abi3"] }
26+
pyo3-build-config = { version = "0.26" }
2727
openssl = "0.10.73"
2828
openssl-sys = "0.9.108"
2929

src/rust/src/backend/cipher_registry.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ use crate::error::CryptographyResult;
1111
use crate::types;
1212

1313
struct RegistryKey {
14-
algorithm: pyo3::PyObject,
15-
mode: pyo3::PyObject,
14+
algorithm: pyo3::Py<pyo3::PyAny>,
15+
mode: pyo3::Py<pyo3::PyAny>,
1616
key_size: Option<u16>,
1717

1818
algorithm_hash: isize,
@@ -22,8 +22,8 @@ struct RegistryKey {
2222
impl RegistryKey {
2323
fn new(
2424
py: pyo3::Python<'_>,
25-
algorithm: pyo3::PyObject,
26-
mode: pyo3::PyObject,
25+
algorithm: pyo3::Py<pyo3::PyAny>,
26+
mode: pyo3::Py<pyo3::PyAny>,
2727
key_size: Option<u16>,
2828
) -> CryptographyResult<Self> {
2929
Ok(Self {
@@ -113,8 +113,8 @@ impl<'p> RegistryBuilder<'p> {
113113
fn get_cipher_registry(
114114
py: pyo3::Python<'_>,
115115
) -> CryptographyResult<&HashMap<RegistryKey, RegistryCipher>> {
116-
static REGISTRY: pyo3::sync::GILOnceCell<HashMap<RegistryKey, RegistryCipher>> =
117-
pyo3::sync::GILOnceCell::new();
116+
static REGISTRY: pyo3::sync::PyOnceLock<HashMap<RegistryKey, RegistryCipher>> =
117+
pyo3::sync::PyOnceLock::new();
118118

119119
REGISTRY.get_or_try_init(py, || {
120120
let mut m = RegistryBuilder::new(py);

src/rust/src/backend/ciphers.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use crate::{exceptions, types};
1212

1313
pub(crate) struct CipherContext {
1414
ctx: openssl::cipher_ctx::CipherCtx,
15-
py_mode: pyo3::PyObject,
16-
py_algorithm: pyo3::PyObject,
15+
py_mode: pyo3::Py<pyo3::PyAny>,
16+
py_algorithm: pyo3::Py<pyo3::PyAny>,
1717
side: openssl::symm::Mode,
1818
}
1919

src/rust/src/backend/keys.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -377,9 +377,9 @@ mod tests {
377377
#[test]
378378
#[cfg(not(any(CRYPTOGRAPHY_IS_BORINGSSL, CRYPTOGRAPHY_IS_AWSLC)))]
379379
fn test_public_key_from_pkey_unknown_key() {
380-
pyo3::prepare_freethreaded_python();
380+
pyo3::Python::initialize();
381381

382-
pyo3::Python::with_gil(|py| {
382+
pyo3::Python::attach(|py| {
383383
let pkey =
384384
openssl::pkey::PKey::public_key_from_raw_bytes(&[0; 32], openssl::pkey::Id::X25519)
385385
.unwrap();
@@ -392,9 +392,9 @@ mod tests {
392392
#[test]
393393
#[cfg(not(any(CRYPTOGRAPHY_IS_BORINGSSL, CRYPTOGRAPHY_IS_AWSLC)))]
394394
fn test_private_key_from_pkey_unknown_key() {
395-
pyo3::prepare_freethreaded_python();
395+
pyo3::Python::initialize();
396396

397-
pyo3::Python::with_gil(|py| {
397+
pyo3::Python::attach(|py| {
398398
let pkey = openssl::pkey::PKey::hmac(&[0; 32]).unwrap();
399399
assert!(private_key_from_pkey(py, &pkey, false).is_err());
400400
});

src/rust/src/error.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ impl From<CryptographyError> for pyo3::PyErr {
158158
pyo3::exceptions::PyMemoryError::new_err(e.to_string())
159159
}
160160
CryptographyError::Py(py_error) => py_error,
161-
CryptographyError::OpenSSL(ref error_stack) => pyo3::Python::with_gil(|py| {
161+
CryptographyError::OpenSSL(ref error_stack) => pyo3::Python::attach(|py| {
162162
let errors = list_from_openssl_error(py, error_stack);
163163
exceptions::InternalError::new_err((e.to_string(), errors.unbind()))
164164
}),
@@ -238,8 +238,8 @@ mod tests {
238238

239239
#[test]
240240
fn test_cryptographyerror_display() {
241-
pyo3::prepare_freethreaded_python();
242-
pyo3::Python::with_gil(|py| {
241+
pyo3::Python::initialize();
242+
pyo3::Python::attach(|py| {
243243
let py_error = pyo3::exceptions::PyRuntimeError::new_err("abc");
244244
let e: CryptographyError = py_error.clone_ref(py).into();
245245
assert!(e.to_string() == py_error.to_string());
@@ -248,8 +248,8 @@ mod tests {
248248

249249
#[test]
250250
fn test_cryptographyerror_from() {
251-
pyo3::prepare_freethreaded_python();
252-
pyo3::Python::with_gil(|py| {
251+
pyo3::Python::initialize();
252+
pyo3::Python::attach(|py| {
253253
let e: CryptographyError = asn1::WriteError::AllocationError.into();
254254
assert!(matches!(
255255
e,

src/rust/src/oid.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ impl ObjectIdentifier {
3939
.call_method1(pyo3::intern!(py, "get"), (slf, "Unknown OID"))
4040
}
4141

42-
fn __deepcopy__(slf: pyo3::PyRef<'_, Self>, _memo: pyo3::PyObject) -> pyo3::PyRef<'_, Self> {
42+
fn __deepcopy__(
43+
slf: pyo3::PyRef<'_, Self>,
44+
_memo: pyo3::Py<pyo3::PyAny>,
45+
) -> pyo3::PyRef<'_, Self> {
4346
slf
4447
}
4548

src/rust/src/types.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ use pyo3::types::PyAnyMethods;
77
pub struct LazyPyImport {
88
module: &'static str,
99
names: &'static [&'static str],
10-
value: pyo3::sync::GILOnceCell<pyo3::PyObject>,
10+
value: pyo3::sync::PyOnceLock<pyo3::Py<pyo3::PyAny>>,
1111
}
1212

1313
impl LazyPyImport {
1414
pub const fn new(module: &'static str, names: &'static [&'static str]) -> LazyPyImport {
1515
LazyPyImport {
1616
module,
1717
names,
18-
value: pyo3::sync::GILOnceCell::new(),
18+
value: pyo3::sync::PyOnceLock::new(),
1919
}
2020
}
2121

@@ -608,10 +608,10 @@ mod tests {
608608

609609
#[test]
610610
fn test_basic() {
611-
pyo3::prepare_freethreaded_python();
611+
pyo3::Python::initialize();
612612

613613
let v = LazyPyImport::new("foo", &["bar"]);
614-
pyo3::Python::with_gil(|py| {
614+
pyo3::Python::attach(|py| {
615615
assert!(v.get(py).is_err());
616616
});
617617
}

src/rust/src/x509/certificate.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ self_cell::self_cell!(
4141
#[pyo3::pyclass(frozen, module = "cryptography.hazmat.bindings._rust.x509")]
4242
pub(crate) struct Certificate {
4343
pub(crate) raw: OwnedCertificate,
44-
pub(crate) cached_extensions: pyo3::sync::GILOnceCell<pyo3::PyObject>,
44+
pub(crate) cached_extensions: pyo3::sync::PyOnceLock<pyo3::Py<pyo3::PyAny>>,
4545
}
4646

4747
#[pyo3::pymethods]
@@ -62,7 +62,10 @@ impl Certificate {
6262
Ok(format!("<Certificate(subject={subject_repr}, ...)>"))
6363
}
6464

65-
fn __deepcopy__(slf: pyo3::PyRef<'_, Self>, _memo: pyo3::PyObject) -> pyo3::PyRef<'_, Self> {
65+
fn __deepcopy__(
66+
slf: pyo3::PyRef<'_, Self>,
67+
_memo: pyo3::Py<pyo3::PyAny>,
68+
) -> pyo3::PyRef<'_, Self> {
6669
slf
6770
}
6871

@@ -292,7 +295,7 @@ impl Certificate {
292295
}
293296

294297
#[getter]
295-
fn extensions(&self, py: pyo3::Python<'_>) -> pyo3::PyResult<pyo3::PyObject> {
298+
fn extensions(&self, py: pyo3::Python<'_>) -> pyo3::PyResult<pyo3::Py<pyo3::PyAny>> {
296299
x509::parse_and_cache_extensions(
297300
py,
298301
&self.cached_extensions,
@@ -432,7 +435,7 @@ pub(crate) fn load_der_x509_certificate(
432435

433436
Ok(Certificate {
434437
raw,
435-
cached_extensions: pyo3::sync::GILOnceCell::new(),
438+
cached_extensions: pyo3::sync::PyOnceLock::new(),
436439
})
437440
}
438441

src/rust/src/x509/common.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,10 +382,10 @@ pub(crate) fn parse_and_cache_extensions<
382382
F: Fn(&Extension<'p>) -> Result<Option<pyo3::Bound<'p, pyo3::PyAny>>, CryptographyError>,
383383
>(
384384
py: pyo3::Python<'p>,
385-
cached_extensions: &pyo3::sync::GILOnceCell<pyo3::PyObject>,
385+
cached_extensions: &pyo3::sync::PyOnceLock<pyo3::Py<pyo3::PyAny>>,
386386
raw_extensions: &Option<RawExtensions<'p>>,
387387
parse_ext: F,
388-
) -> pyo3::PyResult<pyo3::PyObject> {
388+
) -> pyo3::PyResult<pyo3::Py<pyo3::PyAny>> {
389389
cached_extensions
390390
.get_or_try_init(py, || {
391391
let extensions = match Extensions::from_raw_extensions(raw_extensions.as_ref()) {

0 commit comments

Comments
 (0)