Strict Function Parameters in Python
2022-01-23
I was shocked to come across a Hacker News post about enforcing strict function parameters in Python, because I had no idea such a feature existed.
The idea is that Python functions support arguments in various formats:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
But we can restrict the caller format by using the /
and *
symbols like so:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
I can see this being situationally useful. For example, we can use this to prevent calling code from coupling to the specific names of positional arguments (which would prevent us from easily renaming them in the future).
But otherwise, I'm still not sure how I feel about this change, which adds more complexity to Python for minimal gain.