jazzband / geojson

Python bindings and utilities for GeoJSON
https://pypi.python.org/pypi/geojson/
BSD 3-Clause "New" or "Revised" License
905 stars 120 forks source link

Incorrect Expected Type for Classes with Coordinate Lists #113

Closed ahokinson closed 6 years ago

ahokinson commented 6 years ago

I believe the type hinting is incorrect for classes where coordinates are defined by multiple points.

The documentation indicates that the following code should work.

def geojson_serialize(self):
    return Feature(geometry=LineString(coordinates=[(self.city.longitude, self.city.latitude),
                                                    (self.host.city.longitude, self.host.city.latitude)]),
                   properties={"attack_type": self.attack_type.name,
...

When run, it does seem to work as intended. However, it produces a weak warning: Expected type 'tuple', got 'List[Tuple[Any,Any]]' instead.

Because LineString inherits from MultiPoint which inherits from Geometry, it uses the following constructor.

    def __init__(self, coordinates=None, crs=None, validate=False, **extra):
        """
        Initialises a Geometry object.

        :param coordinates: Coordinates of the Geometry object.
        :type coordinates: tuple
        :param crs: CRS
        :type crs: CRS object
        """

which is incorrect for any MultiPoint coordinates.

Would the use of typing.Union be an appropriate fix here?

I'm willing to submit a PR.