Mutables shouldn't be used as default parameters, it is a Python anti-pattern. See for example:
* Default Parameter Values in Python
* Python Mutable Defaults Are The Source of All Evil
* The Hitchhiker's Guide to Python - Common Gotchas
* Python Pitfall: Mutable Default Arguments
Mutable default arguments are used in a few places in docutils. Just grep =[] and ={} and retain function definitions.
Mutable default arguments can also be found in the documentation:
https://docutils.sourceforge.io/docs/howto/rst-roles.html#define-the-role-function
https://docutils.sourceforge.io/docs/howto/rst-roles.html#rfc-reference-role
Of course, that's not an immediate problem if the mutable arguments are actually not mutated by the function, but it remains an anti-pattern that may create problems in the future.
Attached is a suggestion. I would agree it's more verbose and perhaps more complex to understand. But then using anti-patterns in documentation looks like a bad idea.
Thank you for the report and proposal.
Attached is a patch against revision 8874 in the code repository.
As the bug may also be considered just a styling issue and the patch has the potential to break compatibility for 3rd party users, it will have to wait for review and discussion on the way ahead
(inclusion no earlier than 0.19 or 1.0).
Fixed in [r8919]. Thank you for the report.
Related
Commit: [r8919]
Last edit: Günter Milde 2022-07-06
Fixed in Docutils 0.19.
Thank you for the report.