#25225: Unnecessary/Redundant __iter__ method with ListMixin class
(contrib.gis.geos.mutable_list.py)?
-------------------------------------+-------------------------------------
     Reporter:  bixb0012             |                    Owner:  nobody
         Type:                       |                   Status:  new
  Cleanup/optimization               |
    Component:  GIS                  |                  Version:  1.8
     Severity:  Normal               |               Resolution:
     Keywords:  __iter__ geos gis    |             Triage Stage:
  ListMixin                          |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  1                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by timgraham):

 * needs_docs:   => 0
 * needs_tests:   => 0
 * needs_better_patch:   => 0


Old 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.

New 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.

--

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

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/066.ffa92809dc6ffe82db5c19edc6f52fce%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to