Skip to content

Commit 2c7692b

Browse files
committed
Representable for TypeAliasType
1 parent 50a6a83 commit 2c7692b

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

vm/src/stdlib/typing.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub(crate) fn make_module(vm: &VirtualMachine) -> PyRef<PyModule> {
3030
#[pymodule(name = "_typing")]
3131
pub(crate) mod decl {
3232
use crate::{
33-
PyObjectRef, PyPayload, PyResult, VirtualMachine,
33+
Py, PyObjectRef, PyPayload, PyResult, VirtualMachine,
3434
builtins::{PyTupleRef, PyTypeRef, pystr::AsPyStr},
3535
function::{FuncArgs, IntoFuncArgs},
3636
types::{Constructor, Representable},
@@ -88,7 +88,7 @@ pub(crate) mod decl {
8888

8989
impl Representable for NoDefault {
9090
#[inline(always)]
91-
fn repr_str(_zelf: &crate::Py<Self>, _vm: &VirtualMachine) -> PyResult<String> {
91+
fn repr_str(_zelf: &Py<Self>, _vm: &VirtualMachine) -> PyResult<String> {
9292
Ok("typing.NoDefault".to_owned())
9393
}
9494
}
@@ -104,7 +104,7 @@ pub(crate) mod decl {
104104
// compute_value: PyObjectRef,
105105
// module: PyObjectRef,
106106
}
107-
#[pyclass(with(Constructor), flags(BASETYPE))]
107+
#[pyclass(with(Constructor, Representable), flags(BASETYPE))]
108108
impl TypeAliasType {
109109
pub const fn new(name: PyObjectRef, type_params: PyTupleRef, value: PyObjectRef) -> Self {
110110
Self {
@@ -128,12 +128,6 @@ pub(crate) mod decl {
128128
fn __type_params__(&self) -> PyTupleRef {
129129
self.type_params.clone()
130130
}
131-
132-
#[pymethod(name = "__repr__")]
133-
fn repr(&self, vm: &VirtualMachine) -> PyResult<String> {
134-
let name = self.name.str(vm)?;
135-
Ok(name.as_str().to_owned())
136-
}
137131
}
138132

139133
impl Constructor for TypeAliasType {
@@ -176,6 +170,13 @@ pub(crate) mod decl {
176170
}
177171
}
178172

173+
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+
}
178+
}
179+
179180
// impl AsMapping for Generic {
180181
// fn as_mapping() -> &'static PyMappingMethods {
181182
// static AS_MAPPING: Lazy<PyMappingMethods> = Lazy::new(|| PyMappingMethods {

0 commit comments

Comments
 (0)