-
-
Notifications
You must be signed in to change notification settings - Fork 120
Fix: Fix Shapely import #584
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -7,16 +7,22 @@ | |||||||||||||||
| """ | ||||||||||||||||
|
|
||||||||||||||||
| from contextlib import contextmanager | ||||||||||||||||
| from typing import TYPE_CHECKING | ||||||||||||||||
|
|
||||||||||||||||
| try: | ||||||||||||||||
| import shapely | ||||||||||||||||
| import shapely.wkb | ||||||||||||||||
| import shapely.wkt | ||||||||||||||||
| from shapely import Geometry as ShapelyGeometry | ||||||||||||||||
| from shapely.wkb import dumps | ||||||||||||||||
|
|
||||||||||||||||
| HAS_SHAPELY = True | ||||||||||||||||
| _shapely_exc = None | ||||||||||||||||
| except ImportError as exc: | ||||||||||||||||
| if not TYPE_CHECKING: | ||||||||||||||||
|
|
||||||||||||||||
| class ShapelyGeometry: | ||||||||||||||||
| """Requires shapely. Install with: pip install geoalchemy2[shapely].""" | ||||||||||||||||
|
Comment on lines
+21
to
+24
|
||||||||||||||||
| if not TYPE_CHECKING: | |
| class ShapelyGeometry: | |
| """Requires shapely. Install with: pip install geoalchemy2[shapely].""" | |
| class ShapelyGeometry: | |
| """Requires shapely. Install with: pip install geoalchemy2[shapely].""" |
Copilot
AI
Feb 20, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change fixes the runtime NameError when Shapely isn't installed, but there’s no test ensuring import geoalchemy2 (or import geoalchemy2.shape) works in an environment without Shapely. Consider adding a regression test that imports/reloads geoalchemy2.shape with Shapely unavailable (e.g., via an import hook or sys.modules patch) so this doesn’t regress again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from shapely import Geometry as ShapelyGeometryis likely incompatible with the Shapely versions this repo supports (tox installsShapely>=1.3.0, and optional deps declareShapely>=1.7). In Shapely 1.x there is no top-levelGeometry, so this will raise ImportError even when Shapely is installed, incorrectly settingHAS_SHAPELY=Falseand breakingto_shape/from_shape. Import the geometry base type fromshapely.geometry.base(e.g.,BaseGeometry) or otherwise use a version-compatible symbol for the annotation without causing the Shapely import block to fail.