Opened 3 years ago

Last modified 3 years ago

#32971 closed Cleanup/optimization

Internal Field.check() methods don't need to construct and return lists — at Version 1

Reported by: Chris Jerdonek Owned by: nobody
Component: Core (System checks) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Chris Jerdonek)

I noticed that many of the internal "check()" methods used by Field subclasses return lists (including the empty list) when they can just yield items (or yield nothing). This is because the concrete check() implementations unpack the return value when constructing a new list. See here for one example of such a check() method: https://github.com/django/django/blob/f331eba6d576752dd79c4b37c41d981daa537fe6/django/db/models/fields/__init__.py#L196-L205

The proposed change, then, would be to change methods like the following to yield their items instead of creating and returning a list: https://github.com/django/django/blob/f331eba6d576752dd79c4b37c41d981daa537fe6/django/db/models/fields/__init__.py#L243-L254

It looks like there are 23 methods in that file with a name starting with _check....

Change History (1)

comment:1 by Chris Jerdonek, 3 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top