[Django] #28893: Narrow dict.items() calls to .keys()/.items()

37 views
Skip to first unread message

Django

unread,
Dec 5, 2017, 12:23:59 PM12/5/17
to django-...@googlegroups.com
#28893: Narrow dict.items() calls to .keys()/.items()
------------------------------------------------+------------------------
Reporter: Дилян Палаузов | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Uncategorized | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------------+------------------------


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

Django

unread,
Dec 5, 2017, 12:28:12 PM12/5/17
to django-...@googlegroups.com
#28893: Narrow dict.items() calls to .keys()/.items()
-------------------------------------+-------------------------------------

Reporter: Дилян Палаузов | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Uncategorized | Version: master
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
-------------------------------------+-------------------------------------
Changes (by Дилян Палаузов):

* Attachment "narrow.patch" added.

Django

unread,
Dec 5, 2017, 1:22:13 PM12/5/17
to django-...@googlegroups.com
#28893: Narrow dict.items() calls to .keys()/.items()
--------------------------------------+------------------------------------

Reporter: Дилян Палаузов | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Core (Other) | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Tim Graham):

* needs_better_patch: 0 => 1
* has_patch: 0 => 1
* component: Uncategorized => Core (Other)
* stage: Unreviewed => Accepted


Comment:

`keys()` is generally unneeded. Something like `for name in
tb_frame.f_locals` does an implicit keys; see
21046e77734278cea871dce922220bf29aa5b7b4. I guess you didn't test the
patch as there's at least one mistake in `debug.py` that broke things.

By the way, is there something preventing you from submitting patches on
GitHub? If it's only the knowledge of how to to do, we have
[https://docs.djangoproject.com/en/dev/intro/contributing/#committing-the-
changes-in-the-patch a tutorial].

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

Django

unread,
Dec 5, 2017, 2:00:36 PM12/5/17
to django-...@googlegroups.com
#28893: Narrow dict.items() calls to .keys()/.items()
--------------------------------------+------------------------------------

Reporter: Дилян Палаузов | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Core (Other) | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Sergey Fedoseev):

* cc: Sergey Fedoseev (added)


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

Django

unread,
Dec 6, 2017, 9:26:02 AM12/6/17
to django-...@googlegroups.com
#28893: Narrow dict.items() calls to .keys()/.items()
--------------------------------------+------------------------------------

Reporter: Дилян Палаузов | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Core (Other) | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by Дилян Палаузов):

Yes, it is better not to apply the last snippet in debug.py.

I know that iterating over a {{{dict:}}} and {{{dict.keys():}}} is
effectively the same, but while the later returns (an iterator of) a view,
I don't know what the former returns and therefore whether both forms are
really equivalent.

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

Django

unread,
Dec 6, 2017, 9:39:48 AM12/6/17
to django-...@googlegroups.com
#28893: Narrow dict.items() calls to .keys()/.items()
--------------------------------------+------------------------------------

Reporter: Дилян Палаузов | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Core (Other) | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by Sergey Fedoseev):

Replying to [comment:3 Дилян Палаузов]:


> I know that iterating over a {{{dict:}}} and {{{dict.keys():}}} is
effectively the same, but while the later returns (an iterator of) a view,
I don't know what the former returns and therefore whether both forms are
really equivalent.

{{{
In [2]: iter({})
Out[2]: <dict_keyiterator at 0x7fd09e6d3598>

In [3]: iter({}.keys())
Out[3]: <dict_keyiterator at 0x7fd09e6d3728>
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28893#comment:4>

Django

unread,
Dec 6, 2017, 2:26:02 PM12/6/17
to django-...@googlegroups.com
#28893: Narrow dict.items() calls to .keys()/.items()
--------------------------------------+------------------------------------

Reporter: Дилян Палаузов | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Core (Other) | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

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

* needs_better_patch: 1 => 0


Comment:

[https://github.com/django/django/pull/9437 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/28893#comment:5>

Django

unread,
Dec 6, 2017, 5:18:15 PM12/6/17
to django-...@googlegroups.com
#28893: Narrow dict.items() calls to .keys()/.items()
--------------------------------------+------------------------------------

Reporter: Дилян Палаузов | Owner: nobody
Type: Cleanup/optimization | Status: closed

Component: Core (Other) | Version: master
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by GitHub <noreply@…>):

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


Comment:

In [changeset:"a862af383969ade774f6b0fa1d331bc87b188b89" a862af38]:
{{{
#!CommitTicketReference repository=""
revision="a862af383969ade774f6b0fa1d331bc87b188b89"
Fixed #28893 -- Removed unnecessary dict.items() calls.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28893#comment:6>

Reply all
Reply to author
Forward
0 new messages