@@ -26,6 +26,7 @@ use crate::{
2626 vm:: VirtualMachine ,
2727 AsObject , Context , Py , PyObject , PyObjectRef , PyPayload , PyRef , PyResult , TryFromObject ,
2828} ;
29+ use once_cell:: sync:: Lazy ;
2930use rustpython_common:: lock:: PyMutex ;
3031use std:: fmt;
3132
@@ -465,12 +466,12 @@ impl AsMapping for PyDict {
465466
466467impl AsSequence for PyDict {
467468 fn as_sequence ( ) -> & ' static PySequenceMethods {
468- static AS_SEQUENCE : PySequenceMethods = PySequenceMethods {
469+ static AS_SEQUENCE : Lazy < PySequenceMethods > = Lazy :: new ( || PySequenceMethods {
469470 contains : atomic_func ! ( |seq, target, vm| PyDict :: sequence_downcast( seq)
470471 . entries
471472 . contains( vm, target) ) ,
472473 ..PySequenceMethods :: NOT_IMPLEMENTED
473- } ;
474+ } ) ;
474475 & AS_SEQUENCE
475476 }
476477}
@@ -1052,7 +1053,7 @@ impl Comparable for PyDictKeys {
10521053
10531054impl AsSequence for PyDictKeys {
10541055 fn as_sequence ( ) -> & ' static PySequenceMethods {
1055- static AS_SEQUENCE : PySequenceMethods = PySequenceMethods {
1056+ static AS_SEQUENCE : Lazy < PySequenceMethods > = Lazy :: new ( || PySequenceMethods {
10561057 length : atomic_func ! ( |seq, _vm| Ok ( PyDictKeys :: sequence_downcast( seq) . len( ) ) ) ,
10571058 contains : atomic_func ! ( |seq, target, vm| {
10581059 PyDictKeys :: sequence_downcast( seq)
@@ -1061,7 +1062,7 @@ impl AsSequence for PyDictKeys {
10611062 . contains( vm, target)
10621063 } ) ,
10631064 ..PySequenceMethods :: NOT_IMPLEMENTED
1064- } ;
1065+ } ) ;
10651066 & AS_SEQUENCE
10661067 }
10671068}
@@ -1108,7 +1109,7 @@ impl Comparable for PyDictItems {
11081109
11091110impl AsSequence for PyDictItems {
11101111 fn as_sequence ( ) -> & ' static PySequenceMethods {
1111- static AS_SEQUENCE : PySequenceMethods = PySequenceMethods {
1112+ static AS_SEQUENCE : Lazy < PySequenceMethods > = Lazy :: new ( || PySequenceMethods {
11121113 length : atomic_func ! ( |seq, _vm| Ok ( PyDictItems :: sequence_downcast( seq) . len( ) ) ) ,
11131114 contains : atomic_func ! ( |seq, target, vm| {
11141115 PyDictItems :: sequence_downcast( seq)
@@ -1117,7 +1118,7 @@ impl AsSequence for PyDictItems {
11171118 . contains( vm, target)
11181119 } ) ,
11191120 ..PySequenceMethods :: NOT_IMPLEMENTED
1120- } ;
1121+ } ) ;
11211122 & AS_SEQUENCE
11221123 }
11231124}
@@ -1133,10 +1134,10 @@ impl Unconstructible for PyDictValues {}
11331134
11341135impl AsSequence for PyDictValues {
11351136 fn as_sequence ( ) -> & ' static PySequenceMethods {
1136- static AS_SEQUENCE : PySequenceMethods = PySequenceMethods {
1137+ static AS_SEQUENCE : Lazy < PySequenceMethods > = Lazy :: new ( || PySequenceMethods {
11371138 length : atomic_func ! ( |seq, _vm| Ok ( PyDictValues :: sequence_downcast( seq) . len( ) ) ) ,
11381139 ..PySequenceMethods :: NOT_IMPLEMENTED
1139- } ;
1140+ } ) ;
11401141 & AS_SEQUENCE
11411142 }
11421143}
0 commit comments