GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Allow `functools.reduce`s 'initial' to be a keyword argument · Issue #125916 · python/cpython

Allow functools.reduces 'initial' to be a keyword argument #125916

New issue
Copy link
New issue
Copy link
Closed
#125917
Closed
Allow functools.reduces 'initial' to be a keyword argument#125916
#125917
Copy link
Labels
extension-modulesC modules in the Modules dirC modules in the Modules dirtype-featureA feature request or enhancementA feature request or enhancement

Description

@sayandipdutta
sayandipdutta
opened on Oct 24, 2024
Issue body actions

Feature or enhancement

Proposal:

functools.reduce takes function (generally a callable) and iterable, with an optional initial parameter:

https://docs.python.org/3/library/functools.html#functools.reduce

However, initial cannot be passed as a keyword argument, which reduces ;) readability,

from functools import reduce
from operator import sub
>>> reduce(sub, [1, 1, 2, 3, 5, 8], 21)
1
>>> reduce(sub, [1, 1, 2, 3, 5, 8], initial=21)
TypeError: reduce() takes no keyword arguments

Allowing initial as keyword argument will be more clear, and initial could also be passed as a keyword argument while making partial functions out of reduce.

Has this already been discussed elsewhere?

I have already discussed this feature proposal on Discourse

Links to previous discussion of this feature:

https://discuss.python.org/t/remove-positional-only-restriction-on-initial-parameter-of-reduce/68897

Linked PRs

  • gh-125916: Allow functools.reduce 'initial' to be a keyword argument #125917
  • gh-125916: Adapt functools.reduce() to Argument Clinic #125999

Activity

  1. sayandipdutta
    added
    type-featureA feature request or enhancementA feature request or enhancement
    on Oct 24, 2024
  2. skirpichev commented on Oct 24, 2024

    @skirpichev
    skirpichev
    on Oct 24, 2024
    Member
    More actions

    See also #121677

  3. skirpichev commented on Oct 24, 2024

    @skirpichev
    skirpichev
    on Oct 24, 2024
    Member
    More actions

    Also see #96640.

    @sobolevn, did you actually try to do conversion and benchmark it?

  4. skirpichev
    added a commit that references this issue on Oct 26, 2024

    pythongh-125916: convert reduce() to Argument Clinic

    b5ac476
  5. erlend-aasland
    added a commit that references this issue on Nov 1, 2024

    gh-125916: Adapt functools.reduce() to Argument Clinic (#125999)

    51ef54a
  6. erlend-aasland
    added
    extension-modulesC modules in the Modules dirC modules in the Modules dir
    on Nov 1, 2024
  7. erlend-aasland
    linked a pull request that will close this issuegh-125916: Allow functools.reduce 'initial' to be a keyword argument #125917on Nov 12, 2024
  8. erlend-aasland
    added a commit that references this issue on Nov 12, 2024

    gh-125916: Allow functools.reduce() 'initial' to be a keyword argument (

    abb90ba
  9. erlend-aasland
    closed this as completedin #125917on Nov 12, 2024
  10. picnixz
    added 2 commits that reference this issue on Dec 8, 2024

    pythongh-125916: Adapt functools.reduce() to Argument Clinic (python#…

    a156925

    pythongh-125916: Allow functools.reduce() 'initial' to be a keyword a…

    86ef3e4
  11. ebonnal
    added 2 commits that reference this issue on Jan 12, 2025

    pythongh-125916: Adapt functools.reduce() to Argument Clinic (python#…

    14e5e9f

    pythongh-125916: Allow functools.reduce() 'initial' to be a keyword a…

    17efa6e
  12. skirpichev
    marked functools.reduce does not accept keyword arguments for its parameters #139114 as a duplicate of this issue on Sep 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    extension-modulesC modules in the Modules dirC modules in the Modules dirtype-featureA feature request or enhancementA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402520 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.