From b08ee4b7e17b88988f2d2ab94e24596c580222ac Mon Sep 17 00:00:00 2001 From: David Hewitt Date: Mon, 4 Mar 2024 22:23:35 +0000 Subject: [PATCH] remove `gil-refs` feature from `full` feature (#3930) --- Cargo.toml | 3 +-- noxfile.py | 18 +++++++++++++----- src/conversions/chrono.rs | 4 ++-- src/conversions/num_bigint.rs | 8 ++++---- src/conversions/rust_decimal.rs | 14 +++----------- 5 files changed, 23 insertions(+), 24 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e7364a7c..32fa5a00 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -110,7 +110,6 @@ nightly = [] # This is mostly intended for testing purposes - activating *all* of these isn't particularly useful. full = [ "macros", - "gil-refs", # "multiple-pymethods", # TODO re-add this when MSRV is greater than 1.62 "anyhow", "chrono", @@ -140,7 +139,7 @@ members = [ [package.metadata.docs.rs] no-default-features = true -features = ["full"] +features = ["full", "gil-refs"] rustdoc-args = ["--cfg", "docsrs"] [workspace.lints.clippy] diff --git a/noxfile.py b/noxfile.py index add737e5..2aa0f464 100644 --- a/noxfile.py +++ b/noxfile.py @@ -46,6 +46,7 @@ def test_rust(session: nox.Session): _run_cargo_test(session, features="abi3") if "skip-full" not in session.posargs: _run_cargo_test(session, features="full") + _run_cargo_test(session, features="full gil-refs") _run_cargo_test(session, features="abi3 full") @@ -617,6 +618,7 @@ def check_feature_powerset(session: nox.Session): EXCLUDED_FROM_FULL = { "nightly", + "gil-refs", "extension-module", "full", "default", @@ -658,10 +660,15 @@ def check_feature_powerset(session: nox.Session): session.error("no experimental features exist; please simplify the noxfile") features_to_skip = [ - *EXCLUDED_FROM_FULL, + *(EXCLUDED_FROM_FULL - {"gil-refs"}), *abi3_version_features, ] + # deny warnings + env = os.environ.copy() + rust_flags = env.get("RUSTFLAGS", "") + env["RUSTFLAGS"] = f"{rust_flags} -Dwarnings" + comma_join = ",".join _run_cargo( session, @@ -672,6 +679,7 @@ def check_feature_powerset(session: nox.Session): *(f"--group-features={comma_join(group)}" for group in features_to_group), "check", "--all-targets", + env=env, ) @@ -715,8 +723,8 @@ def _get_feature_sets() -> Tuple[Tuple[str, ...], ...]: "--no-default-features", "--features=abi3", ), - ("--features=full multiple-pymethods",), - ("--features=abi3 full multiple-pymethods",), + ("--features=full gil-refs multiple-pymethods",), + ("--features=abi3 full gil-refs multiple-pymethods",), ) else: return ( @@ -725,8 +733,8 @@ def _get_feature_sets() -> Tuple[Tuple[str, ...], ...]: "--no-default-features", "--features=abi3", ), - ("--features=full",), - ("--features=abi3 full",), + ("--features=full gil-refs",), + ("--features=abi3 full gil-refs",), ) diff --git a/src/conversions/chrono.rs b/src/conversions/chrono.rs index 3aa6dbeb..134724b2 100644 --- a/src/conversions/chrono.rs +++ b/src/conversions/chrono.rs @@ -980,13 +980,13 @@ mod tests { let td = new_py_datetime_ob(py, "timedelta", (0, 3600, 0)); let py_timedelta = new_py_datetime_ob(py, "timezone", (td,)); // Should be equal - assert!(offset.as_ref(py).eq(py_timedelta).unwrap()); + assert!(offset.bind(py).eq(py_timedelta).unwrap()); // Same but with negative values let offset = FixedOffset::east_opt(-3600).unwrap().to_object(py); let td = new_py_datetime_ob(py, "timedelta", (0, -3600, 0)); let py_timedelta = new_py_datetime_ob(py, "timezone", (td,)); - assert!(offset.as_ref(py).eq(py_timedelta).unwrap()); + assert!(offset.bind(py).eq(py_timedelta).unwrap()); }) } diff --git a/src/conversions/num_bigint.rs b/src/conversions/num_bigint.rs index 69bc5493..743df8a9 100644 --- a/src/conversions/num_bigint.rs +++ b/src/conversions/num_bigint.rs @@ -282,7 +282,7 @@ mod tests { let mut f0 = 1.to_object(py); let mut f1 = 1.to_object(py); std::iter::from_fn(move || { - let f2 = f0.call_method1(py, "__add__", (f1.as_ref(py),)).unwrap(); + let f2 = f0.call_method1(py, "__add__", (f1.bind(py),)).unwrap(); Some(std::mem::replace(&mut f0, std::mem::replace(&mut f1, f2))) }) } @@ -295,7 +295,7 @@ mod tests { // Python -> Rust assert_eq!(py_result.extract::(py).unwrap(), rs_result); // Rust -> Python - assert!(py_result.as_ref(py).eq(rs_result).unwrap()); + assert!(py_result.bind(py).eq(rs_result).unwrap()); } }); } @@ -308,7 +308,7 @@ mod tests { // Python -> Rust assert_eq!(py_result.extract::(py).unwrap(), rs_result); // Rust -> Python - assert!(py_result.as_ref(py).eq(&rs_result).unwrap()); + assert!(py_result.bind(py).eq(&rs_result).unwrap()); // negate @@ -318,7 +318,7 @@ mod tests { // Python -> Rust assert_eq!(py_result.extract::(py).unwrap(), rs_result); // Rust -> Python - assert!(py_result.as_ref(py).eq(rs_result).unwrap()); + assert!(py_result.bind(py).eq(rs_result).unwrap()); } }); } diff --git a/src/conversions/rust_decimal.rs b/src/conversions/rust_decimal.rs index 8bf2e337..b75cd875 100644 --- a/src/conversions/rust_decimal.rs +++ b/src/conversions/rust_decimal.rs @@ -54,9 +54,7 @@ use crate::sync::GILOnceCell; use crate::types::any::PyAnyMethods; use crate::types::string::PyStringMethods; use crate::types::PyType; -use crate::{ - intern, Bound, FromPyObject, IntoPy, Py, PyAny, PyObject, PyResult, Python, ToPyObject, -}; +use crate::{Bound, FromPyObject, IntoPy, Py, PyAny, PyObject, PyResult, Python, ToPyObject}; use rust_decimal::Decimal; use std::str::FromStr; @@ -74,14 +72,8 @@ impl FromPyObject<'_> for Decimal { static DECIMAL_CLS: GILOnceCell> = GILOnceCell::new(); -fn get_decimal_cls(py: Python<'_>) -> PyResult<&PyType> { - DECIMAL_CLS - .get_or_try_init(py, || { - py.import_bound(intern!(py, "decimal"))? - .getattr(intern!(py, "Decimal"))? - .extract() - }) - .map(|ty| ty.as_ref(py)) +fn get_decimal_cls(py: Python<'_>) -> PyResult<&Bound<'_, PyType>> { + DECIMAL_CLS.get_or_try_init_type_ref(py, "decimal", "Decimal") } impl ToPyObject for Decimal {