@@ -247,7 +247,7 @@ def test_integer_casting():
247247 assert "incompatible function arguments" in str (excinfo .value )
248248
249249
250- def test_int_convert (doc ):
250+ def test_int_convert (doc , avoid_PyLong_AsLong_deprecation ):
251251 class Int :
252252 def __int__ (self ):
253253 return 42
@@ -300,15 +300,9 @@ def cant_convert(v):
300300
301301 assert convert (7 ) == 7
302302 assert noconvert (7 ) == 7
303- assert convert ( 3.14159 ) == 3
303+ assert avoid_PyLong_AsLong_deprecation ( convert , 3.14159 , 3 )
304304 requires_conversion (3.14159 )
305- # TODO: Avoid DeprecationWarning in `PyLong_AsLong` (and similar)
306- # TODO: PyPy 3.8 does not behave like CPython 3.8 here yet (7.3.7)
307- if sys .version_info < (3 , 10 ) and env .CPYTHON :
308- with env .deprecated_call ():
309- assert convert (Int ()) == 42
310- else :
311- assert convert (Int ()) == 42
305+ assert avoid_PyLong_AsLong_deprecation (convert , Int (), 42 )
312306 requires_conversion (Int ())
313307 cant_convert (NotInt ())
314308 cant_convert (Float ())
@@ -326,7 +320,7 @@ def cant_convert(v):
326320 requires_conversion (RaisingValueErrorOnIndex ())
327321
328322
329- def test_float_convert (doc ):
323+ def test_float_convert (doc , avoid_PyLong_AsLong_deprecation ):
330324 class Int :
331325 def __int__ (self ):
332326 return - 5
@@ -357,12 +351,12 @@ def cant_convert(v):
357351 assert pytest .approx (convert (Float ())) == 41.45
358352 assert pytest .approx (convert (Index ())) == - 7.0
359353 assert isinstance (convert (Float ()), float )
360- assert pytest . approx (convert ( 3 )) == 3.0
354+ assert avoid_PyLong_AsLong_deprecation (convert , 3 , 3.0 )
361355 assert pytest .approx (noconvert (3 )) == 3.0
362356 cant_convert (Int ())
363357
364358
365- def test_numpy_int_convert ():
359+ def test_numpy_int_convert (avoid_PyLong_AsLong_deprecation ):
366360 np = pytest .importorskip ("numpy" )
367361
368362 convert , noconvert = m .int_passthrough , m .int_passthrough_noconvert
@@ -375,14 +369,7 @@ def require_implicit(v):
375369 assert noconvert (np .intc (42 )) == 42
376370
377371 # The implicit conversion from np.float32 is undesirable but currently accepted.
378- # TODO: Avoid DeprecationWarning in `PyLong_AsLong` (and similar)
379- # TODO: PyPy 3.8 does not behave like CPython 3.8 here yet (7.3.7)
380- # https://github.com/pybind/pybind11/issues/3408
381- if (3 , 8 ) <= sys .version_info < (3 , 10 ) and env .CPYTHON :
382- with env .deprecated_call ():
383- assert convert (np .float32 (3.14159 )) == 3
384- else :
385- assert convert (np .float32 (3.14159 )) == 3
372+ assert avoid_PyLong_AsLong_deprecation (convert , np .float32 (3.14159 ), 3 )
386373 require_implicit (np .float32 (3.14159 ))
387374
388375
@@ -483,7 +470,7 @@ def test_reference_wrapper():
483470 assert m .refwrap_call_iiw (IncType (10 ), m .refwrap_iiw ) == [10 , 10 , 10 , 10 ]
484471
485472
486- def test_complex_cast (doc ):
473+ def test_complex_cast (doc , avoid_PyLong_AsLong_deprecation ):
487474 """std::complex casts"""
488475
489476 class Complex :
@@ -526,8 +513,8 @@ def cant_convert(v):
526513 )
527514 assert doc (noconvert ) == "complex_noconvert(arg0: complex) -> complex"
528515
529- assert convert ( 1 ) == 1.0
530- assert convert ( 2.0 ) == 2.0
516+ assert avoid_PyLong_AsLong_deprecation ( convert , 1 , 1.0 )
517+ assert avoid_PyLong_AsLong_deprecation ( convert , 2.0 , 2.0 )
531518 assert convert (1 + 5j ) == 1.0 + 5.0j
532519 assert convert (Complex ()) == 5.0 + 4j
533520 assert convert (Float ()) == 5.0
0 commit comments