@@ -31,7 +31,7 @@ pub(crate) fn make_module(vm: &VirtualMachine) -> PyRef<PyModule> {
3131pub ( crate ) mod decl {
3232 use crate :: {
3333 Py , PyObjectRef , PyPayload , PyResult , VirtualMachine ,
34- builtins:: { PyTupleRef , PyTypeRef , pystr:: AsPyStr } ,
34+ builtins:: { PyStrRef , PyTupleRef , PyTypeRef , pystr:: AsPyStr } ,
3535 function:: { FuncArgs , IntoFuncArgs } ,
3636 types:: { Constructor , Representable } ,
3737 } ;
@@ -98,15 +98,15 @@ pub(crate) mod decl {
9898 #[ derive( Debug , PyPayload ) ]
9999 #[ allow( dead_code) ]
100100 pub ( crate ) struct TypeAliasType {
101- name : PyObjectRef , // TODO PyStrRef?
101+ name : PyStrRef ,
102102 type_params : PyTupleRef ,
103103 value : PyObjectRef ,
104104 // compute_value: PyObjectRef,
105105 // module: PyObjectRef,
106106 }
107107 #[ pyclass( with( Constructor , Representable ) , flags( BASETYPE ) ) ]
108108 impl TypeAliasType {
109- pub const fn new ( name : PyObjectRef , type_params : PyTupleRef , value : PyObjectRef ) -> Self {
109+ pub const fn new ( name : PyStrRef , type_params : PyTupleRef , value : PyObjectRef ) -> Self {
110110 Self {
111111 name,
112112 type_params,
@@ -116,7 +116,7 @@ pub(crate) mod decl {
116116
117117 #[ pygetset]
118118 fn __name__ ( & self ) -> PyObjectRef {
119- self . name . clone ( )
119+ self . name . clone ( ) . into ( )
120120 }
121121
122122 #[ pygetset]
@@ -154,7 +154,9 @@ pub(crate) mod decl {
154154 ) ) ) ;
155155 }
156156
157- let name = args. args [ 0 ] . clone ( ) ;
157+ let name = args. args [ 0 ] . clone ( ) . downcast :: < crate :: builtins:: PyStr > ( ) . map_err ( |_| {
158+ vm. new_type_error ( "TypeAliasType name must be a string" . to_owned ( ) )
159+ } ) ?;
158160 let value = args. args [ 1 ] . clone ( ) ;
159161
160162 let type_params = if let Some ( tp) = args. kwargs . get ( "type_params" ) {
@@ -171,9 +173,8 @@ pub(crate) mod decl {
171173 }
172174
173175 impl Representable for TypeAliasType {
174- fn repr_str ( zelf : & Py < Self > , vm : & VirtualMachine ) -> PyResult < String > {
175- let name = zelf. name . str ( vm) ?;
176- Ok ( name. as_str ( ) . to_owned ( ) )
176+ fn repr_str ( zelf : & Py < Self > , _vm : & VirtualMachine ) -> PyResult < String > {
177+ Ok ( zelf. name . as_str ( ) . to_owned ( ) )
177178 }
178179 }
179180
0 commit comments