The Wayback Machine - https://web.archive.org/web/20221108131041/https://github.com/python/cpython/issues/99152
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Behaviour change in partialmethod in Python3.11 #99152

Open
garyvdm opened this issue Nov 6, 2022 · 2 comments
Open

Behaviour change in partialmethod in Python3.11 #99152

garyvdm opened this issue Nov 6, 2022 · 2 comments
Assignees
Labels
type-bug An unexpected behavior, bug, or error

Comments

@garyvdm
Copy link

garyvdm commented Nov 6, 2022

Bug report

The behavior of partialmethod changed in python3.11. This caused a library that I use testsuite to fail.

Here is a minimal use case that demonstrates this:

from functools import partialmethod


class Cell:
    def __init__(self):
        self.alive = False

    def set_state(self, state):
        self.alive = bool(state)


class Wrapper:
    def set_state_wrap(self, cell: Cell, state):
        cell.set_state(state)


wrapper = Wrapper()

Cell.set_alive = partialmethod(wrapper.set_state_wrap, True)

cell = Cell()
cell.set_alive()
print(cell.alive)

In python3.10, this prints True. In python3.11 it errors with:

Traceback (most recent call last):
  File "/home/gary/partialmethod.py", line 23, in <module>
    c.set_alive()
TypeError: Wrapper.set_state_wrap() missing 1 required positional argument: 'state'

The arguments passed to Wrapper.set_state_wrap are:
python3.10: wrapper, cell, True
python3.11: cell, True

So partialmethod is forgetting that set_state_wrap is a method of wrapper, and it needs to pass that in as the first arg.

I know that the way that they are using partialmethod here is not how it is intended to be used, and feels wrong. However this change is behavior if intended should be documented.

Your environment

  • CPython versions tested on: Python 3.11.0 (broken) Python 3.10.7 (working)
  • Operating system and architecture: Fedora Linux 36
@garyvdm garyvdm added the type-bug An unexpected behavior, bug, or error label Nov 6, 2022
@sweeneyde
Copy link
Member

sweeneyde commented Nov 6, 2022

I bisected to here:

a918589 is the first bad commit
commit a918589
Author: Michael J. Sullivan [email protected]
Date: Wed May 4 21:00:21 2022 -0700

bpo-46764: Fix wrapping bound method with @classmethod (#31367)

@sweeneyde
Copy link
Member

sweeneyde commented Nov 6, 2022

cc @rhettinger

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants