Opened 5 years ago
Closed 5 years ago
#30880 closed Cleanup/optimization (wontfix)
Optimize the _tx_resource_for_name() function in django/scripts/manage_translations.py
Reported by: | ankit1219 | Owned by: | nobody |
---|---|---|---|
Component: | Core (Other) | Version: | dev |
Severity: | Normal | Keywords: | Optimize scripts |
Cc: | asrokx917@… | Triage Stage: | Unreviewed |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description (last modified by )
The _tx_resource_for_name() function in django/scripts/manage_translations.py uses simple if else statement to return the Transifex resource name.
def _tx_resource_for_name(name):
if name == 'core':
return "django.core"
else:
return "django.contrib-%s" % name
You can use Python ternary operator to reduce code size and increase readability of the code.
def _tx_resource_for_name(name):
return "django.core" if name == 'core' else "django.contrib-%s" % name
It allows us to replace simple if statements with a single line expression. Increases code readability by reducing number of lines of code.
Change History (2)
comment:1 by , 5 years ago
Description: | modified (diff) |
---|
comment:2 by , 5 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
Version: | 2.2 → master |
Decreasing the number of lines doesn't increase readability in most of cases. The current form looks good to me.
I can send a PR to optimize the code.