How about adding type hints?
See original GitHub issueAs Shapely currently doesn’t have type hints, results produced by type checkers are far from perfect. Some examples:
from shapely.geometry import Polygon, LineString, Point
area = Polygon().area # Inferred type: Any. Should be: float
geom_type = LineString().geom_type # Inferred type: Union[str, List[str]]
# Should be LineString in this case
representative_point = Polygon().representative_point()
# Inferred type: Union[Polygon, Any]. Should be: Point
x = Point(1, 1).x # Inferred type: Union[object, Tuple[object, object, object], Tuple[object, object]]
# Should be: float
and so on.
So, how about adding stub files with the type hints, at least for the most basic functionality from the docs?
Shapely version: 1.6.4.post1, installed from conda.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:8
- Comments:7 (7 by maintainers)
Top Results From Across the Web
typing — Support for type hints — Python 3.11.1 documentation
This module provides runtime support for type hints. The most fundamental support consists of the types Any , Union , Callable , TypeVar ......
Read more >Type Hinting - Real Python
In this lesson, you'll learn about type hinting in Python. Type hinting is a formal solution to statically indicate the type of a...
Read more >12 Beginner Concepts About Type Hints To Improve Your ...
Type hints are performed using Python annotations (introduced since PEP 3107). They are used to add types to variables, parameters, function arguments as...
Read more >Python Type Hints
Adding type hints for multiple types ... The numbers can be integers or floats. To set type hints for multiple types, you can...
Read more >Type hints cheat sheet - mypy 0.991 documentation
This document is a quick cheat sheet showing how to use type annotations for various common ... Good practice is to add a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I would love to see type annotations in Shapely.
Inline type annotations will be much easier to maintain going forward.
If we want to use the new annotation syntax this will required 3.5 as a minimum version, whereas we currently support 3.4. I don’t know if we’ve agreed this yet?
Type annotations will look like this:
Unless we need to support 3.4, in which case they’d need to be done as comments (not as nice!):
My preference would be to require Python 3.5 for Shapely 1.8.