#32794: Get rid of boolean traps in Engine
-------------------------------------+-------------------------------------
Reporter: Abhyudai | Owner: nobody
Type: | Status: new
Uncategorized |
Component: Template | Version: 3.2
system |
Severity: Normal | Keywords: template, engine
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
While working on adding `repr` method to the
`django.template.engine.Engine` class, I noticed the class definition,
(essentially the `__init__` function) accepts some parameters like
`app_dirs`, `debug` and `autoescape` which are `boolean` but are accepted
as positional arguments. I think this design pattern pretty much falls
into the real of [https://ariya.io/2011/08/hall-of-api-shame-boolean-trap
boolean-trap].
One of the ways that we can deal by not making this backward incompatible
would be to add `**kwargs` to the function definition and do something of
this type along the lines:
{{{#!python
def __init__(self, dirs=None, app_dirs=False, context_processors=None,
debug=False, loaders=None, string_if_invalid='',
file_charset='utf-8', libraries=None, builtins=None,
autoescape=True, /, **kwargs):
# because False is it's default value
if not debug and 'debug' not in kwargs:
raise DeprecationWarning('this argument will be made named only
in a later release')
# the same thing can be done with the other two arguments
}}}
Another way would be to fiddle with `inspect.signature`. While the first
one appears lesser complex to me, I'm open to any other suggestions.
If the proposal seems acceptable, I would want to work on it.
--
Ticket URL: <https://code.djangoproject.com/ticket/32794>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/053.07fab49496d43577373785eb3b44ea9a%40djangoproject.com.