Watch out for mutable defaults in function arguments
Default arguments in functions are useful. When you write a function with defaults you do so with the understanding that other developers may not wish to alter or amend options that are common or change infrequently. All defaults imply a contract – both a technical one, but also a social one to your fellow coders – that they cannot be mutable; if they change, you run the risk of invalidating the intent that you or your fellow developers made when they first called your function. But there are a parts of Python’s language design that can break that contract if you are not careful.
Read More ->
from Planet Python
via read more
No comments:
Post a Comment