Skip to content
Merged
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
Prev Previous commit
remove to_owned() from typing
  • Loading branch information
youknowone committed Jun 26, 2025
commit 166c7bc268f64904d5a1e679690d0a18b0ab3c04
34 changes: 13 additions & 21 deletions vm/src/stdlib/typing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ pub(crate) mod decl {
impl ParamSpec {
#[pymethod(magic)]
fn mro_entries(&self, _bases: PyObjectRef, vm: &VirtualMachine) -> PyResult {
Err(vm.new_type_error("Cannot subclass an instance of ParamSpec".to_owned()))
Err(vm.new_type_error("Cannot subclass an instance of ParamSpec"))
}

#[pygetset(magic)]
Expand Down Expand Up @@ -483,16 +483,14 @@ pub(crate) mod decl {
if let Some(name) = kwargs.swap_remove("name") {
name
} else {
return Err(vm.new_type_error(
"ParamSpec() missing required argument: 'name' (pos 1)".to_owned(),
));
return Err(
vm.new_type_error("ParamSpec() missing required argument: 'name' (pos 1)")
);
}
} else if args.args.len() == 1 {
args.args[0].clone()
} else {
return Err(
vm.new_type_error("ParamSpec() takes at most 1 positional argument".to_owned())
);
return Err(vm.new_type_error("ParamSpec() takes at most 1 positional argument"));
};

let bound = kwargs.swap_remove("bound");
Expand Down Expand Up @@ -524,15 +522,11 @@ pub(crate) mod decl {

// Check for invalid combinations
if covariant && contravariant {
return Err(
vm.new_value_error("Bivariant type variables are not supported.".to_owned())
);
return Err(vm.new_value_error("Bivariant type variables are not supported."));
}

if infer_variance && (covariant || contravariant) {
return Err(vm.new_value_error(
"Variance cannot be specified with infer_variance".to_owned(),
));
return Err(vm.new_value_error("Variance cannot be specified with infer_variance"));
}

// Handle default value
Expand Down Expand Up @@ -653,12 +647,12 @@ pub(crate) mod decl {

#[pymethod(magic)]
fn mro_entries(&self, _bases: PyObjectRef, vm: &VirtualMachine) -> PyResult {
Err(vm.new_type_error("Cannot subclass an instance of TypeVarTuple".to_owned()))
Err(vm.new_type_error("Cannot subclass an instance of TypeVarTuple"))
}

#[pymethod(magic)]
fn typing_subst(&self, _arg: PyObjectRef, vm: &VirtualMachine) -> PyResult {
Err(vm.new_type_error("Substitution of bare TypeVarTuple is not supported".to_owned()))
Err(vm.new_type_error("Substitution of bare TypeVarTuple is not supported"))
}

#[pymethod(magic)]
Expand All @@ -685,15 +679,13 @@ pub(crate) mod decl {
name
} else {
return Err(vm.new_type_error(
"TypeVarTuple() missing required argument: 'name' (pos 1)".to_owned(),
"TypeVarTuple() missing required argument: 'name' (pos 1)",
));
}
} else if args.args.len() == 1 {
args.args[0].clone()
} else {
return Err(vm.new_type_error(
"TypeVarTuple() takes at most 1 positional argument".to_owned(),
));
return Err(vm.new_type_error("TypeVarTuple() takes at most 1 positional argument"));
};

let default = kwargs.swap_remove("default");
Expand Down Expand Up @@ -755,7 +747,7 @@ pub(crate) mod decl {
impl ParamSpecArgs {
#[pymethod(magic)]
fn mro_entries(&self, _bases: PyObjectRef, vm: &VirtualMachine) -> PyResult {
Err(vm.new_type_error("Cannot subclass an instance of ParamSpecArgs".to_owned()))
Err(vm.new_type_error("Cannot subclass an instance of ParamSpecArgs"))
}

#[pygetset(magic)]
Expand Down Expand Up @@ -834,7 +826,7 @@ pub(crate) mod decl {
impl ParamSpecKwargs {
#[pymethod(magic)]
fn mro_entries(&self, _bases: PyObjectRef, vm: &VirtualMachine) -> PyResult {
Err(vm.new_type_error("Cannot subclass an instance of ParamSpecKwargs".to_owned()))
Err(vm.new_type_error("Cannot subclass an instance of ParamSpecKwargs"))
}

#[pygetset(magic)]
Expand Down