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 — gh-102757: fix function signature mismatch for `functools.reduce` between code and documentation by XuehaiPan · Pull Request #102759 · python/cpython

Conversation

@XuehaiPan

@XuehaiPan XuehaiPan commented Mar 16, 2023 •
edited by bedevere-bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor
  • Align function signature for functools.reduce in Python implementation and documentation with the C implementation.
  • Add / to mark all arguments are positional only.
  • Issue: Function signature mismatch for functools.reduce between C implementation, Python implementation, and online documentaion #102757

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
XuehaiPan added 3 commits March 16, 2023 15:32
@XuehaiPan
Align signature of functools.reduce for Python implementation
fb8d48e
@XuehaiPan
Align signature of functools.reduce in documentation
dc418c4
@XuehaiPan
Mark all arguments in functools.reduce positional only
7ec4feb
@XuehaiPan
XuehaiPan requested a review from rhettinger as a code owner March 16, 2023 15:37
@bedevere-bot bedevere-bot mentioned this pull request Mar 16, 2023
Function signature mismatch for functools.reduce between C implementation, Python implementation, and online documentaion #102757
Closed
@bedevere-bot bedevere-bot added the awaiting review label Mar 16, 2023
@XuehaiPan
Add news entry
900963e
@rhettinger rhettinger self-assigned this Mar 16, 2023
sobolevn
sobolevn reviewed Mar 16, 2023
View reviewed changes
Comment thread Lib/functools.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@rhettinger rhettinger removed their assignment Mar 17, 2023
@XuehaiPan
XuehaiPan requested review from sobolevn and removed request for rhettinger March 17, 2023 11:33
XuehaiPan added 3 commits March 19, 2023 20:44
@XuehaiPan
Merge branch 'main' into functools.reduce-docs
1f8830f
@XuehaiPan
Revert signature change for functools.reduce Python implementation
a9b6860
@XuehaiPan
Update news entry
af70b37
@XuehaiPan XuehaiPan mentioned this pull request Mar 20, 2023
fix(ops): align kwargs for tree_reduce with functools.reduce with the Python C implementation metaopt/optree#47
Merged
10 of 12 tasks
XuehaiPan added 2 commits March 20, 2023 16:51
@XuehaiPan
Merge branch 'main' into functools.reduce-docs
9886226
@XuehaiPan
Merge branch 'main' into functools.reduce-docs
1157dfa
@arhadthedev arhadthedev added docs Documentation in the Doc dir extension-modules C modules in the Modules dir labels Mar 22, 2023
@XuehaiPan

XuehaiPan commented Mar 22, 2023

Copy link
Copy Markdown
Contributor Author

May also need to backport to Python 3.10 and 3.11. This documentation issue is causing real-world problems. Such as:

https://github.com/google/jax/blob/1703f096b5b7b66a1c97726c1c89ffdfbbfaaa22/jax/_src/tree_util.py#L274-L280

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@arhadthedev

arhadthedev commented Mar 22, 2023

Copy link
Copy Markdown
Member

@rhettinger (as a functools expert)

XuehaiPan reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

XuehaiPan added 3 commits March 24, 2023 14:36
@XuehaiPan
Merge branch 'main' into functools.reduce-docs
661ecc8
@XuehaiPan
Merge branch 'main' into functools.reduce-docs
f24c255
@XuehaiPan
Merge branch 'main' into functools.reduce-docs
9084477
carljm
carljm approved these changes Apr 17, 2023
View reviewed changes

@carljm carljm left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! It makes sense for the CPython
documentation and docstring of functools.reduce to align with the implementation that is always used in CPython.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-bot bedevere-bot added awaiting merge and removed awaiting review labels Apr 17, 2023
@XuehaiPan

XuehaiPan commented Sep 18, 2023

Copy link
Copy Markdown
Contributor Author

Gentle ping for this. Any updates?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@carljm
Merge branch 'main' into functools.reduce-docs
c8bc13f
@carljm
carljm merged commit 74f315e into python:main Sep 18, 2023
@bedevere-app bedevere-app Bot removed the awaiting merge label Sep 18, 2023
@XuehaiPan
XuehaiPan deleted the functools.reduce-docs branch September 18, 2023 16:43
@bedevere-bot

bedevere-bot commented Sep 18, 2023

Copy link
Copy Markdown

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot AMD64 RHEL7 3.x has failed when building commit 74f315e.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/all/#builders/15/builds/5692) and take a look at the build logs.
  4. Check if the failure is related to this commit (74f315e) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/all/#builders/15/builds/5692

Failed tests:

  • test_socket

Failed subtests:

  • test_dual_stack_client_v4 - test.test_socket.CreateServerFunctionalTest.test_dual_stack_client_v4

Summary of the results of the build (if available):

==

Click to see traceback logs
Traceback (most recent call last):
  File "/home/buildbot/buildarea/3.x.cstratak-RHEL7-x86_64/build/Lib/test/test_socket.py", line 6771, in test_dual_stack_client_v4
    with socket.create_server(("", port), family=socket.AF_INET6,
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/buildbot/buildarea/3.x.cstratak-RHEL7-x86_64/build/Lib/socket.py", line 935, in create_server
    raise error(err.errno, msg) from None
OSError: [Errno 98] Address already in use (while attempting to bind on address ('', 57716))
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot

bedevere-bot commented Sep 18, 2023

Copy link
Copy Markdown

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot AMD64 RHEL8 LTO + PGO 3.x has failed when building commit 74f315e.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/all/#builders/568/builds/4853) and take a look at the build logs.
  4. Check if the failure is related to this commit (74f315e) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/all/#builders/568/builds/4853

Failed tests:

  • test.test_asyncio.test_unix_events

Failed subtests:

  • test_fork_signal_handling - test.test_asyncio.test_unix_events.TestFork.test_fork_signal_handling

Summary of the results of the build (if available):

==

Click to see traceback logs
Traceback (most recent call last):
  File "/home/buildbot/buildarea/3.x.cstratak-RHEL8-x86_64.lto-pgo/build/Lib/unittest/async_case.py", line 90, in _callTestMethod
    if self._callMaybeAsync(method) is not None:
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/buildbot/buildarea/3.x.cstratak-RHEL8-x86_64.lto-pgo/build/Lib/unittest/async_case.py", line 117, in _callMaybeAsync
    return self._asyncioTestContext.run(func, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/buildbot/buildarea/3.x.cstratak-RHEL8-x86_64.lto-pgo/build/Lib/test/support/hashlib_helper.py", line 49, in wrapper
    return func_or_class(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/buildbot/buildarea/3.x.cstratak-RHEL8-x86_64.lto-pgo/build/Lib/test/test_asyncio/test_unix_events.py", line 1937, in test_fork_signal_handling
    self.assertTrue(child_handled.is_set())
AssertionError: False is not true
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot

bedevere-bot commented Sep 18, 2023

Copy link
Copy Markdown

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot AMD64 RHEL8 LTO 3.x has failed when building commit 74f315e.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/all/#builders/64/builds/5081) and take a look at the build logs.
  4. Check if the failure is related to this commit (74f315e) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/all/#builders/64/builds/5081

Failed tests:

  • test.test_asyncio.test_unix_events

Failed subtests:

  • test_fork_signal_handling - test.test_asyncio.test_unix_events.TestFork.test_fork_signal_handling

Summary of the results of the build (if available):

==

Click to see traceback logs
Traceback (most recent call last):
  File "/home/buildbot/buildarea/3.x.cstratak-RHEL8-x86_64.lto/build/Lib/unittest/async_case.py", line 90, in _callTestMethod
    if self._callMaybeAsync(method) is not None:
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/buildbot/buildarea/3.x.cstratak-RHEL8-x86_64.lto/build/Lib/unittest/async_case.py", line 117, in _callMaybeAsync
    return self._asyncioTestContext.run(func, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/buildbot/buildarea/3.x.cstratak-RHEL8-x86_64.lto/build/Lib/test/support/hashlib_helper.py", line 49, in wrapper
    return func_or_class(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/buildbot/buildarea/3.x.cstratak-RHEL8-x86_64.lto/build/Lib/test/test_asyncio/test_unix_events.py", line 1937, in test_fork_signal_handling
    self.assertTrue(child_handled.is_set())
AssertionError: False is not true
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@AA-Turner

AA-Turner commented Sep 19, 2023

Copy link
Copy Markdown
Member

@carljm should we backport the docs part of this PR?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@carljm

carljm commented Sep 20, 2023

Copy link
Copy Markdown
Member

@AA-Turner Sure, we can. I don't think it's important, but I guess it's possible it could reduce conflict in some other backport in future.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

csm10495 pushed a commit to csm10495/cpython that referenced this pull request Sep 28, 2023
@XuehaiPan @csm10495
pythongh-102757: fix function signature mismatch for `functools.reduc…
ebfa90b
…e` between code and documentation (python#102759)
@XuehaiPan XuehaiPan mentioned this pull request Dec 25, 2023
[dynamo] fix functools.reduce() function with None as initial pytorch/pytorch#116398
Closed
pytorchmergebot pushed a commit to pytorch/pytorch that referenced this pull request Dec 25, 2023
@XuehaiPan @pytorchmergebot
[dynamo] fix functools.reduce() function with None as initial (#…
039fbeb
…116398)

The `initial` argument in `functools.reduce` can be `None`.

```python
initial_missing = object()

def reduce(function, iterable, initial=initial_missing, /):
    it = iter(iterable)
    if initial is initial_missing:
        value = next(it)
    else:
        value = initial
    for element in it:
        value = function(value, element)
    return value
```

Reference:

- python/cpython#102759

Pull Request resolved: #116398
Approved by: https://github.com/Skylion007
facebook-github-bot pushed a commit to pytorch/benchmark that referenced this pull request Jan 2, 2024
@XuehaiPan @facebook-github-bot
fix functools.reduce() function with None as initial (#116398)
f535c05
Summary:
The `initial` argument in `functools.reduce` can be `None`.

```python
initial_missing = object()

def reduce(function, iterable, initial=initial_missing, /):
    it = iter(iterable)
    if initial is initial_missing:
        value = next(it)
    else:
        value = initial
    for element in it:
        value = function(value, element)
    return value
```

Reference:

- python/cpython#102759

X-link: pytorch/pytorch#116398
Approved by: https://github.com/Skylion007

Reviewed By: izaitsevfb, jeanschmidt

Differential Revision: D52424773

fbshipit-source-id: 36d3a6f5f5786350fe8c325773deb135ccbd48e9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@carljm carljm carljm approved these changes
@sobolevn sobolevn Awaiting requested review from sobolevn

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

docs Documentation in the Doc dir extension-modules C modules in the Modules dir

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

7 participants

@XuehaiPan @arhadthedev @bedevere-bot @AA-Turner @carljm @sobolevn @rhettinger
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — 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.