Opened 3 weeks ago
Closed 3 weeks ago
#36763 closed Cleanup/optimization (invalid)
Replace if-None checks with ternary operator in TemplateDoesNotExist.init
| Reported by: | Pravin | Owned by: | Pravin |
|---|---|---|---|
| Component: | Template system | Version: | 5.2 |
| Severity: | Normal | Keywords: | TemplateDoesNotExist |
| Cc: | Pravin | Triage Stage: | Unreviewed |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | yes | UI/UX: | no |
Description
I noticed TemplateDoesNotExist.__init__ could be made more readable and more clear.
Instead of this
def __init__(self, msg, tried=None, backend=None, chain=None):
self.backend = backend
if tried is None:
tried = []
self.tried = tried
if chain is None:
chain = []
self.chain = chain
super().__init__(msg)
This could have been more simple, clear and readable like this
def __init__(self, msg, tried=None, backend=None, chain=None):
self.backend = backend
self.tried = tried if tried else []
self.chain = chain if chain else []
super().__init__(msg)
Change History (3)
comment:1 by , 3 weeks ago
| Summary: | Small code refactoring in TemplateDoesNotExist.__init__ → Replace if-None checks with ternary operator in TemplateDoesNotExist.init |
|---|
comment:3 by , 3 weeks ago
| Resolution: | → invalid |
|---|---|
| Status: | assigned → closed |
There is nothing wrong with this code, and as I said (multiple times) we try to avoid unnecessary (and this is completely unnecessary) and trivial code reformatting unless it's a big problem as it creates extra noise in the history.
Note:
See TracTickets
for help on using tickets.
since the codebase already uses the if-none pattern for initialization, I think it’s clear and consistent enough. so this seems more like a matter of style preference.
what do you think?