[docutils:bugs] #430 avoid mutables as default functions arguments

"Günter Milde" via Docutils-develop <[email protected]>
Newsgroups gmane.text.docutils.devel
Message-ID </p/docutils/bugs/430/cc883204516239e2c0ae98ed355a753f519323ce.bugs@docutils.p.sourceforge.net>
- **status**: open-fixed --> closed-fixed
- **Comment**:

Fixed in Docutils 0.19.
Thank you for the report.



---

** [bugs:#430] avoid mutables as default functions arguments**

**Status:** closed-fixed
**Labels:** rst parser 
**Created:** Mon Oct 25, 2021 09:53 AM UTC by Dimitri Papadopoulos
**Last Updated:** Wed Dec 29, 2021 12:19 PM UTC
**Owner:** Günter Milde


Mutables shouldn't be used as default parameters, it is a Python anti-pattern. See for example:
* [Default Parameter Values in Python](https://web.archive.org/web/20200221224620/http://effbot.org/zone/default-values.htm)
* [Python Mutable Defaults Are The Source of All Evil](https://florimond.dev/en/posts/2018/08/python-mutable-defaults-are-the-source-of-all-evil/)
* [The Hitchhiker's Guide to Python - Common Gotchas](https://docs.python-guide.org/writing/gotchas/#mutable-default-arguments)
* [Python Pitfall: Mutable Default Arguments](https://towardsdatascience.com/python-pitfall-mutable-default-arguments-9385e8265422)

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.


---

Sent from sourceforge.net because [email protected] is subscribed to https://sourceforge.net/p/docutils/bugs/

To unsubscribe from further messages, a project admin can change settings at https://sourceforge.net/p/docutils/admin/bugs/options.  Or, if this is a mailing list, you can unsubscribe from the mailing list.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.