classification
Title: functools.partialmethod example doesn't actually work
Type: Stage: resolved
Components: Documentation Versions: Python 3.4, Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: alex, docs@python, python-dev
Priority: normal Keywords: easy

Created on 2014-03-30 18:15 by alex, last changed 2014-03-30 19:07 by python-dev. This issue is now closed.

Messages (2)
msg215191 - (view) Author: Alex Gaynor (alex) * (Python committer) Date: 2014-03-30 18:15
Specifically the example at: https://docs.python.org/3/library/functools.html?highlight=functools#functools.partialmethod

``_alive`` isn't actually assigned before the example tries to read it. Running this code at a for-real REPL results in:

>>> class Cell(object):
...     @property
...     def alive(self):
...         return self._alive
...     def set_state(self, state):
...         self._alive = bool(state)
...     import functools
...     set_alive = functools.partialmethod(set_state, True)
...     set_dead = functools.partialmethod(set_state, False)
...
>>> c = Cell()
>>> c.alive
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 4, in alive
AttributeError: 'Cell' object has no attribute '_alive'
msg215195 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-03-30 19:07
New changeset ed81acc970d9 by Benjamin Peterson in branch '3.4':
make partialmethod example work (closes #21105)
http://hg.python.org/cpython/rev/ed81acc970d9

New changeset b8a76485b5ed by Benjamin Peterson in branch 'default':
merge 3.4 (#21105)
http://hg.python.org/cpython/rev/b8a76485b5ed
History
Date User Action Args
2014-03-30 19:07:39python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg215195

resolution: fixed
stage: resolved
2014-03-30 18:15:13alexcreate