[Django] #36103: Simplify get_namespace() and adjust get_and_report_namespace() method signature

7 views
Skip to first unread message

Django

unread,
Jan 16, 2025, 2:19:04 AM1/16/25
to django-...@googlegroups.com
#36103: Simplify get_namespace() and adjust get_and_report_namespace() method
signature
-------------------------------------+-------------------------------------
Reporter: Salvo | Owner: Salvo Polizzi
Polizzi |
Type: | Status: assigned
Cleanup/optimization |
Component: Core | Version: dev
(Management commands) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Following the discussion in [https://github.com/django/django/pull/18158
PR], we propose the following improvements to enhance readability and
reduce confusion:
1. Simplify `get_namespace()`:
- The current implementation of get_namespace() can be rewritten as a
one-liner for better readability without changing its functionality.
- Example:
{{{
#current
def get_namespace(self):
apps_models = apps.get_models()
namespace = {}
for model in reversed(apps_models):
if model.__module__:
namespace[model.__name__] = model
return namespace

#proposed
def get_namespace():
return {m.__name__: m for m in reversed(apps.get_models()) if
m.__module__}
}}}

2. Update `get_and_report_namespace()`:
- The `no_imports` parameter in the method signature can be
misleading and cause confusion for its users.
- Proposed Change: Remove the `no_imports` parameter from the method
and instead handle its logic in the relevant runners where the
namespace is imported.
- Justification: This improves separation of concerns and makes the
method more focused.
--
Ticket URL: <https://code.djangoproject.com/ticket/36103>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jan 16, 2025, 2:19:37 AM1/16/25
to django-...@googlegroups.com
#36103: Simplify get_namespace() and adjust get_and_report_namespace() method
signature
-------------------------------------+-------------------------------------
Reporter: Salvo Polizzi | Owner: Salvo
Type: | Polizzi
Cleanup/optimization | Status: assigned
Component: Core (Management | Version: dev
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Salvo Polizzi:

Old description:
New description:

Following the last discussion in
--
Ticket URL: <https://code.djangoproject.com/ticket/36103#comment:1>

Django

unread,
Jan 16, 2025, 6:43:08 AM1/16/25
to django-...@googlegroups.com
#36103: Simplify get_namespace() and adjust get_and_report_namespace() method
signature
-------------------------------------+-------------------------------------
Reporter: Salvo Polizzi | Owner: Salvo
Type: | Polizzi
Cleanup/optimization | Status: assigned
Component: Core (Management | Version: 5.2
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Natalia Bidart):

* stage: Unreviewed => Accepted
* version: dev => 5.2

Comment:

Thank you Salvo for this ticket, I overall agree except for the
`no_imports`, I have no problem to remove it from
`get_and_report_namespace` but we should do it in a way that does not
duplicate logic/checks. Thank you!
--
Ticket URL: <https://code.djangoproject.com/ticket/36103#comment:2>
Reply all
Reply to author
Forward
0 new messages