Behaviour change in partialmethod in Python3.11
@rhettinger ci sta già lavorando.
Dal 7/11/2022.
Valutazione
Questa issue non è ancora stata valutata.
Descrizione
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
- Lingua principale
- Python
- Stelle
- 77.2k
- Fork
- 36k
- Merge medio
- 1g 9h
- PR unite (30g)
- 558
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di python/cpython
-
docs pending
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
stdlib type-feature
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
stdlib type-feature
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
build type-bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
-
stdlib topic-email type-feature
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
Tutte le issue di python/cpython
Issue simili
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
zostera/django-bootstrap4#894 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
use-agent-os/agent-os#3276 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
zephyrproject-rtos/zephyr#119726 ·
-
area/auth bug comp/agent P3 platform/discord type/security
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
NousResearch/hermes-agent#117848 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
zilliztech/memsearch#759 ·