[Python-ideas] Improving fn(arg=arg, name=name, wibble=wibble) code
jfine2358 at gmail.com
Sat Sep 8 14:12:55 EDT 2018
The problem is to improve
Here's a suggestion. For each of four permissions, the code has an
assignment such as
has_add_permission = inline._has_add_permission(request, obj)
and the function call has four named parameters such as
where the permissions are add, change, deleted and view.
Browsing the file, I see something similar in several places, such as
'has_view_permission': self.has_view_permission(request, obj),
'has_change_permission': self.has_change_permission(request, obj),
'has_delete_permission': self.has_delete_permission(request, obj),
So, off the top of my head, have a function
get_permissions(item, request, obj)
and then simply write
** get_permissions(item, request, obj)
in the function call, to pass the permissions to the called function.
By the way, for ease of use this is relying on
https://www.python.org/dev/peps/pep-0448/ # Additional Unpacking
which allows multiple **kwargs in a function call. It was implemented
in Python 3.5.
By the way, Django 1.11 and 2.0 are still supported by Django, and
they both support Python 3.4. So we'll have to wait for a bit before
Django could accept this suggestion.
More information about the Python-ideas