question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How about adding type hints?

See original GitHub issue

As 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:closed
  • Created 4 years ago
  • Reactions:8
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

9reactions
snorfalorpaguscommented, May 26, 2019

I would love to see type annotations in Shapely.

3reactions
snorfalorpaguscommented, May 29, 2019

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:

def nearest_points(g1: Geometry, g2: Geometry) -> Tuple[Geometry, Geometry]:

Unless we need to support 3.4, in which case they’d need to be done as comments (not as nice!):

def nearest_points(g1, g2): # type: (Geometry, Geometry) -> Tuple[Geometry, Geometry]

My preference would be to require Python 3.5 for Shapely 1.8.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found