[docs] [issue21105] functools.partialmethod example doesn't actually work

Alex Gaynor report at bugs.python.org
Sun Mar 30 20:15:13 CEST 2014

New submission from Alex Gaynor:

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'

assignee: docs at python
components: Documentation
keywords: easy
messages: 215191
nosy: alex, docs at python
priority: normal
severity: normal
status: open
title: functools.partialmethod example doesn't actually work
versions: Python 3.4, Python 3.5

Python tracker <report at bugs.python.org>

More information about the docs mailing list