Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
StefanBrand opened this issue Jan 23, 2023 · 2 comments · Fixed by #1335
Closed

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

StefanBrand opened this issue Jan 23, 2023 · 2 comments · Fixed by #1335
Labels
bug Something isn't working regression Behavior has changed for worse with a release stubs Issues in stubs files (.pyi)

Comments

@StefanBrand
Copy link

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
@StefanBrand StefanBrand added the bug Something isn't working label Jan 23, 2023
@intgr intgr added stubs Issues in stubs files (.pyi) regression Behavior has changed for worse with a release labels Jan 23, 2023
@intgr
Copy link
Collaborator

intgr commented Jan 23, 2023

Related PR: #1299

@ciscorn
Copy link
Contributor

ciscorn commented Jan 23, 2023

@StefanBrand @intgr
Thank you for reporting. I've made a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working regression Behavior has changed for worse with a release stubs Issues in stubs files (.pyi)
Development

Successfully merging a pull request may close this issue.

3 participants