[Django] #27870: Clean up autocomplete function

16 views
Skip to first unread message

Django

unread,
Feb 22, 2017, 8:08:41 AM2/22/17
to django-...@googlegroups.com
#27870: Clean up autocomplete function
-------------------------------------+-------------------------------------
Reporter: Phil | Owner: Phil
Type: | Status: assigned
Uncategorized |
Component: Core | Version: master
(Management commands) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
-------------------------------------+-------------------------------------
There are few thing in
[core/management/__init__.py](https://github.com/django/django/blob/master/django/core/management/__init__.py)
those look strange.

1. In [line
257](https://github.com/django/django/blob/master/django/core/management/__init__.py#L257)
there is the code like `sorted(x)[0]` which is similar to `min(x)`. But
the second one looks better, works for O(N) but not O(N log N) and doesn't
spend memory for the new object.
Sure, time and memory optimizations are negligible in this case, but
readability is more important.

2. In [line
261](https://github.com/django/django/blob/master/django/core/management/__init__.py#L261)
we declare list of used options but use only to understand if option was
already used. So while we don't need order, but only want to check, if
option is already used. So set is better than list both semantically and
complexity (~ O(1) instead of O(N)).

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

Django

unread,
Feb 22, 2017, 8:28:27 AM2/22/17
to django-...@googlegroups.com
#27870: Clean up autocomplete function
-------------------------------------+-------------------------------------
Reporter: Phil | Owner: Phil
Type: | Status: assigned
Cleanup/optimization |
Component: Core (Management | Version: master
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

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

* type: Uncategorized => Cleanup/optimization


Old description:

> There are few thing in
> [core/management/__init__.py](https://github.com/django/django/blob/master/django/core/management/__init__.py)
> those look strange.
>
> 1. In [line
> 257](https://github.com/django/django/blob/master/django/core/management/__init__.py#L257)
> there is the code like `sorted(x)[0]` which is similar to `min(x)`. But
> the second one looks better, works for O(N) but not O(N log N) and
> doesn't spend memory for the new object.
> Sure, time and memory optimizations are negligible in this case, but
> readability is more important.
>
> 2. In [line
> 261](https://github.com/django/django/blob/master/django/core/management/__init__.py#L261)
> we declare list of used options but use only to understand if option was
> already used. So while we don't need order, but only want to check, if
> option is already used. So set is better than list both semantically and
> complexity (~ O(1) instead of O(N)).

New description:

There are few thing in
{{{core/management/__init__.py}}}(https://github.com/django/django/blob/master/django/core/management/__init__.py)
those look strange.

1. In line
257(https://github.com/django/django/blob/master/django/core/management/__init__.py#L257)


there is the code like `sorted(x)[0]` which is similar to `min(x)`. But
the second one looks better, works for O(N) but not O(N log N) and doesn't
spend memory for the new object.
Sure, time and memory optimizations are negligible in this case, but
readability is more important.

2. In line
261(https://github.com/django/django/blob/master/django/core/management/__init__.py#L261)


we declare list of used options but use only to understand if option was
already used. So while we don't need order, but only want to check, if
option is already used. So set is better than list both semantically and
complexity (~ O(1) instead of O(N)).

--

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

Django

unread,
Feb 22, 2017, 9:15:37 AM2/22/17
to django-...@googlegroups.com
#27870: Clean up ManagementUtility.autocomplete()

-------------------------------------+-------------------------------------
Reporter: Phil | Owner: Phil
Type: | Status: assigned
Cleanup/optimization |
Component: Core (Management | Version: master
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

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

* has_patch: 0 => 1
* stage: Unreviewed => Ready for checkin


Comment:

The [https://github.com/django/django/pull/8096 PR] looks good.

--
Ticket URL: <https://code.djangoproject.com/ticket/27870#comment:2>

Django

unread,
Feb 22, 2017, 9:16:04 AM2/22/17
to django-...@googlegroups.com
#27870: Clean up ManagementUtility.autocomplete()

-------------------------------------+-------------------------------------
Reporter: Phil | Owner: Phil
Type: | Status: closed

Cleanup/optimization |
Component: Core (Management | Version: master
commands) |
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"cc5c1b7568ca77d32c8ecdb235f893aef0072f71" cc5c1b75]:
{{{
#!CommitTicketReference repository=""
revision="cc5c1b7568ca77d32c8ecdb235f893aef0072f71"
Fixed #27870 -- Cleaned up ManagementUtility.autocomplete().
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/27870#comment:3>

Reply all
Reply to author
Forward
0 new messages