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

Commit 5fb03b6

Browse filesBrowse files
authored
use qualname in TypeErrors for functions (#4476)
1 parent b6e4471 commit 5fb03b6
Copy full SHA for 5fb03b6

File tree

2 files changed

+15
-17
lines changed
Filter options

2 files changed

+15
-17
lines changed

‎Lib/test/test_dataclasses.py

Copy file name to clipboardExpand all lines: Lib/test/test_dataclasses.py
-8Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1954,8 +1954,6 @@ class R:
19541954
self.assertEqual(new_sample.x, another_new_sample.x)
19551955
self.assertEqual(sample.y, another_new_sample.y)
19561956

1957-
# TODO: RUSTPYTHON
1958-
@unittest.expectedFailure
19591957
def test_dataclasses_qualnames(self):
19601958
@dataclass(order=True, unsafe_hash=True, frozen=True)
19611959
class A:
@@ -3442,8 +3440,6 @@ class C:
34423440
self.assertEqual(c1.x, 3)
34433441
self.assertEqual(c1.y, 2)
34443442

3445-
# TODO: RUSTPYTHON
3446-
@unittest.expectedFailure
34473443
def test_frozen(self):
34483444
@dataclass(frozen=True)
34493445
class C:
@@ -3476,8 +3472,6 @@ class C:
34763472
"keyword argument 'a'"):
34773473
c1 = replace(c, x=20, a=5)
34783474

3479-
# TODO: RUSTPYTHON
3480-
@unittest.expectedFailure
34813475
def test_invalid_field_name(self):
34823476
@dataclass(frozen=True)
34833477
class C:
@@ -3521,8 +3515,6 @@ class C:
35213515
with self.assertRaisesRegex(ValueError, 'init=False'):
35223516
replace(c, y=30)
35233517

3524-
# TODO: RUSTPYTHON
3525-
@unittest.expectedFailure
35263518
def test_classvar(self):
35273519
@dataclass
35283520
class C:

‎vm/src/builtins/function.rs

Copy file name to clipboardExpand all lines: vm/src/builtins/function.rs
+15-9Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ impl PyFunction {
101101
if nargs > nexpected_args {
102102
return Err(vm.new_type_error(format!(
103103
"{}() takes {} positional arguments but {} were given",
104-
&self.code.obj_name, nexpected_args, nargs
104+
self.qualname(),
105+
nexpected_args,
106+
nargs
105107
)));
106108
}
107109
}
@@ -132,25 +134,29 @@ impl PyFunction {
132134
if let Some(pos) = argpos(code.posonlyarg_count..total_args, &name) {
133135
let slot = &mut fastlocals[pos];
134136
if slot.is_some() {
135-
return Err(
136-
vm.new_type_error(format!("Got multiple values for argument '{name}'"))
137-
);
137+
return Err(vm.new_type_error(format!(
138+
"{}() got multiple values for argument '{}'",
139+
self.qualname(),
140+
name
141+
)));
138142
}
139143
*slot = Some(value);
140144
} else if let Some(kwargs) = kwargs.as_ref() {
141145
kwargs.set_item(&name, value, vm)?;
142146
} else if argpos(0..code.posonlyarg_count, &name).is_some() {
143147
posonly_passed_as_kwarg.push(name);
144148
} else {
145-
return Err(
146-
vm.new_type_error(format!("got an unexpected keyword argument '{name}'"))
147-
);
149+
return Err(vm.new_type_error(format!(
150+
"{}() got an unexpected keyword argument '{}'",
151+
self.qualname(),
152+
name
153+
)));
148154
}
149155
}
150156
if !posonly_passed_as_kwarg.is_empty() {
151157
return Err(vm.new_type_error(format!(
152158
"{}() got some positional-only arguments passed as keyword arguments: '{}'",
153-
&self.code.obj_name,
159+
self.qualname(),
154160
posonly_passed_as_kwarg.into_iter().format(", "),
155161
)));
156162
}
@@ -207,7 +213,7 @@ impl PyFunction {
207213

208214
return Err(vm.new_type_error(format!(
209215
"{}() missing {} required positional argument{}: '{}{}{}'",
210-
&self.code.obj_name,
216+
self.qualname(),
211217
missing_args_len,
212218
if missing_args_len == 1 { "" } else { "s" },
213219
missing.iter().join("', '"),

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.