Skip to content

Commit

Permalink
Fix all flake8 errors
Browse files Browse the repository at this point in the history
  • Loading branch information
KostyaEsmukov committed May 16, 2018
1 parent 4fca371 commit 80ddcc4
Show file tree
Hide file tree
Showing 31 changed files with 135 additions and 128 deletions.
6 changes: 3 additions & 3 deletions geopy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
PyPy3. geopy does not and will not support CPython 2.6.
"""

from geopy.location import Location
from geopy.point import Point
from geopy.util import __version__
from geopy.location import Location # noqa
from geopy.point import Point # noqa
from geopy.util import __version__ # noqa

from geopy.geocoders import * # noqa
# geopy.geocoders.options must not be importable as `geopy.options`,
Expand Down
50 changes: 24 additions & 26 deletions geopy/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,34 @@

py3k = sys.version_info >= (3, 0)

if py3k: # pragma: no cover
if py3k: # pragma: no cover
string_compare = str
else: # pragma: no cover
string_compare = (str, unicode)
else: # pragma: no cover
string_compare = (str, unicode) # noqa

if py3k: # pragma: no cover
text_type = str
else: # pragma: no cover
text_type = unicode
text_type = unicode # noqa

# Unicode compatibility, borrowed from 'six'
if py3k: # pragma: no cover
if py3k: # pragma: no cover
def u(s):
"""
Convert to Unicode with py3k
"""
return s
else: # pragma: no cover
else: # pragma: no cover
def u(s):
"""
Convert to Unicode with unicode escaping
"""
return unicode(s.replace(r'\\', r'\\\\'), 'unicode_escape')
return unicode(s.replace(r'\\', r'\\\\'), 'unicode_escape') # noqa

if py3k:
if py3k: # pragma: no cover
def cmp(a, b):
return (a > b) - (a < b)
else:
else: # pragma: no cover
cmp = cmp # builtin in py2


Expand All @@ -48,15 +48,12 @@ def isfinite(x):
return not isinf(x) and not isnan(x)


if py3k: # pragma: no cover
from urllib.parse import (urlencode, quote,
urlparse, parse_qs)
from urllib.request import (Request, urlopen,
build_opener, ProxyHandler, HTTPSHandler,
URLError,
HTTPPasswordMgrWithDefaultRealm,
HTTPBasicAuthHandler)
if py3k: # pragma: no cover
from urllib.error import HTTPError
from urllib.parse import parse_qs, quote, urlencode, urlparse
from urllib.request import (HTTPBasicAuthHandler, HTTPPasswordMgrWithDefaultRealm,
HTTPSHandler, ProxyHandler, Request, URLError,
build_opener, urlopen)

def itervalues(d):
"""
Expand All @@ -65,6 +62,7 @@ def itervalues(d):
For Python2
"""
return iter(d.values())

def iteritems(d):
"""
Function for iterating on items due to methods
Expand All @@ -73,20 +71,19 @@ def iteritems(d):
"""
return iter(d.items())

else: # pragma: no cover
from urllib import urlencode as original_urlencode, quote
from urllib2 import (Request, HTTPError,
ProxyHandler, HTTPSHandler, URLError, urlopen,
build_opener,
HTTPPasswordMgrWithDefaultRealm,
HTTPBasicAuthHandler)
from urlparse import urlparse, parse_qs
else: # pragma: no cover
from urllib import quote # noqa
from urllib import urlencode as original_urlencode
from urllib2 import (HTTPBasicAuthHandler, HTTPError, # noqa
HTTPPasswordMgrWithDefaultRealm, HTTPSHandler, ProxyHandler,
Request, URLError, build_opener, urlopen)
from urlparse import parse_qs, urlparse # noqa

def force_str(str_or_unicode):
"""
Python2-only, ensures that a string is encoding to a str.
"""
if isinstance(str_or_unicode, unicode):
if isinstance(str_or_unicode, unicode): # noqa
return str_or_unicode.encode('utf-8')
else:
return str_or_unicode
Expand Down Expand Up @@ -115,6 +112,7 @@ def itervalues(d):
For Python3
"""
return d.itervalues()

def iteritems(d):
"""
Function for iterating on items due to methods
Expand Down
28 changes: 18 additions & 10 deletions geopy/distance.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,14 @@
from __future__ import division

import warnings
from math import atan, tan, sin, cos, pi, sqrt, atan2, asin
from geopy.units import radians
from math import asin, atan, atan2, cos, pi, sin, sqrt, tan

from geographiclib.geodesic import Geodesic

from geopy import units, util
from geopy.compat import cmp, py3k, string_compare
from geopy.point import Point
from geopy.compat import string_compare, py3k, cmp
from geographiclib.geodesic import Geodesic
from geopy.units import radians

# IUGG mean earth radius in kilometers, from
# https://en.wikipedia.org/wiki/Earth_radius#Mean_radius. Using a
Expand Down Expand Up @@ -203,10 +205,10 @@ def measure(self, a, b):
"""
raise NotImplementedError()

def __repr__(self): # pragma: no cover
def __repr__(self): # pragma: no cover
return 'Distance(%s)' % self.kilometers

def __str__(self): # pragma: no cover
def __str__(self): # pragma: no cover
return '%s km' % self.__kilometers

def __cmp__(self, other): # py2 only
Expand Down Expand Up @@ -274,6 +276,7 @@ def nautical(self):
def nm(self):
return self.nautical


class great_circle(Distance):
"""
Use spherical geometry to calculate the surface distance between two
Expand Down Expand Up @@ -344,8 +347,10 @@ def destination(self, point, bearing, distance=None):

return Point(units.degrees(radians=lat2), units.degrees(radians=lng2))


GreatCircleDistance = great_circle


class geodesic(Distance):
"""
Calculate the geodesic distance between two points.
Expand Down Expand Up @@ -411,8 +416,8 @@ def measure(self, a, b):
self.geod.f == self.ELLIPSOID[2]):
self.geod = Geodesic(self.ELLIPSOID[0], self.ELLIPSOID[2])

s12 = self.geod.Inverse(lat1, lon1, lat2, lon2,
Geodesic.DISTANCE)['s12']
s12 = self.geod.Inverse(lat1, lon1, lat2, lon2,
Geodesic.DISTANCE)['s12']

return s12

Expand Down Expand Up @@ -440,8 +445,10 @@ def destination(self, point, bearing, distance=None):

return Point(r['lat2'], r['lon2'])


GeodesicDistance = geodesic


class vincenty(Distance):
"""
.. deprecated:: 1.13
Expand Down Expand Up @@ -543,7 +550,7 @@ def measure(self, a, b):
)

if sin_sigma == 0:
return 0 # Coincident points
return 0 # Coincident points

cos_sigma = (
sin_reduced1 * sin_reduced2 +
Expand All @@ -562,7 +569,7 @@ def measure(self, a, b):
sin_reduced1 * sin_reduced2 / cos_sq_alpha
)
else:
cos2_sigma_m = 0.0 # Equatorial line
cos2_sigma_m = 0.0 # Equatorial line

C = f / 16. * cos_sq_alpha * (4 + f * (4 - 3 * cos_sq_alpha))

Expand Down Expand Up @@ -692,6 +699,7 @@ def destination(self, point, bearing, distance=None):

return Point(units.degrees(radians=lat2), units.degrees(radians=lng2))


VincentyDistance = vincenty

# Set the default distance formula
Expand Down
4 changes: 4 additions & 0 deletions geopy/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
'arcsec': ABBR_ARCSEC
}


def format_degrees(degrees, fmt=DEGREES_FORMAT, symbols=None):
"""
TODO docs.
Expand All @@ -79,6 +80,7 @@ def format_degrees(degrees, fmt=DEGREES_FORMAT, symbols=None):
)
return fmt % format_dict


DISTANCE_FORMAT = "%(magnitude)s%(unit)s"
DISTANCE_UNITS = {
'km': lambda d: d,
Expand All @@ -89,13 +91,15 @@ def format_degrees(degrees, fmt=DEGREES_FORMAT, symbols=None):
'nmi': lambda d: units.nautical(kilometers=d)
}


def format_distance(kilometers, fmt=DISTANCE_FORMAT, unit='km'):
"""
TODO docs.
"""
magnitude = DISTANCE_UNITS[unit](kilometers)
return fmt % {'magnitude': magnitude, 'unit': unit}


_DIRECTIONS = [
('north', 'N'),
('north by east', 'NbE'),
Expand Down
3 changes: 2 additions & 1 deletion geopy/geocoders/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@
>>> geolocator = GoogleV3(format_string="%s, Cleveland OH")
>>> address, (latitude, longitude) = geolocator.geocode("11111 Euclid Ave")
>>> print(address, latitude, longitude)
Thwing Center, 11111 Euclid Ave, Cleveland, OH 44106, USA 41.5074066 -81.60832649999999
Thwing Center, 11111 Euclid Ave, Cleveland, OH 44106, USA \
41.5074066 -81.60832649999999
"""

Expand Down
5 changes: 2 additions & 3 deletions geopy/geocoders/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
)
from geopy.util import decode_page, __version__


__all__ = (
"Geocoder",
"options",
Expand Down Expand Up @@ -205,10 +204,10 @@ def _coerce_point_to_string(point):
if isinstance(point, Point):
return ",".join((str(point.latitude), str(point.longitude)))
elif isinstance(point, (list, tuple)):
return ",".join((str(point[0]), str(point[1]))) # -altitude
return ",".join((str(point[0]), str(point[1]))) # -altitude
elif isinstance(point, string_compare):
return point
else: # pragma: no cover
else:
raise ValueError("Invalid point")

def _geocoder_exception_handler(self, error, message):
Expand Down
4 changes: 1 addition & 3 deletions geopy/geocoders/googlev3.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,7 @@ def _format_components_param(components):
Format the components dict to something Google understands.
"""
return "|".join(
(":".join(item)
for item in components.items()
)
(":".join(item) for item in components.items())
)

@staticmethod
Expand Down
3 changes: 1 addition & 2 deletions geopy/geocoders/ignfrance.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ def __init__(

# Catch if no api key with username and password
# or no api key with referer
if not (api_key and username and password) \
and not (api_key and referer):
if not ((api_key and username and password) or (api_key and referer)):
raise ConfigurationError('You should provide an api key and a '
'username with a password or an api '
'key with a referer depending on '
Expand Down
4 changes: 2 additions & 2 deletions geopy/geocoders/openmapquest.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ def __init__(
if not api_key:
raise ConfigurationError('OpenMapQuest requires an API key')
self.api_key = api_key
self.api = "%s://open.mapquestapi.com/nominatim/v1/search" \
"?format=json" % self.scheme
self.api = ("%s://open.mapquestapi.com/nominatim/v1/search"
"?format=json" % self.scheme)

def geocode(self, query, exactly_one=True, timeout=DEFAULT_SENTINEL):
"""
Expand Down
1 change: 0 additions & 1 deletion geopy/geocoders/pickpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
PickPoint geocoder
"""

from geopy.compat import urlencode
from geopy.geocoders import Nominatim
from geopy.geocoders.base import DEFAULT_SENTINEL

Expand Down
3 changes: 1 addition & 2 deletions geopy/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,5 @@ def __eq__(self, other):
def __ne__(self, other):
return not (self == other)

def __len__(self): # pragma: no cover
def __len__(self):
return len(self._tuple)

8 changes: 4 additions & 4 deletions geopy/point.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
import collections
import re
import warnings
from math import fmod
from itertools import islice
from math import fmod

from geopy import util, units
from geopy.format import (
DEGREE,
Expand All @@ -18,7 +19,6 @@
)
from geopy.compat import string_compare, isfinite


POINT_PATTERN = re.compile(r"""
.*?
(?P<latitude>
Expand Down Expand Up @@ -163,7 +163,7 @@ def __new__(cls, latitude=None, longitude=None, altitude=None):
else:
try:
seq = iter(arg)
except TypeError: # pragma: no cover
except TypeError:
raise TypeError(
"Failed to create Point instance from %r." % (arg,)
)
Expand Down Expand Up @@ -314,7 +314,7 @@ def parse_altitude(cls, distance, unit):
}
try:
return CONVERTERS[unit](distance)
except KeyError: # pragma: no cover
except KeyError:
raise NotImplementedError(
'Bad distance unit specified, valid are: %r' %
CONVERTERS.keys()
Expand Down

0 comments on commit 80ddcc4

Please sign in to comment.