Skip to content

Commit 4f7c706

Browse files
adamreicholddavidhewitt
authored andcommitted
Suppress non_local_definitions lint as we often want the non-local effects in macro code (#4074)
* Resolve references to legacy numerical constants and use the associated constants instead * Suppress non_local_definitions lint as we often want the non-local effects in macro code
1 parent 3f6faf0 commit 4f7c706

File tree

10 files changed

+25
-24
lines changed

10 files changed

+25
-24
lines changed

pyo3-ffi/src/pyport.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ pub type Py_ssize_t = ::libc::ssize_t;
1111
pub type Py_hash_t = Py_ssize_t;
1212
pub type Py_uhash_t = ::libc::size_t;
1313

14-
pub const PY_SSIZE_T_MIN: Py_ssize_t = std::isize::MIN as Py_ssize_t;
15-
pub const PY_SSIZE_T_MAX: Py_ssize_t = std::isize::MAX as Py_ssize_t;
14+
pub const PY_SSIZE_T_MIN: Py_ssize_t = isize::MIN as Py_ssize_t;
15+
pub const PY_SSIZE_T_MAX: Py_ssize_t = isize::MAX as Py_ssize_t;
1616

1717
#[cfg(target_endian = "big")]
1818
pub const PY_BIG_ENDIAN: usize = 1;

pyo3-macros-backend/src/module.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ pub fn pymodule_module_impl(mut module: syn::ItemMod) -> Result<TokenStream> {
249249

250250
#initialization
251251

252+
#[allow(unknown_lints, non_local_definitions)]
252253
impl MakeDef {
253254
const fn make_def() -> #pyo3_path::impl_::pymodule::ModuleDef {
254255
use #pyo3_path::impl_::pymodule as impl_;
@@ -333,6 +334,7 @@ pub fn pymodule_function_impl(mut function: syn::ItemFn) -> Result<TokenStream>
333334
// this avoids complications around the fact that the generated module has a different scope
334335
// (and `super` doesn't always refer to the outer scope, e.g. if the `#[pymodule] is
335336
// inside a function body)
337+
#[allow(unknown_lints, non_local_definitions)]
336338
impl #ident::MakeDef {
337339
const fn make_def() -> #pyo3_path::impl_::pymodule::ModuleDef {
338340
fn __pyo3_pymodule(module: &#pyo3_path::Bound<'_, #pyo3_path::types::PyModule>) -> #pyo3_path::PyResult<()> {

pyo3-macros-backend/src/pyfunction.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ pub fn impl_wrap_pyfunction(
273273
// this avoids complications around the fact that the generated module has a different scope
274274
// (and `super` doesn't always refer to the outer scope, e.g. if the `#[pyfunction] is
275275
// inside a function body)
276+
#[allow(unknown_lints, non_local_definitions)]
276277
impl #name::MakeDef {
277278
const _PYO3_DEF: #pyo3_path::impl_::pymethods::PyMethodDef = #methoddef;
278279
}

pyo3-macros-backend/src/pymethod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ pub fn impl_py_method_def_new(
366366
#deprecations
367367

368368
use #pyo3_path::impl_::pyclass::*;
369+
#[allow(unknown_lints, non_local_definitions)]
369370
impl PyClassNewTextSignature<#cls> for PyClassImplCollector<#cls> {
370371
#[inline]
371372
fn new_text_signature(self) -> ::std::option::Option<&'static str> {

src/callback.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use crate::err::{PyErr, PyResult};
44
use crate::exceptions::PyOverflowError;
55
use crate::ffi::{self, Py_hash_t};
66
use crate::{IntoPy, PyObject, Python};
7-
use std::isize;
87
use std::os::raw::c_int;
98

109
/// A type which can be the return type of a python C-API callback
@@ -85,11 +84,7 @@ impl IntoPyCallbackOutput<()> for () {
8584
impl IntoPyCallbackOutput<ffi::Py_ssize_t> for usize {
8685
#[inline]
8786
fn convert(self, _py: Python<'_>) -> PyResult<ffi::Py_ssize_t> {
88-
if self <= (isize::MAX as usize) {
89-
Ok(self as isize)
90-
} else {
91-
Err(PyOverflowError::new_err(()))
92-
}
87+
self.try_into().map_err(|_err| PyOverflowError::new_err(()))
9388
}
9489
}
9590

src/conversions/std/num.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ mod test_128bit_integers {
445445
#[test]
446446
fn test_i128_max() {
447447
Python::with_gil(|py| {
448-
let v = std::i128::MAX;
448+
let v = i128::MAX;
449449
let obj = v.to_object(py);
450450
assert_eq!(v, obj.extract::<i128>(py).unwrap());
451451
assert_eq!(v as u128, obj.extract::<u128>(py).unwrap());
@@ -456,7 +456,7 @@ mod test_128bit_integers {
456456
#[test]
457457
fn test_i128_min() {
458458
Python::with_gil(|py| {
459-
let v = std::i128::MIN;
459+
let v = i128::MIN;
460460
let obj = v.to_object(py);
461461
assert_eq!(v, obj.extract::<i128>(py).unwrap());
462462
assert!(obj.extract::<i64>(py).is_err());
@@ -467,7 +467,7 @@ mod test_128bit_integers {
467467
#[test]
468468
fn test_u128_max() {
469469
Python::with_gil(|py| {
470-
let v = std::u128::MAX;
470+
let v = u128::MAX;
471471
let obj = v.to_object(py);
472472
assert_eq!(v, obj.extract::<u128>(py).unwrap());
473473
assert!(obj.extract::<i128>(py).is_err());
@@ -495,7 +495,7 @@ mod test_128bit_integers {
495495
#[test]
496496
fn test_nonzero_i128_max() {
497497
Python::with_gil(|py| {
498-
let v = NonZeroI128::new(std::i128::MAX).unwrap();
498+
let v = NonZeroI128::new(i128::MAX).unwrap();
499499
let obj = v.to_object(py);
500500
assert_eq!(v, obj.extract::<NonZeroI128>(py).unwrap());
501501
assert_eq!(
@@ -509,7 +509,7 @@ mod test_128bit_integers {
509509
#[test]
510510
fn test_nonzero_i128_min() {
511511
Python::with_gil(|py| {
512-
let v = NonZeroI128::new(std::i128::MIN).unwrap();
512+
let v = NonZeroI128::new(i128::MIN).unwrap();
513513
let obj = v.to_object(py);
514514
assert_eq!(v, obj.extract::<NonZeroI128>(py).unwrap());
515515
assert!(obj.extract::<NonZeroI64>(py).is_err());
@@ -520,7 +520,7 @@ mod test_128bit_integers {
520520
#[test]
521521
fn test_nonzero_u128_max() {
522522
Python::with_gil(|py| {
523-
let v = NonZeroU128::new(std::u128::MAX).unwrap();
523+
let v = NonZeroU128::new(u128::MAX).unwrap();
524524
let obj = v.to_object(py);
525525
assert_eq!(v, obj.extract::<NonZeroU128>(py).unwrap());
526526
assert!(obj.extract::<NonZeroI128>(py).is_err());
@@ -573,7 +573,7 @@ mod tests {
573573
#[test]
574574
fn test_u32_max() {
575575
Python::with_gil(|py| {
576-
let v = std::u32::MAX;
576+
let v = u32::MAX;
577577
let obj = v.to_object(py);
578578
assert_eq!(v, obj.extract::<u32>(py).unwrap());
579579
assert_eq!(u64::from(v), obj.extract::<u64>(py).unwrap());
@@ -584,7 +584,7 @@ mod tests {
584584
#[test]
585585
fn test_i64_max() {
586586
Python::with_gil(|py| {
587-
let v = std::i64::MAX;
587+
let v = i64::MAX;
588588
let obj = v.to_object(py);
589589
assert_eq!(v, obj.extract::<i64>(py).unwrap());
590590
assert_eq!(v as u64, obj.extract::<u64>(py).unwrap());
@@ -595,7 +595,7 @@ mod tests {
595595
#[test]
596596
fn test_i64_min() {
597597
Python::with_gil(|py| {
598-
let v = std::i64::MIN;
598+
let v = i64::MIN;
599599
let obj = v.to_object(py);
600600
assert_eq!(v, obj.extract::<i64>(py).unwrap());
601601
assert!(obj.extract::<i32>(py).is_err());
@@ -606,7 +606,7 @@ mod tests {
606606
#[test]
607607
fn test_u64_max() {
608608
Python::with_gil(|py| {
609-
let v = std::u64::MAX;
609+
let v = u64::MAX;
610610
let obj = v.to_object(py);
611611
assert_eq!(v, obj.extract::<u64>(py).unwrap());
612612
assert!(obj.extract::<i64>(py).is_err());
@@ -664,7 +664,7 @@ mod tests {
664664
#[test]
665665
fn test_nonzero_u32_max() {
666666
Python::with_gil(|py| {
667-
let v = NonZeroU32::new(std::u32::MAX).unwrap();
667+
let v = NonZeroU32::new(u32::MAX).unwrap();
668668
let obj = v.to_object(py);
669669
assert_eq!(v, obj.extract::<NonZeroU32>(py).unwrap());
670670
assert_eq!(NonZeroU64::from(v), obj.extract::<NonZeroU64>(py).unwrap());
@@ -675,7 +675,7 @@ mod tests {
675675
#[test]
676676
fn test_nonzero_i64_max() {
677677
Python::with_gil(|py| {
678-
let v = NonZeroI64::new(std::i64::MAX).unwrap();
678+
let v = NonZeroI64::new(i64::MAX).unwrap();
679679
let obj = v.to_object(py);
680680
assert_eq!(v, obj.extract::<NonZeroI64>(py).unwrap());
681681
assert_eq!(
@@ -689,7 +689,7 @@ mod tests {
689689
#[test]
690690
fn test_nonzero_i64_min() {
691691
Python::with_gil(|py| {
692-
let v = NonZeroI64::new(std::i64::MIN).unwrap();
692+
let v = NonZeroI64::new(i64::MIN).unwrap();
693693
let obj = v.to_object(py);
694694
assert_eq!(v, obj.extract::<NonZeroI64>(py).unwrap());
695695
assert!(obj.extract::<NonZeroI32>(py).is_err());
@@ -700,7 +700,7 @@ mod tests {
700700
#[test]
701701
fn test_nonzero_u64_max() {
702702
Python::with_gil(|py| {
703-
let v = NonZeroU64::new(std::u64::MAX).unwrap();
703+
let v = NonZeroU64::new(u64::MAX).unwrap();
704704
let obj = v.to_object(py);
705705
assert_eq!(v, obj.extract::<NonZeroU64>(py).unwrap());
706706
assert!(obj.extract::<NonZeroI64>(py).is_err());

src/impl_/pyclass.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,7 @@ slot_fragment_trait! {
852852
#[macro_export]
853853
macro_rules! generate_pyclass_richcompare_slot {
854854
($cls:ty) => {{
855+
#[allow(unknown_lints, non_local_definitions)]
855856
impl $cls {
856857
#[allow(non_snake_case)]
857858
unsafe extern "C" fn __pymethod___richcmp____(

src/pycell/impl_.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ struct BorrowFlag(usize);
5555

5656
impl BorrowFlag {
5757
pub(crate) const UNUSED: BorrowFlag = BorrowFlag(0);
58-
const HAS_MUTABLE_BORROW: BorrowFlag = BorrowFlag(usize::max_value());
58+
const HAS_MUTABLE_BORROW: BorrowFlag = BorrowFlag(usize::MAX);
5959
const fn increment(self) -> Self {
6060
Self(self.0 + 1)
6161
}

src/types/any.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2491,6 +2491,7 @@ class SimpleClass:
24912491

24922492
#[cfg(feature = "macros")]
24932493
#[test]
2494+
#[allow(unknown_lints, non_local_definitions)]
24942495
fn test_hasattr_error() {
24952496
use crate::exceptions::PyValueError;
24962497
use crate::prelude::*;

tests/test_proto_methods.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use pyo3::exceptions::{PyAttributeError, PyIndexError, PyValueError};
44
use pyo3::types::{PyDict, PyList, PyMapping, PySequence, PySlice, PyType};
55
use pyo3::{prelude::*, py_run};
6-
use std::{isize, iter};
6+
use std::iter;
77

88
#[path = "../src/tests/common.rs"]
99
mod common;

0 commit comments

Comments
 (0)