mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
use qualname in TypeErrors for functions (#4476)
This commit is contained in:
8
Lib/test/test_dataclasses.py
vendored
8
Lib/test/test_dataclasses.py
vendored
@@ -1954,8 +1954,6 @@ class TestCase(unittest.TestCase):
|
||||
self.assertEqual(new_sample.x, another_new_sample.x)
|
||||
self.assertEqual(sample.y, another_new_sample.y)
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
def test_dataclasses_qualnames(self):
|
||||
@dataclass(order=True, unsafe_hash=True, frozen=True)
|
||||
class A:
|
||||
@@ -3442,8 +3440,6 @@ class TestReplace(unittest.TestCase):
|
||||
self.assertEqual(c1.x, 3)
|
||||
self.assertEqual(c1.y, 2)
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
def test_frozen(self):
|
||||
@dataclass(frozen=True)
|
||||
class C:
|
||||
@@ -3476,8 +3472,6 @@ class TestReplace(unittest.TestCase):
|
||||
"keyword argument 'a'"):
|
||||
c1 = replace(c, x=20, a=5)
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
def test_invalid_field_name(self):
|
||||
@dataclass(frozen=True)
|
||||
class C:
|
||||
@@ -3521,8 +3515,6 @@ class TestReplace(unittest.TestCase):
|
||||
with self.assertRaisesRegex(ValueError, 'init=False'):
|
||||
replace(c, y=30)
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
def test_classvar(self):
|
||||
@dataclass
|
||||
class C:
|
||||
|
||||
@@ -101,7 +101,9 @@ impl PyFunction {
|
||||
if nargs > nexpected_args {
|
||||
return Err(vm.new_type_error(format!(
|
||||
"{}() takes {} positional arguments but {} were given",
|
||||
&self.code.obj_name, nexpected_args, nargs
|
||||
self.qualname(),
|
||||
nexpected_args,
|
||||
nargs
|
||||
)));
|
||||
}
|
||||
}
|
||||
@@ -132,9 +134,11 @@ impl PyFunction {
|
||||
if let Some(pos) = argpos(code.posonlyarg_count..total_args, &name) {
|
||||
let slot = &mut fastlocals[pos];
|
||||
if slot.is_some() {
|
||||
return Err(
|
||||
vm.new_type_error(format!("Got multiple values for argument '{name}'"))
|
||||
);
|
||||
return Err(vm.new_type_error(format!(
|
||||
"{}() got multiple values for argument '{}'",
|
||||
self.qualname(),
|
||||
name
|
||||
)));
|
||||
}
|
||||
*slot = Some(value);
|
||||
} else if let Some(kwargs) = kwargs.as_ref() {
|
||||
@@ -142,15 +146,17 @@ impl PyFunction {
|
||||
} else if argpos(0..code.posonlyarg_count, &name).is_some() {
|
||||
posonly_passed_as_kwarg.push(name);
|
||||
} else {
|
||||
return Err(
|
||||
vm.new_type_error(format!("got an unexpected keyword argument '{name}'"))
|
||||
);
|
||||
return Err(vm.new_type_error(format!(
|
||||
"{}() got an unexpected keyword argument '{}'",
|
||||
self.qualname(),
|
||||
name
|
||||
)));
|
||||
}
|
||||
}
|
||||
if !posonly_passed_as_kwarg.is_empty() {
|
||||
return Err(vm.new_type_error(format!(
|
||||
"{}() got some positional-only arguments passed as keyword arguments: '{}'",
|
||||
&self.code.obj_name,
|
||||
self.qualname(),
|
||||
posonly_passed_as_kwarg.into_iter().format(", "),
|
||||
)));
|
||||
}
|
||||
@@ -207,7 +213,7 @@ impl PyFunction {
|
||||
|
||||
return Err(vm.new_type_error(format!(
|
||||
"{}() missing {} required positional argument{}: '{}{}{}'",
|
||||
&self.code.obj_name,
|
||||
self.qualname(),
|
||||
missing_args_len,
|
||||
if missing_args_len == 1 { "" } else { "s" },
|
||||
missing.iter().join("', '"),
|
||||
|
||||
Reference in New Issue
Block a user