[Django] #30881: Optimize _tx_resource_for_name() function in django/scripts/manage_translations.py

4 views
Skip to first unread message

Django

unread,
Oct 14, 2019, 4:18:58 PM10/14/19
to django-...@googlegroups.com
#30881: Optimize _tx_resource_for_name() function in
django/scripts/manage_translations.py
-------------------------------------+-------------------------------------
Reporter: ankit1219 | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Core | Version: 3.0
(Other) |
Severity: Normal | Keywords: Optimize scripts
Triage Stage: | Has patch: 1
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
-------------------------------------+-------------------------------------
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):
""" Return the Transifex resource 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 the Transifex resource 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.

--
Ticket URL: <https://code.djangoproject.com/ticket/30881>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Oct 14, 2019, 4:24:03 PM10/14/19
to django-...@googlegroups.com
#30881: Optimize _tx_resource_for_name() function in
django/scripts/manage_translations.py
-------------------------------------+-------------------------------------
Reporter: ankit1219 | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: Core (Other) | Version: 3.0
Severity: Normal | Resolution: duplicate

Keywords: Optimize scripts | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

* status: new => closed
* resolution: => duplicate


Comment:

Duplicate of #30880.

--
Ticket URL: <https://code.djangoproject.com/ticket/30881#comment:1>

Reply all
Reply to author
Forward
0 new messages