11use super :: {
22 set:: PySetInner , IterStatus , PositionIterInternal , PyBaseExceptionRef , PyGenericAlias ,
3- PyMappingProxy , PySet , PyStrRef , PyTupleRef , PyType , PyTypeRef ,
3+ PyMappingProxy , PySet , PyStr , PyTupleRef , PyType , PyTypeRef ,
44} ;
55use crate :: {
66 atomic_func,
@@ -11,7 +11,6 @@ use crate::{
1111 } ,
1212 class:: { PyClassDef , PyClassImpl } ,
1313 common:: ascii,
14- convert:: ToPyObject ,
1514 dictdatatype:: { self , DictKey } ,
1615 function:: {
1716 ArgIterable , FuncArgs , KwArgs , OptionalArg , PyArithmeticValue :: * , PyComparisonValue ,
@@ -24,7 +23,8 @@ use crate::{
2423 IterNextIterable , Iterable , PyComparisonOp , Unconstructible , Unhashable ,
2524 } ,
2625 vm:: VirtualMachine ,
27- AsObject , Context , Py , PyObject , PyObjectRef , PyPayload , PyRef , PyResult , TryFromObject ,
26+ AsObject , Context , Py , PyObject , PyObjectRef , PyPayload , PyRef , PyRefExact , PyResult ,
27+ TryFromObject ,
2828} ;
2929use once_cell:: sync:: Lazy ;
3030use rustpython_common:: lock:: PyMutex ;
@@ -65,8 +65,9 @@ impl PyDict {
6565
6666 // Used in update and ior.
6767 pub ( crate ) fn merge_object ( & self , other : PyObjectRef , vm : & VirtualMachine ) -> PyResult < ( ) > {
68- let other = match other. downcast_exact ( vm) {
69- Ok ( dict_other) => return self . merge_dict ( dict_other, vm) ,
68+ let casted: Result < PyRefExact < PyDict > , _ > = other. downcast_exact ( vm) ;
69+ let other = match casted {
70+ Ok ( dict_other) => return self . merge_dict ( dict_other. into_pyref ( ) , vm) ,
7071 Err ( other) => other,
7172 } ;
7273 let dict = & self . entries ;
@@ -227,7 +228,7 @@ impl PyDict {
227228 for key in iterable. iter ( vm) ? {
228229 pydict. setitem ( key?, value. clone ( ) , vm) ?;
229230 }
230- Ok ( pydict. to_pyobject ( vm ) )
231+ Ok ( pydict. into_pyref ( ) . into ( ) )
231232 }
232233 Err ( pyobj) => {
233234 for key in iterable. iter ( vm) ? {
@@ -533,9 +534,8 @@ impl Py<PyDict> {
533534 pub fn to_attributes ( & self , vm : & VirtualMachine ) -> PyAttributes {
534535 let mut attrs = PyAttributes :: default ( ) ;
535536 for ( key, value) in self {
536- // TODO: use PyRefExact for interning
537- let key: PyStrRef = key. downcast ( ) . expect ( "dict has non-string keys" ) ;
538- attrs. insert ( vm. ctx . intern_str ( key. as_str ( ) ) , value) ;
537+ let key: PyRefExact < PyStr > = key. downcast_exact ( vm) . expect ( "dict has non-string keys" ) ;
538+ attrs. insert ( vm. ctx . intern_str ( key) , value) ;
539539 }
540540 attrs
541541 }
0 commit comments