@@ -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,10 @@ pub(crate) mod decl {
154154 )));
155155 }
156156
157- let name = args.args[0].clone();
157+ let name = args.args[0]
158+ .clone()
159+ .downcast::<crate::builtins::PyStr>()
160+ .map_err(|_| vm.new_type_error("TypeAliasType name must be a string".to_owned()))?;
158161 let value = args.args[1].clone();
159162
160163 let type_params = if let Some(tp) = args.kwargs.get("type_params") {
@@ -171,9 +174,8 @@ pub(crate) mod decl {
171174 }
172175
173176 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())
177+ fn repr_str(zelf: &Py<Self>, _vm: &VirtualMachine) -> PyResult<String> {
178+ Ok(zelf.name.as_str().to_owned())
177179 }
178180 }
179181
0 commit comments