Opened 9 years ago
Last modified 7 years ago
#25225 closed Cleanup/optimization
Unnecessary/Redundant __iter__ method with ListMixin class (contrib.gis.geos.mutable_list.py)? — at Initial Version
Reported by: | Joshua Bixby | Owned by: | nobody |
---|---|---|---|
Component: | GIS | Version: | 1.8 |
Severity: | Normal | Keywords: | __iter__ geos gis ListMixin |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
The ListMixin class (contrib.gis.geos.mutable_list.py) currently has an iter method and getitem method. Typically iteration is implemented using one or the other, not both. Looking at the two methods, the iter method appears to be unnecessary since the Python interpreter will use getitem to iterate if iter is not present. Also, stepping through code appears to have iter call getitem, which raises the question of why define an iter method when the interpreter can use getitem directly.
Currently, getitem can't be used properly for iteration because of the custom IndexError raised in the _checkindex method. Switching from raising a django.contrib.gis.geos.error.GEOSIndexError exception to a exceptions.IndexError will allow for the interpreter to use getitem for iteration, which would allow removing the unnecessary or redundant iter method.