Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Behaviour change in partialmethod in Python3.11 #99152

Open
Assignees
rhettinger
Labels
stdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error
@garyvdm

Description

@garyvdm

Bug report

The behavior ofpartialmethod changed in python3.11. This caused a library that I usetestsuite to fail.

Here is a minimal use case that demonstrates this:

from functools import partialmethodclass 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 printsTrue. 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 toWrapper.set_state_wrap are:
python3.10:wrapper, cell, True
python3.11:cell, True

Sopartialmethod is forgetting thatset_state_wrap is a method ofwrapper, and it needs to pass that in as the first arg.

I know that the way that they are usingpartialmethod 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

Metadata

Metadata

Assignees

Labels

stdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp