Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix(PyStrRef): fix TODO in typing.rs where PyObjectRef was used
  • Loading branch information
walker84837 committed Oct 20, 2025
commit 78601f30d12cc3892214d31c606b016defcb9a93
3 changes: 3 additions & 0 deletions vm/src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2453,6 +2453,9 @@ impl ExecutingFrame<'_> {
.map_err(|_| vm.new_type_error("Type params must be a tuple."))?
};

let name = name.downcast::<crate::builtins::PyStr>().map_err(|_| {
vm.new_type_error("TypeAliasType name must be a string".to_owned())
})?;
let type_alias = typing::TypeAliasType::new(name, type_params, value);
Ok(type_alias.into_ref(&vm.ctx).into())
}
Expand Down
17 changes: 9 additions & 8 deletions vm/src/stdlib/typing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub(crate) fn make_module(vm: &VirtualMachine) -> PyRef<PyModule> {
pub(crate) mod decl {
use crate::{
Py, PyObjectRef, PyPayload, PyResult, VirtualMachine,
builtins::{PyTupleRef, PyTypeRef, pystr::AsPyStr},
builtins::{PyStrRef, PyTupleRef, PyTypeRef, pystr::AsPyStr},
function::{FuncArgs, IntoFuncArgs},
types::{Constructor, Representable},
};
Expand Down Expand Up @@ -98,15 +98,15 @@ pub(crate) mod decl {
#[derive(Debug, PyPayload)]
#[allow(dead_code)]
pub(crate) struct TypeAliasType {
name: PyObjectRef, // TODO PyStrRef?
name: PyStrRef,
type_params: PyTupleRef,
value: PyObjectRef,
// compute_value: PyObjectRef,
// module: PyObjectRef,
}
#[pyclass(with(Constructor, Representable), flags(BASETYPE))]
impl TypeAliasType {
pub const fn new(name: PyObjectRef, type_params: PyTupleRef, value: PyObjectRef) -> Self {
pub const fn new(name: PyStrRef, type_params: PyTupleRef, value: PyObjectRef) -> Self {
Self {
name,
type_params,
Expand All @@ -116,7 +116,7 @@ pub(crate) mod decl {

#[pygetset]
fn __name__(&self) -> PyObjectRef {
self.name.clone()
self.name.clone().into()
}

#[pygetset]
Expand Down Expand Up @@ -154,7 +154,9 @@ pub(crate) mod decl {
)));
}

let name = args.args[0].clone();
let name = args.args[0].clone().downcast::<crate::builtins::PyStr>().map_err(|_| {
vm.new_type_error("TypeAliasType name must be a string".to_owned())
})?;
let value = args.args[1].clone();

let type_params = if let Some(tp) = args.kwargs.get("type_params") {
Expand All @@ -171,9 +173,8 @@ pub(crate) mod decl {
}

impl Representable for TypeAliasType {
fn repr_str(zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<String> {
let name = zelf.name.str(vm)?;
Ok(name.as_str().to_owned())
fn repr_str(zelf: &Py<Self>, _vm: &VirtualMachine) -> PyResult<String> {
Ok(zelf.name.as_str().to_owned())
}
}

Expand Down
Loading