add some more type hinting

This commit is contained in:
Laura Klünder 2017-05-09 13:16:36 +02:00
parent 39a6104d7a
commit 2da1bf0bd5
2 changed files with 5 additions and 6 deletions

View file

@ -15,9 +15,9 @@ validate_bssid_lines = RegexValidator(regex=r'^([0-9a-f]{2}(:[0-9a-f]{2}){5}(\r?
message=_('please enter a newline seperated lowercase list of BSSIDs'))
def validate_geometry(geometry):
def validate_geometry(geometry: BaseGeometry):
if not isinstance(geometry, BaseGeometry):
raise ValidationError('GeometryField expexted a Shapely BaseGeometry child-class.')
raise ValidationError('GeometryField expected a Shapely BaseGeometry child-class.')
if not geometry.is_valid:
raise ValidationError('Invalid geometry: %s' % validation.explain_validity(geometry))

View file

@ -2,7 +2,6 @@ from collections import OrderedDict
from shapely.geometry import Point, mapping
from c3nav.mapdata.fields import GeometryField
from c3nav.mapdata.models.base import EditorFormMixin
from c3nav.mapdata.utils.json import format_geojson
@ -18,13 +17,13 @@ class GeometryMixin(EditorFormMixin):
class Meta:
abstract = True
def get_geojson_properties(self):
def get_geojson_properties(self) -> dict:
return OrderedDict((
('type', self.__class__.__name__.lower()),
('id', self.id),
))
def to_geojson(self):
def to_geojson(self) -> dict:
return OrderedDict((
('type', 'Feature'),
('properties', self.get_geojson_properties()),
@ -34,5 +33,5 @@ class GeometryMixin(EditorFormMixin):
def get_shadow_geojson(self):
pass
def contains(self, x, y):
def contains(self, x, y) -> bool:
return self.geometry.contains(Point(x, y))