Skip to content

"OGRGeometry" has no attribute "__iter__" (not iterable) #1333

@StefanBrand

Description

@StefanBrand

Bug report

What's wrong

Iterating on the return type of Layer.get_geoms throws:

"OGRGeometry" has no attribute "__iter__" (not iterable)

I think these lines are wrong:

@overload
def get_geoms(self, geos: Literal[True] = ...) -> OGRGeometry: ...
@overload
def get_geoms(self, geos: Literal[False]) -> GEOSGeometry: ...

How is that should be

>>> type(layer.get_geoms())
<class 'list'>
>>> type(layer.get_geoms()[0])
<class 'django.contrib.gis.gdal.geometries.Polygon'>
>>> type(layer.get_geoms(geos=True)[0])
<class 'django.contrib.gis.geos.polygon.Polygon'>

I think the type definitions should be as follows (mind also the switched geos parameter):

    @overload
    def get_geoms(self, geos: Literal[False] = ...) -> list[OGRGeometry]: ...
    @overload
    def get_geoms(self, geos: Literal[True]) -> list[GEOSGeometry]: ...

What do you think, @ciscorn?

System information

  • OS: Docker image python:3.9.16-bullseye
  • python version: 3.9.16
  • django version: 4.1.4
  • mypy version: 0-991
  • django-stubs version: 1.13.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingregressionBehavior has changed for worse with a releasestubsIssues in stubs files (.pyi)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions