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
Prev Previous commit
Next Next commit
Update test_unpack_ex from v3.14.2
  • Loading branch information
CPython Developers authored and youknowone committed Feb 11, 2026
commit b6d08fe371f538e4abb08a1030310eea402dc9dd
1 change: 0 additions & 1 deletion Lib/test/test_inspect/test_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -2247,7 +2247,6 @@ def test_varkw_only(self):
self.assertEqualCallArgs(f, '**collections.UserDict(a=1, b=2)')
self.assertEqualCallArgs(f, 'c=3, **collections.UserDict(a=1, b=2)')

@unittest.expectedFailure # TODO: RUSTPYTHON; ? ^^^^^^^^^^^^ ++ ++ ^^^^
def test_keyword_only(self):
f = self.makeCallable('a=3, *, c, d=2')
self.assertEqualCallArgs(f, 'c=3')
Expand Down
2 changes: 0 additions & 2 deletions Lib/test/test_positional_only_arg.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,6 @@ def f(a, b, /, c=3):
with self.assertRaisesRegex(TypeError, r"f\(\) takes from 2 to 3 positional arguments but 4 were given"):
f(1, 2, 3, 4)

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_positional_only_and_kwonlyargs_invalid_calls(self):
def f(a, b, /, c, *, d, e):
pass
Expand Down
57 changes: 25 additions & 32 deletions Lib/test/test_unpack_ex.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
>>> sorted({**{'x': 1}, 'y': 2, **{'x': 3}}.items())
[('x', 3), ('y', 2)]

>>> sorted({**{'x': 1}, **{'x': 3}, 'x': 4}.items()) # TODO: RUSTPYTHON # doctest:+EXPECTED_FAILURE
>>> sorted({**{'x': 1}, **{'x': 3}, 'x': 4}.items())
[('x', 4)]

>>> {**{}}
Expand All @@ -138,7 +138,7 @@
... for i in range(1000)) + "}"))
1000

>>> {0:1, **{0:2}, 0:3, 0:4} # TODO: RUSTPYTHON # doctest:+EXPECTED_FAILURE
>>> {0:1, **{0:2}, 0:3, 0:4}
{0: 4}

List comprehension element unpacking
Expand All @@ -148,27 +148,27 @@
[0, 1, 2, 3, 4]

>>> l = [a, (3, 4), {5}, {6: None}, (i for i in range(7, 10))]
>>> [*item for item in l] # TODO: RUSTPYTHON # doctest:+EXPECTED_FAILURE
>>> [*item for item in l]
Traceback (most recent call last):
...
SyntaxError: iterable unpacking cannot be used in comprehension

>>> [*[0, 1] for i in range(10)] # TODO: RUSTPYTHON # doctest:+EXPECTED_FAILURE
>>> [*[0, 1] for i in range(10)]
Traceback (most recent call last):
...
SyntaxError: iterable unpacking cannot be used in comprehension

>>> [*'a' for i in range(10)] # TODO: RUSTPYTHON # doctest:+EXPECTED_FAILURE
>>> [*'a' for i in range(10)]
Traceback (most recent call last):
...
SyntaxError: iterable unpacking cannot be used in comprehension

>>> [*[] for i in range(10)] # TODO: RUSTPYTHON # doctest:+EXPECTED_FAILURE
>>> [*[] for i in range(10)]
Traceback (most recent call last):
...
SyntaxError: iterable unpacking cannot be used in comprehension

>>> {**{} for a in [1]} # TODO: RUSTPYTHON # doctest:+EXPECTED_FAILURE
>>> {**{} for a in [1]}
Traceback (most recent call last):
...
SyntaxError: dict unpacking cannot be used in dict comprehension
Expand Down Expand Up @@ -249,34 +249,34 @@

Overridden parameters

>>> f(x=5, **{'x': 3}, y=2) # TODO: RUSTPYTHON # doctest:+EXPECTED_FAILURE
>>> f(x=5, **{'x': 3}, y=2)
Traceback (most recent call last):
...
TypeError: test.test_unpack_ex.f() got multiple values for keyword argument 'x'

>>> f(**{'x': 3}, x=5, y=2) # TODO: RUSTPYTHON # doctest:+EXPECTED_FAILURE
>>> f(**{'x': 3}, x=5, y=2)
Traceback (most recent call last):
...
TypeError: test.test_unpack_ex.f() got multiple values for keyword argument 'x'

>>> f(**{'x': 3}, **{'x': 5}, y=2) # TODO: RUSTPYTHON # doctest:+EXPECTED_FAILURE
>>> f(**{'x': 3}, **{'x': 5}, y=2)
Traceback (most recent call last):
...
TypeError: test.test_unpack_ex.f() got multiple values for keyword argument 'x'

>>> f(x=5, **{'x': 3}, **{'x': 2}) # TODO: RUSTPYTHON # doctest:+EXPECTED_FAILURE
>>> f(x=5, **{'x': 3}, **{'x': 2})
Traceback (most recent call last):
...
TypeError: test.test_unpack_ex.f() got multiple values for keyword argument 'x'

>>> f(**{1: 3}, **{1: 5}) # TODO: RUSTPYTHON # doctest:+EXPECTED_FAILURE
>>> f(**{1: 3}, **{1: 5})
Traceback (most recent call last):
...
TypeError: test.test_unpack_ex.f() got multiple values for keyword argument '1'

Unpacking non-sequence

>>> a, *b = 7 # TODO: RUSTPYTHON # doctest:+EXPECTED_FAILURE
>>> a, *b = 7
Traceback (most recent call last):
...
TypeError: cannot unpack non-iterable int object
Expand Down Expand Up @@ -321,17 +321,17 @@

Now some general starred expressions (all fail).

>>> a, *b, c, *d, e = range(10) # TODO: RUSTPYTHON # doctest:+ELLIPSIS +EXPECTED_FAILURE
>>> a, *b, c, *d, e = range(10) # doctest:+ELLIPSIS
Traceback (most recent call last):
...
SyntaxError: multiple starred expressions in assignment

>>> [*b, *c] = range(10) # TODO: RUSTPYTHON # doctest:+ELLIPSIS +EXPECTED_FAILURE
>>> [*b, *c] = range(10) # doctest:+ELLIPSIS
Traceback (most recent call last):
...
SyntaxError: multiple starred expressions in assignment

>>> a,*b,*c,*d = range(4) # TODO: RUSTPYTHON # doctest:+ELLIPSIS +EXPECTED_FAILURE
>>> a,*b,*c,*d = range(4) # doctest:+ELLIPSIS
Traceback (most recent call last):
...
SyntaxError: multiple starred expressions in assignment
Expand All @@ -341,42 +341,42 @@
...
SyntaxError: starred assignment target must be in a list or tuple

>>> *a # TODO: RUSTPYTHON # doctest:+ELLIPSIS +EXPECTED_FAILURE
>>> *a # doctest:+ELLIPSIS
Traceback (most recent call last):
...
SyntaxError: can't use starred expression here

>>> *1 # TODO: RUSTPYTHON # doctest:+ELLIPSIS +EXPECTED_FAILURE
>>> *1 # doctest:+ELLIPSIS
Traceback (most recent call last):
...
SyntaxError: can't use starred expression here

>>> x = *a # TODO: RUSTPYTHON # doctest:+ELLIPSIS +EXPECTED_FAILURE
>>> x = *a # doctest:+ELLIPSIS
Traceback (most recent call last):
...
SyntaxError: can't use starred expression here

>>> (*x),y = 1, 2 # TODO: RUSTPYTHON # doctest:+ELLIPSIS +EXPECTED_FAILURE
>>> (*x),y = 1, 2 # doctest:+ELLIPSIS
Traceback (most recent call last):
...
SyntaxError: cannot use starred expression here

>>> (((*x))),y = 1, 2 # TODO: RUSTPYTHON # doctest:+ELLIPSIS +EXPECTED_FAILURE
>>> (((*x))),y = 1, 2 # doctest:+ELLIPSIS
Traceback (most recent call last):
...
SyntaxError: cannot use starred expression here

>>> z,(*x),y = 1, 2, 4 # TODO: RUSTPYTHON # doctest:+ELLIPSIS +EXPECTED_FAILURE
>>> z,(*x),y = 1, 2, 4 # doctest:+ELLIPSIS
Traceback (most recent call last):
...
SyntaxError: cannot use starred expression here

>>> z,(*x) = 1, 2 # TODO: RUSTPYTHON # doctest:+ELLIPSIS +EXPECTED_FAILURE
>>> z,(*x) = 1, 2 # doctest:+ELLIPSIS
Traceback (most recent call last):
...
SyntaxError: cannot use starred expression here

>>> ((*x),y) = 1, 2 # TODO: RUSTPYTHON # doctest:+ELLIPSIS +EXPECTED_FAILURE
>>> ((*x),y) = 1, 2 # doctest:+ELLIPSIS
Traceback (most recent call last):
...
SyntaxError: cannot use starred expression here
Expand All @@ -402,15 +402,8 @@

__test__ = {'doctests' : doctests}

EXPECTED_FAILURE = doctest.register_optionflag('EXPECTED_FAILURE') # TODO: RUSTPYTHON
class CustomOutputChecker(doctest.OutputChecker): # TODO: RUSTPYTHON
def check_output(self, want, got, optionflags): # TODO: RUSTPYTHON
if optionflags & EXPECTED_FAILURE: # TODO: RUSTPYTHON
return not super().check_output(want, got, optionflags) # TODO: RUSTPYTHON
return super().check_output(want, got, optionflags) # TODO: RUSTPYTHON

def load_tests(loader, tests, pattern):
tests.addTest(doctest.DocTestSuite(checker=CustomOutputChecker())) # TODO: RUSTPYTHON
tests.addTest(doctest.DocTestSuite())
return tests


Expand Down
14 changes: 7 additions & 7 deletions crates/vm/src/builtins/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,24 +229,24 @@ impl PyFunction {
};

// Count keyword-only arguments that were actually provided
let kwonly_given = if code.kwonlyarg_count > 0 {
let kwonly_start = code.arg_count as usize;
let kwonly_end = kwonly_start + code.kwonlyarg_count as usize;
code.varnames[kwonly_start..kwonly_end]
let kw_only_given = if code.kwonlyarg_count > 0 {
let start = code.arg_count as usize;
let end = start + code.kwonlyarg_count as usize;
code.varnames[start..end]
.iter()
.filter(|name| func_args.kwargs.contains_key(name.as_str()))
.count()
} else {
0
};

let given_msg = if kwonly_given > 0 {
let given_msg = if kw_only_given > 0 {
format!(
"{} positional argument{} (and {} keyword-only argument{}) were",
nargs,
if nargs == 1 { "" } else { "s" },
kwonly_given,
if kwonly_given == 1 { "" } else { "s" },
kw_only_given,
if kw_only_given == 1 { "" } else { "s" },
)
} else {
format!("{} {}", nargs, if nargs == 1 { "was" } else { "were" })
Expand Down