Skip to content

Commit

Permalink
Fix flake8 errors from existing code
Browse files Browse the repository at this point in the history
- Use `r` strings to resolve "invalid escape sequence" errors
- Switch string comparison from `is not` to `!=`
- Remove `as e` in `except` clause where `e` isn't used
  • Loading branch information
KlaasH committed Jul 29, 2019
1 parent 353b1d4 commit 1329a86
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
14 changes: 7 additions & 7 deletions omgeo/preprocessors.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ReplaceRangeWithNumber(_PreProcessor):
#: * 789-91
#: * 201A-201B
#: * 201A-B
RE_STREET_NUMBER = re.compile('(^\d+\w*-\d*\w*)\s', re.IGNORECASE)
RE_STREET_NUMBER = re.compile(r'(^\d+\w*-\d*\w*)\s', re.IGNORECASE)

def replace_range(self, addr_str):
match = self.RE_STREET_NUMBER.match(addr_str)
Expand All @@ -67,10 +67,10 @@ class ParseSingleLine(_PreProcessor):
Adapted from `Cicero Live <http://azavea.com/packages/azavea_cicero/blocks/cicero_live/view.js>`_
"""
# Some Regexes:
re_unit_numbered = re.compile('(su?i?te|p\W*[om]\W*b(?:ox)?|(?:ap|dep)(?:ar)?t(?:me?nt)?|ro*m|flo*r?|uni?t|bu?i?ldi?n?g|ha?nga?r|lo?t|pier|slip|spa?ce?|stop|tra?i?le?r|bo?x|no\.?)\s+|#', re.IGNORECASE)
re_unit_not_numbered = re.compile('ba?se?me?n?t|fro?nt|lo?bby|lowe?r|off?i?ce?|pe?n?t?ho?u?s?e?|rear|side|uppe?r', re.IGNORECASE)
re_UK_postcode = re.compile('[A-Z]{1,2}[0-9R][0-9A-Z]? *[0-9][A-Z]{0,2}', re.IGNORECASE)
re_blank = re.compile('\s')
re_unit_numbered = re.compile(r'(su?i?te|p\W*[om]\W*b(?:ox)?|(?:ap|dep)(?:ar)?t(?:me?nt)?|ro*m|flo*r?|uni?t|bu?i?ldi?n?g|ha?nga?r|lo?t|pier|slip|spa?ce?|stop|tra?i?le?r|bo?x|no\.?)\s+|#', re.IGNORECASE)
re_unit_not_numbered = re.compile(r'ba?se?me?n?t|fro?nt|lo?bby|lowe?r|off?i?ce?|pe?n?t?ho?u?s?e?|rear|side|uppe?r', re.IGNORECASE)
re_UK_postcode = re.compile(r'[A-Z]{1,2}[0-9R][0-9A-Z]? *[0-9][A-Z]{0,2}', re.IGNORECASE)
re_blank = re.compile(r'\s')

def _comma_join(self, left, right):
if left == '':
Expand All @@ -94,7 +94,7 @@ def process(self, pq):

query_parts = [part.strip() for part in pq.query.split(',')]

if postcode is not '' and re.search(postcode, query_parts[0]):
if postcode != '' and re.search(postcode, query_parts[0]):
# if postcode is in the first part of query_parts, there are probably no commas
# get just the part before the postcode
part_before_postcode = query_parts[0].split(postcode)[0].strip()
Expand All @@ -107,7 +107,7 @@ def process(self, pq):

for part in query_parts[1:]:
part = part.strip()
if postcode is not '' and re.search(postcode, part) is not None:
if postcode != '' and re.search(postcode, part) is not None:
part = part.replace(postcode, '').strip() # if postcode is in part, remove it

if self.re_unit_numbered.search(part) is not None:
Expand Down
5 changes: 2 additions & 3 deletions omgeo/services/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,8 @@ def _get_response(self, endpoint, query, is_post=False):
else:
response = requests.get(
endpoint, params=query, headers=headers, timeout=timeout_secs)
except requests.exceptions.Timeout as e:
raise Exception(
'API request timed out after %s seconds.' % timeout_secs)
except requests.exceptions.Timeout:
raise Exception('API request timed out after %s seconds.' % timeout_secs)
except Exception as e:
raise e

Expand Down
8 changes: 4 additions & 4 deletions omgeo/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,10 @@ def test_geocode_karori(self):
True, 'Could not find bldg. no. "102" and postcode "6012" in any address.')

def _test_address_components(self, candidate):
for field in ['match_streetaddr', 'match_city', 'match_subregion', 'match_region',
'match_postal', 'match_country']:
self.assertIsNotNone(getattr(candidate, field, None),
msg='Missing address component %s' % field)
for field in ['match_streetaddr', 'match_city', 'match_subregion', 'match_region',
'match_postal', 'match_country']:
self.assertIsNotNone(getattr(candidate, field, None),
msg='Missing address component %s' % field)

def _test_geocode_results_all_(self, verbosity=0, geocoder=Geocoder(),
expected_results=16):
Expand Down

0 comments on commit 1329a86

Please sign in to comment.