@@ -173,12 +173,10 @@ pub trait PyTimeAccess {
173
173
/// Trait for accessing the components of a struct containing a tzinfo.
174
174
pub trait PyTzInfoAccess < ' py > {
175
175
/// Deprecated form of `get_tzinfo_bound`.
176
- #[ cfg_attr(
177
- not( feature = "gil-refs" ) ,
178
- deprecated(
179
- since = "0.21.0" ,
180
- note = "`get_tzinfo` will be replaced by `get_tzinfo_bound` in a future PyO3 version"
181
- )
176
+ #[ cfg( feature = "gil-refs" ) ]
177
+ #[ deprecated(
178
+ since = "0.21.0" ,
179
+ note = "`get_tzinfo` will be replaced by `get_tzinfo_bound` in a future PyO3 version"
182
180
) ]
183
181
fn get_tzinfo ( & self ) -> Option < & ' py PyTzInfo > {
184
182
self . get_tzinfo_bound ( ) . map ( Bound :: into_gil_ref)
@@ -205,12 +203,10 @@ pyobject_native_type!(
205
203
206
204
impl PyDate {
207
205
/// Deprecated form of [`PyDate::new_bound`].
208
- #[ cfg_attr(
209
- not( feature = "gil-refs" ) ,
210
- deprecated(
211
- since = "0.21.0" ,
212
- note = "`PyDate::new` will be replaced by `PyDate::new_bound` in a future PyO3 version"
213
- )
206
+ #[ cfg( feature = "gil-refs" ) ]
207
+ #[ deprecated(
208
+ since = "0.21.0" ,
209
+ note = "`PyDate::new` will be replaced by `PyDate::new_bound` in a future PyO3 version"
214
210
) ]
215
211
pub fn new ( py : Python < ' _ > , year : i32 , month : u8 , day : u8 ) -> PyResult < & PyDate > {
216
212
Self :: new_bound ( py, year, month, day) . map ( Bound :: into_gil_ref)
@@ -227,12 +223,10 @@ impl PyDate {
227
223
}
228
224
229
225
/// Deprecated form of [`PyDate::from_timestamp_bound`].
230
- #[ cfg_attr(
231
- not( feature = "gil-refs" ) ,
232
- deprecated(
233
- since = "0.21.0" ,
234
- note = "`PyDate::from_timestamp` will be replaced by `PyDate::from_timestamp_bound` in a future PyO3 version"
235
- )
226
+ #[ cfg( feature = "gil-refs" ) ]
227
+ #[ deprecated(
228
+ since = "0.21.0" ,
229
+ note = "`PyDate::from_timestamp` will be replaced by `PyDate::from_timestamp_bound` in a future PyO3 version"
236
230
) ]
237
231
pub fn from_timestamp ( py : Python < ' _ > , timestamp : i64 ) -> PyResult < & PyDate > {
238
232
Self :: from_timestamp_bound ( py, timestamp) . map ( Bound :: into_gil_ref)
@@ -296,12 +290,10 @@ pyobject_native_type!(
296
290
297
291
impl PyDateTime {
298
292
/// Deprecated form of [`PyDateTime::new_bound`].
299
- #[ cfg_attr(
300
- not( feature = "gil-refs" ) ,
301
- deprecated(
302
- since = "0.21.0" ,
303
- note = "`PyDateTime::new` will be replaced by `PyDateTime::new_bound` in a future PyO3 version"
304
- )
293
+ #[ cfg( feature = "gil-refs" ) ]
294
+ #[ deprecated(
295
+ since = "0.21.0" ,
296
+ note = "`PyDateTime::new` will be replaced by `PyDateTime::new_bound` in a future PyO3 version"
305
297
) ]
306
298
#[ allow( clippy:: too_many_arguments) ]
307
299
pub fn new < ' py > (
@@ -361,12 +353,10 @@ impl PyDateTime {
361
353
}
362
354
363
355
/// Deprecated form of [`PyDateTime::new_bound_with_fold`].
364
- #[ cfg_attr(
365
- not( feature = "gil-refs" ) ,
366
- deprecated(
367
- since = "0.21.0" ,
368
- note = "`PyDateTime::new_with_fold` will be replaced by `PyDateTime::new_bound_with_fold` in a future PyO3 version"
369
- )
356
+ #[ cfg( feature = "gil-refs" ) ]
357
+ #[ deprecated(
358
+ since = "0.21.0" ,
359
+ note = "`PyDateTime::new_with_fold` will be replaced by `PyDateTime::new_bound_with_fold` in a future PyO3 version"
370
360
) ]
371
361
#[ allow( clippy:: too_many_arguments) ]
372
362
pub fn new_with_fold < ' py > (
@@ -436,12 +426,10 @@ impl PyDateTime {
436
426
}
437
427
438
428
/// Deprecated form of [`PyDateTime::from_timestamp_bound`].
439
- #[ cfg_attr(
440
- not( feature = "gil-refs" ) ,
441
- deprecated(
442
- since = "0.21.0" ,
443
- note = "`PyDateTime::from_timestamp` will be replaced by `PyDateTime::from_timestamp_bound` in a future PyO3 version"
444
- )
429
+ #[ cfg( feature = "gil-refs" ) ]
430
+ #[ deprecated(
431
+ since = "0.21.0" ,
432
+ note = "`PyDateTime::from_timestamp` will be replaced by `PyDateTime::from_timestamp_bound` in a future PyO3 version"
445
433
) ]
446
434
pub fn from_timestamp < ' py > (
447
435
py : Python < ' py > ,
@@ -598,12 +586,10 @@ pyobject_native_type!(
598
586
599
587
impl PyTime {
600
588
/// Deprecated form of [`PyTime::new_bound`].
601
- #[ cfg_attr(
602
- not( feature = "gil-refs" ) ,
603
- deprecated(
604
- since = "0.21.0" ,
605
- note = "`PyTime::new` will be replaced by `PyTime::new_bound` in a future PyO3 version"
606
- )
589
+ #[ cfg( feature = "gil-refs" ) ]
590
+ #[ deprecated(
591
+ since = "0.21.0" ,
592
+ note = "`PyTime::new` will be replaced by `PyTime::new_bound` in a future PyO3 version"
607
593
) ]
608
594
pub fn new < ' py > (
609
595
py : Python < ' py > ,
@@ -649,12 +635,10 @@ impl PyTime {
649
635
}
650
636
651
637
/// Deprecated form of [`PyTime::new_bound_with_fold`].
652
- #[ cfg_attr(
653
- not( feature = "gil-refs" ) ,
654
- deprecated(
655
- since = "0.21.0" ,
656
- note = "`PyTime::new_with_fold` will be replaced by `PyTime::new_bound_with_fold` in a future PyO3 version"
657
- )
638
+ #[ cfg( feature = "gil-refs" ) ]
639
+ #[ deprecated(
640
+ since = "0.21.0" ,
641
+ note = "`PyTime::new_with_fold` will be replaced by `PyTime::new_bound_with_fold` in a future PyO3 version"
658
642
) ]
659
643
pub fn new_with_fold < ' py > (
660
644
py : Python < ' py > ,
@@ -804,12 +788,10 @@ pyobject_native_type!(
804
788
) ;
805
789
806
790
/// Deprecated form of [`timezone_utc_bound`].
807
- #[ cfg_attr(
808
- not( feature = "gil-refs" ) ,
809
- deprecated(
810
- since = "0.21.0" ,
811
- note = "`timezone_utc` will be replaced by `timezone_utc_bound` in a future PyO3 version"
812
- )
791
+ #[ cfg( feature = "gil-refs" ) ]
792
+ #[ deprecated(
793
+ since = "0.21.0" ,
794
+ note = "`timezone_utc` will be replaced by `timezone_utc_bound` in a future PyO3 version"
813
795
) ]
814
796
pub fn timezone_utc ( py : Python < ' _ > ) -> & PyTzInfo {
815
797
timezone_utc_bound ( py) . into_gil_ref ( )
@@ -858,12 +840,10 @@ pyobject_native_type!(
858
840
859
841
impl PyDelta {
860
842
/// Deprecated form of [`PyDelta::new_bound`].
861
- #[ cfg_attr(
862
- not( feature = "gil-refs" ) ,
863
- deprecated(
864
- since = "0.21.0" ,
865
- note = "`PyDelta::new` will be replaced by `PyDelta::new_bound` in a future PyO3 version"
866
- )
843
+ #[ cfg( feature = "gil-refs" ) ]
844
+ #[ deprecated(
845
+ since = "0.21.0" ,
846
+ note = "`PyDelta::new` will be replaced by `PyDelta::new_bound` in a future PyO3 version"
867
847
) ]
868
848
pub fn new (
869
849
py : Python < ' _ > ,
@@ -936,7 +916,6 @@ fn opt_to_pyobj(opt: Option<&Bound<'_, PyTzInfo>>) -> *mut ffi::PyObject {
936
916
}
937
917
938
918
#[ cfg( test) ]
939
- #[ cfg_attr( not( feature = "gil-refs" ) , allow( deprecated) ) ]
940
919
mod tests {
941
920
use super :: * ;
942
921
#[ cfg( feature = "macros" ) ]
@@ -947,14 +926,15 @@ mod tests {
947
926
#[ cfg_attr( target_arch = "wasm32" , ignore) ] // DateTime import fails on wasm for mysterious reasons
948
927
fn test_datetime_fromtimestamp ( ) {
949
928
Python :: with_gil ( |py| {
950
- let dt = PyDateTime :: from_timestamp ( py, 100.0 , None ) . unwrap ( ) ;
929
+ let dt = PyDateTime :: from_timestamp_bound ( py, 100.0 , None ) . unwrap ( ) ;
951
930
py_run ! (
952
931
py,
953
932
dt,
954
933
"import datetime; assert dt == datetime.datetime.fromtimestamp(100)"
955
934
) ;
956
935
957
- let dt = PyDateTime :: from_timestamp ( py, 100.0 , Some ( timezone_utc ( py) ) ) . unwrap ( ) ;
936
+ let dt =
937
+ PyDateTime :: from_timestamp_bound ( py, 100.0 , Some ( & timezone_utc_bound ( py) ) ) . unwrap ( ) ;
958
938
py_run ! (
959
939
py,
960
940
dt,
@@ -968,7 +948,7 @@ mod tests {
968
948
#[ cfg_attr( target_arch = "wasm32" , ignore) ] // DateTime import fails on wasm for mysterious reasons
969
949
fn test_date_fromtimestamp ( ) {
970
950
Python :: with_gil ( |py| {
971
- let dt = PyDate :: from_timestamp ( py, 100 ) . unwrap ( ) ;
951
+ let dt = PyDate :: from_timestamp_bound ( py, 100 ) . unwrap ( ) ;
972
952
py_run ! (
973
953
py,
974
954
dt,
@@ -981,8 +961,10 @@ mod tests {
981
961
#[ cfg_attr( target_arch = "wasm32" , ignore) ] // DateTime import fails on wasm for mysterious reasons
982
962
fn test_new_with_fold ( ) {
983
963
Python :: with_gil ( |py| {
984
- let a = PyDateTime :: new_with_fold ( py, 2021 , 1 , 23 , 20 , 32 , 40 , 341516 , None , false ) ;
985
- let b = PyDateTime :: new_with_fold ( py, 2021 , 1 , 23 , 20 , 32 , 40 , 341516 , None , true ) ;
964
+ let a =
965
+ PyDateTime :: new_bound_with_fold ( py, 2021 , 1 , 23 , 20 , 32 , 40 , 341516 , None , false ) ;
966
+ let b =
967
+ PyDateTime :: new_bound_with_fold ( py, 2021 , 1 , 23 , 20 , 32 , 40 , 341516 , None , true ) ;
986
968
987
969
assert ! ( !a. unwrap( ) . get_fold( ) ) ;
988
970
assert ! ( b. unwrap( ) . get_fold( ) ) ;
@@ -991,26 +973,25 @@ mod tests {
991
973
992
974
#[ test]
993
975
#[ cfg_attr( target_arch = "wasm32" , ignore) ] // DateTime import fails on wasm for mysterious reasons
994
- #[ cfg_attr( not( feature = "gil-refs" ) , allow( deprecated) ) ]
995
976
fn test_get_tzinfo ( ) {
996
977
crate :: Python :: with_gil ( |py| {
997
- let utc = timezone_utc ( py) ;
978
+ let utc = timezone_utc_bound ( py) ;
998
979
999
- let dt = PyDateTime :: new ( py, 2018 , 1 , 1 , 0 , 0 , 0 , 0 , Some ( utc) ) . unwrap ( ) ;
980
+ let dt = PyDateTime :: new_bound ( py, 2018 , 1 , 1 , 0 , 0 , 0 , 0 , Some ( & utc) ) . unwrap ( ) ;
1000
981
1001
- assert ! ( dt. get_tzinfo ( ) . unwrap( ) . eq( utc) . unwrap( ) ) ;
982
+ assert ! ( dt. get_tzinfo_bound ( ) . unwrap( ) . eq( & utc) . unwrap( ) ) ;
1002
983
1003
- let dt = PyDateTime :: new ( py, 2018 , 1 , 1 , 0 , 0 , 0 , 0 , None ) . unwrap ( ) ;
984
+ let dt = PyDateTime :: new_bound ( py, 2018 , 1 , 1 , 0 , 0 , 0 , 0 , None ) . unwrap ( ) ;
1004
985
1005
- assert ! ( dt. get_tzinfo ( ) . is_none( ) ) ;
986
+ assert ! ( dt. get_tzinfo_bound ( ) . is_none( ) ) ;
1006
987
1007
- let t = PyTime :: new ( py, 0 , 0 , 0 , 0 , Some ( utc) ) . unwrap ( ) ;
988
+ let t = PyTime :: new_bound ( py, 0 , 0 , 0 , 0 , Some ( & utc) ) . unwrap ( ) ;
1008
989
1009
- assert ! ( t. get_tzinfo ( ) . unwrap( ) . eq( utc) . unwrap( ) ) ;
990
+ assert ! ( t. get_tzinfo_bound ( ) . unwrap( ) . eq( utc) . unwrap( ) ) ;
1010
991
1011
- let t = PyTime :: new ( py, 0 , 0 , 0 , 0 , None ) . unwrap ( ) ;
992
+ let t = PyTime :: new_bound ( py, 0 , 0 , 0 , 0 , None ) . unwrap ( ) ;
1012
993
1013
- assert ! ( t. get_tzinfo ( ) . is_none( ) ) ;
994
+ assert ! ( t. get_tzinfo_bound ( ) . is_none( ) ) ;
1014
995
} ) ;
1015
996
}
1016
997
@@ -1024,9 +1005,9 @@ mod tests {
1024
1005
. unwrap( )
1025
1006
. call_method1( "utcoffset" , ( ( ) , ) )
1026
1007
. unwrap( )
1027
- . extract :: <& PyDelta >( )
1008
+ . downcast_into :: <PyDelta >( )
1028
1009
. unwrap( )
1029
- . eq( PyDelta :: new ( py, 0 , -3600 , 0 , true ) . unwrap( ) )
1010
+ . eq( PyDelta :: new_bound ( py, 0 , -3600 , 0 , true ) . unwrap( ) )
1030
1011
. unwrap( )
1031
1012
) ;
1032
1013
@@ -1035,9 +1016,9 @@ mod tests {
1035
1016
. unwrap( )
1036
1017
. call_method1( "utcoffset" , ( ( ) , ) )
1037
1018
. unwrap( )
1038
- . extract :: <& PyDelta >( )
1019
+ . downcast_into :: <PyDelta >( )
1039
1020
. unwrap( )
1040
- . eq( PyDelta :: new ( py, 0 , 3600 , 0 , true ) . unwrap( ) )
1021
+ . eq( PyDelta :: new_bound ( py, 0 , 3600 , 0 , true ) . unwrap( ) )
1041
1022
. unwrap( )
1042
1023
) ;
1043
1024
0 commit comments