Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

use qualname in TypeErrors for functions #4476

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 0 additions & 8 deletions 8 Lib/test/test_dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -1954,8 +1954,6 @@ class R:
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:
Expand Down Expand Up @@ -3442,8 +3440,6 @@ class C:
self.assertEqual(c1.x, 3)
self.assertEqual(c1.y, 2)

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_frozen(self):
@dataclass(frozen=True)
class C:
Expand Down Expand Up @@ -3476,8 +3472,6 @@ class C:
"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:
Expand Down Expand Up @@ -3521,8 +3515,6 @@ class C:
with self.assertRaisesRegex(ValueError, 'init=False'):
replace(c, y=30)

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_classvar(self):
@dataclass
class C:
Expand Down
24 changes: 15 additions & 9 deletions 24 vm/src/builtins/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
)));
}
}
Expand Down Expand Up @@ -132,25 +134,29 @@ 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() {
kwargs.set_item(&name, value, vm)?;
} 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(", "),
)));
}
Expand Down Expand Up @@ -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("', '"),
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.