[New-bugs-announce] [issue46224] doc: Fix bisect example using mutable function default
Sardorbek Imomaliev
report at bugs.python.org
Sun Jan 2 03:46:54 EST 2022
New submission from Sardorbek Imomaliev <imomaliev at hey.com>:
Currently, in `bisect` examples `grade` function is declared with mutable default for `breakpoints` arugment. I suggest updating.
https://github.com/sweeneyde commented
> I would say that even though using mutable defaults is often undesirable, there is no problem with it in this case: the body of the function does not mutate the default. It's also probably faster than re-constructing a new list at each function call. I would suggest opening an issue on https://bugs.python.org/ if you want to discuss more.
I agree that in this case it wouldn't matter because `breakpoints` are not mutated, but most of the time people copy from examples and adapt the code to their needs without giving it a second thought. In my opinion, it is a good practice to provide examples as foolproof as possible.
----------
assignee: docs at python
components: Documentation
messages: 409490
nosy: docs at python, imomaliev
priority: normal
pull_requests: 28548
severity: normal
status: open
title: doc: Fix bisect example using mutable function default
type: enhancement
versions: Python 3.10, Python 3.11, Python 3.6, Python 3.7, Python 3.8, Python 3.9
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue46224>
_______________________________________
More information about the New-bugs-announce
mailing list