@@ -10,7 +10,7 @@ use crate::common::{
1010use crate :: {
1111 builtins:: { PyInt , PyStr , PyStrRef } ,
1212 convert:: ToPyObject ,
13- AsObject , PyObject , PyObjectRef , PyRefExact , PyResult , VirtualMachine ,
13+ AsObject , Py , PyObject , PyObjectRef , PyRefExact , PyResult , VirtualMachine ,
1414} ;
1515use num_traits:: ToPrimitive ;
1616use std:: { fmt, mem:: size_of, ops:: ControlFlow } ;
@@ -735,6 +735,30 @@ impl DictKey for PyObject {
735735 }
736736}
737737
738+ impl DictKey for Py < PyStr > {
739+ fn key_hash ( & self , vm : & VirtualMachine ) -> PyResult < HashValue > {
740+ Ok ( self . hash ( vm) )
741+ }
742+
743+ fn key_is ( & self , other : & PyObject ) -> bool {
744+ self . is ( other)
745+ }
746+
747+ fn key_eq ( & self , vm : & VirtualMachine , other_key : & PyObject ) -> PyResult < bool > {
748+ if self . is ( other_key) {
749+ Ok ( true )
750+ } else if let Some ( pystr) = str_exact ( other_key, vm) {
751+ Ok ( pystr. as_str ( ) == self . as_str ( ) )
752+ } else {
753+ vm. bool_eq ( self . as_object ( ) , other_key)
754+ }
755+ }
756+
757+ fn key_as_isize ( & self , vm : & VirtualMachine ) -> PyResult < isize > {
758+ self . as_object ( ) . key_as_isize ( vm)
759+ }
760+ }
761+
738762impl DictKey for PyStrRef {
739763 fn key_hash ( & self , vm : & VirtualMachine ) -> PyResult < HashValue > {
740764 Ok ( self . hash ( vm) )
0 commit comments