44
44
use crate :: conversion:: IntoPyObject ;
45
45
use crate :: exceptions:: { PyTypeError , PyUserWarning , PyValueError } ;
46
46
#[ cfg( Py_LIMITED_API ) ]
47
- use crate :: sync :: GILOnceCell ;
47
+ use crate :: intern ;
48
48
use crate :: types:: any:: PyAnyMethods ;
49
49
#[ cfg( not( Py_LIMITED_API ) ) ]
50
50
use crate :: types:: datetime:: timezone_from_offset;
51
51
#[ cfg( Py_LIMITED_API ) ]
52
+ use crate :: types:: datetime_abi:: { check_type, timezone_utc, DatetimeTypes } ;
53
+ #[ cfg( Py_LIMITED_API ) ]
52
54
use crate :: types:: IntoPyDict ;
53
55
use crate :: types:: PyNone ;
54
56
#[ cfg( not( Py_LIMITED_API ) ) ]
@@ -57,8 +59,6 @@ use crate::types::{
57
59
PyTzInfo , PyTzInfoAccess ,
58
60
} ;
59
61
use crate :: { ffi, Bound , FromPyObject , IntoPyObjectExt , PyAny , PyErr , PyObject , PyResult , Python } ;
60
- #[ cfg( Py_LIMITED_API ) ]
61
- use crate :: { intern, DowncastError } ;
62
62
#[ allow( deprecated) ]
63
63
use crate :: { IntoPy , ToPyObject } ;
64
64
use chrono:: offset:: { FixedOffset , Utc } ;
@@ -811,54 +811,6 @@ fn py_time_to_naive_time(py_time: &Bound<'_, PyAny>) -> PyResult<NaiveTime> {
811
811
. ok_or_else ( || PyValueError :: new_err ( "invalid or out-of-range time" ) )
812
812
}
813
813
814
- #[ cfg( Py_LIMITED_API ) ]
815
- fn check_type ( value : & Bound < ' _ , PyAny > , t : & PyObject , type_name : & ' static str ) -> PyResult < ( ) > {
816
- if !value. is_instance ( t. bind ( value. py ( ) ) ) ? {
817
- return Err ( DowncastError :: new ( value, type_name) . into ( ) ) ;
818
- }
819
- Ok ( ( ) )
820
- }
821
-
822
- #[ cfg( Py_LIMITED_API ) ]
823
- struct DatetimeTypes {
824
- date : PyObject ,
825
- datetime : PyObject ,
826
- time : PyObject ,
827
- timedelta : PyObject ,
828
- timezone : PyObject ,
829
- timezone_utc : PyObject ,
830
- tzinfo : PyObject ,
831
- }
832
-
833
- #[ cfg( Py_LIMITED_API ) ]
834
- impl DatetimeTypes {
835
- fn get ( py : Python < ' _ > ) -> & Self {
836
- Self :: try_get ( py) . expect ( "failed to load datetime module" )
837
- }
838
-
839
- fn try_get ( py : Python < ' _ > ) -> PyResult < & Self > {
840
- static TYPES : GILOnceCell < DatetimeTypes > = GILOnceCell :: new ( ) ;
841
- TYPES . get_or_try_init ( py, || {
842
- let datetime = py. import ( "datetime" ) ?;
843
- let timezone = datetime. getattr ( "timezone" ) ?;
844
- Ok :: < _ , PyErr > ( Self {
845
- date : datetime. getattr ( "date" ) ?. into ( ) ,
846
- datetime : datetime. getattr ( "datetime" ) ?. into ( ) ,
847
- time : datetime. getattr ( "time" ) ?. into ( ) ,
848
- timedelta : datetime. getattr ( "timedelta" ) ?. into ( ) ,
849
- timezone_utc : timezone. getattr ( "utc" ) ?. into ( ) ,
850
- timezone : timezone. into ( ) ,
851
- tzinfo : datetime. getattr ( "tzinfo" ) ?. into ( ) ,
852
- } )
853
- } )
854
- }
855
- }
856
-
857
- #[ cfg( Py_LIMITED_API ) ]
858
- fn timezone_utc ( py : Python < ' _ > ) -> Bound < ' _ , PyAny > {
859
- DatetimeTypes :: get ( py) . timezone_utc . bind ( py) . clone ( )
860
- }
861
-
862
814
#[ cfg( test) ]
863
815
mod tests {
864
816
use super :: * ;
0 commit comments