diff options
author | Kirill Podoprigora <kirill.bast9@mail.ru> | 2025-01-01 11:36:47 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-01-01 11:36:47 (GMT) |
commit | d903b17499b1a3bfb3ea848f6a1b6da02eac3328 (patch) | |
tree | 070a24e1cd2e3ebdb2ce6a739185f265138b244c /Lib/test | |
parent | c5438fdf4706a70bdd19338edc000dacffff6837 (diff) | |
download | cpython-d903b17499b1a3bfb3ea848f6a1b6da02eac3328.zip cpython-d903b17499b1a3bfb3ea848f6a1b6da02eac3328.tar.gz cpython-d903b17499b1a3bfb3ea848f6a1b6da02eac3328.tar.bz2 |
gh-121676: Raise a ``DeprecationWarning`` if the Python implementation of ``functools.reduce`` is called with `function` or `sequence` as a keyword args (#121677)
Python implementation of `functools` allows calling `reduce`
with `function` or `sequence` as keyword args. This doesn't
match behavior of our C accelerator and our documentation
for `functools.reduce` states that `function`and `sequence`
are positional-only arguments.
Now calling a Python implementation of `functools.reduce`
with `function` or `sequence` as keyword args would raise
a `DeprecationWarning` and is planned to be prohibited in
Python 3.16.
Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_functools.py | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/Lib/test/test_functools.py b/Lib/test/test_functools.py index 4a0252c..3222486 100644 --- a/Lib/test/test_functools.py +++ b/Lib/test/test_functools.py @@ -1045,6 +1045,12 @@ class TestReduceC(TestReduce, unittest.TestCase): class TestReducePy(TestReduce, unittest.TestCase): reduce = staticmethod(py_functools.reduce) + def test_reduce_with_kwargs(self): + with self.assertWarns(DeprecationWarning): + self.reduce(function=lambda x, y: x + y, sequence=[1, 2, 3, 4, 5], initial=1) + with self.assertWarns(DeprecationWarning): + self.reduce(lambda x, y: x + y, sequence=[1, 2, 3, 4, 5], initial=1) + class TestCmpToKey: |