Skip to content

Commit 59e72d8

Browse files
committed
PEP8 fixes
1 parent 1c70eff commit 59e72d8

5 files changed

Lines changed: 50 additions & 51 deletions

File tree

python/phonenumbers/phonenumbermatcher.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -149,25 +149,25 @@ def _limit(lower, upper):
149149
# Note that if there is a match, we will always check any text found up to the
150150
# first match as well.
151151
_INNER_MATCHES = (
152-
# Breaks on the slash - e.g. "651-234-2345/332-445-1234"
153-
re.compile(u("/+(.*)")),
154-
# Note that the bracket here is inside the capturing group, since we
155-
# consider it part of the phone number. Will match a pattern like "(650)
156-
# 223 3345 (754) 223 3321".
157-
re.compile(u("(\\([^(]*)")),
158-
# Breaks on a hyphen - e.g. "12345 - 332-445-1234 is my number." We
159-
# require a space on either side of the hyphen for it to be considered a
160-
# separator.
161-
re.compile(u("(?u)(?:\\p{Z}-|-\\s)\\s*(.+)")),
162-
# Various types of wide hyphens. Note we have decided not to enforce a
163-
# space here, since it's possible that it's supposed to be used to break
164-
# two numbers without spaces, and we haven't seen many instances of it
165-
# used within a number.
166-
re.compile(u("(?u)[\u2012-\u2015\uFF0D]\\s*(.+)")),
167-
# Breaks on a full stop - e.g. "12345. 332-445-1234 is my number."
168-
re.compile(u("(?u)\\.+\\s*([^.]+)")),
169-
# Breaks on space - e.g. "3324451234 8002341234"
170-
re.compile(u("(?u)\\s+(\\S+)")))
152+
# Breaks on the slash - e.g. "651-234-2345/332-445-1234"
153+
re.compile(u("/+(.*)")),
154+
# Note that the bracket here is inside the capturing group, since we
155+
# consider it part of the phone number. Will match a pattern like "(650)
156+
# 223 3345 (754) 223 3321".
157+
re.compile(u("(\\([^(]*)")),
158+
# Breaks on a hyphen - e.g. "12345 - 332-445-1234 is my number." We
159+
# require a space on either side of the hyphen for it to be considered a
160+
# separator.
161+
re.compile(u("(?u)(?:\\p{Z}-|-\\s)\\s*(.+)")),
162+
# Various types of wide hyphens. Note we have decided not to enforce a
163+
# space here, since it's possible that it's supposed to be used to break
164+
# two numbers without spaces, and we haven't seen many instances of it
165+
# used within a number.
166+
re.compile(u("(?u)[\u2012-\u2015\uFF0D]\\s*(.+)")),
167+
# Breaks on a full stop - e.g. "12345. 332-445-1234 is my number."
168+
re.compile(u("(?u)\\.+\\s*([^.]+)")),
169+
# Breaks on space - e.g. "3324451234 8002341234"
170+
re.compile(u("(?u)\\s+(\\S+)")))
171171

172172

173173
class Leniency(object):
@@ -309,7 +309,7 @@ def _all_number_groups_are_exactly_present(numobj, normalized_candidate, formatt
309309
"""
310310
candidate_groups = re.split(NON_DIGITS_PATTERN, normalized_candidate)
311311
# Set this to the last group, skipping it if the number has an extension.
312-
if numobj.extension != None:
312+
if numobj.extension is not None:
313313
candidate_number_group_index = len(candidate_groups) - 2
314314
else:
315315
candidate_number_group_index = len(candidate_groups) - 1

python/phonenumbers/phonenumberutil.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@
165165
# Put (lower letter -> upper letter) and
166166
# (upper letter -> upper letter) mappings.
167167
**dict([(_c.lower(), _c) for _c in _ALPHA_MAPPINGS.keys()] +
168-
[(_c, _c) for _c in _ALPHA_MAPPINGS.keys()],
168+
[(_c, _c) for _c in _ALPHA_MAPPINGS.keys()],
169169
**_ASCII_DIGITS_MAP))
170170

171171
# Pattern that makes it easy to distinguish whether a region has a unique
@@ -1256,7 +1256,7 @@ def _has_formatting_pattern_for_number(numobj):
12561256
return False
12571257
national_number = national_significant_number(numobj)
12581258
format_rule = choose_formatting_pattern_for_number(metadata.number_format, national_number)
1259-
return format_rule != None
1259+
return format_rule is not None
12601260

12611261

12621262
def format_out_of_country_keeping_alpha_chars(numobj, region_calling_from):

python/tests/geocodertest.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -86,41 +86,41 @@ def testGetDescriptionForNumberWithNoDataFile(self):
8686
# No data file containing mappings for US numbers is available in Chinese for the unittests. As
8787
# a result, the country name of United States in simplified Chinese is returned.
8888
self.assertEqual(u("\u7F8E\u56FD"),
89-
description_for_number(US_NUMBER1, _CHINESE, region=_CHINA))
89+
description_for_number(US_NUMBER1, _CHINESE, region=_CHINA))
9090
self.assertEqual("Bahamas",
91-
description_for_number(BS_NUMBER1, _ENGLISH, region=_USA))
91+
description_for_number(BS_NUMBER1, _ENGLISH, region=_USA))
9292
self.assertEqual("Australia",
93-
description_for_number(AU_NUMBER, _ENGLISH, region=_USA))
93+
description_for_number(AU_NUMBER, _ENGLISH, region=_USA))
9494
self.assertEqual("",
95-
description_for_number(NUMBER_WITH_INVALID_COUNTRY_CODE, _ENGLISH, region=_USA))
95+
description_for_number(NUMBER_WITH_INVALID_COUNTRY_CODE, _ENGLISH, region=_USA))
9696
self.assertEqual("",
97-
description_for_number(INTERNATIONAL_TOLL_FREE, _ENGLISH, region=_USA))
97+
description_for_number(INTERNATIONAL_TOLL_FREE, _ENGLISH, region=_USA))
9898

9999
def testGetDescriptionForNumberWithMissingPrefix(self):
100100
# Test that the name of the country is returned when the number passed in
101101
# is valid but not covered by the geocoding data file.
102102
self.assertEqual("United States",
103-
description_for_number(US_NUMBER4, _ENGLISH, region=_USA))
103+
description_for_number(US_NUMBER4, _ENGLISH, region=_USA))
104104

105105
def testGetDescriptionForNumber_en_US(self):
106106
self.assertEqual("CA",
107-
description_for_number(US_NUMBER1, _ENGLISH, region=_USA))
107+
description_for_number(US_NUMBER1, _ENGLISH, region=_USA))
108108
self.assertEqual("Mountain View, CA",
109-
description_for_number(US_NUMBER2, _ENGLISH, region=_USA))
109+
description_for_number(US_NUMBER2, _ENGLISH, region=_USA))
110110
self.assertEqual("New York, NY",
111-
description_for_number(US_NUMBER3, _ENGLISH, region=_USA))
111+
description_for_number(US_NUMBER3, _ENGLISH, region=_USA))
112112

113113
def testGetDescriptionForKoreanNumber(self):
114114
self.assertEqual("Seoul",
115-
description_for_number(KO_NUMBER1, _ENGLISH))
115+
description_for_number(KO_NUMBER1, _ENGLISH))
116116
self.assertEqual("Incheon",
117-
description_for_number(KO_NUMBER2, _ENGLISH))
117+
description_for_number(KO_NUMBER2, _ENGLISH))
118118
self.assertEqual("Jeju",
119-
description_for_number(KO_NUMBER3, _ENGLISH))
119+
description_for_number(KO_NUMBER3, _ENGLISH))
120120
self.assertEqual(u("\uC11C\uC6B8"),
121-
description_for_number(KO_NUMBER1, _KOREAN))
121+
description_for_number(KO_NUMBER1, _KOREAN))
122122
self.assertEqual(u("\uC778\uCC9C"),
123-
description_for_number(KO_NUMBER2, _KOREAN))
123+
description_for_number(KO_NUMBER2, _KOREAN))
124124

125125
def testGetDescriptionForArgentinianMobileNumber(self):
126126
self.assertEqual("La Plata", description_for_number(AR_MOBILE_NUMBER, _ENGLISH))
@@ -134,16 +134,16 @@ def testGetDescriptionForFallBack(self):
134134
# No fallback, as the location name for the given phone number is
135135
# available in the requested language.
136136
self.assertEqual("Kalifornien",
137-
description_for_number(US_NUMBER1, _GERMAN))
137+
description_for_number(US_NUMBER1, _GERMAN))
138138
# German falls back to English.
139139
self.assertEqual("New York, NY",
140-
description_for_number(US_NUMBER3, _GERMAN))
140+
description_for_number(US_NUMBER3, _GERMAN))
141141
# Italian falls back to English.
142142
self.assertEqual("CA",
143-
description_for_number(US_NUMBER1, _ITALIAN))
143+
description_for_number(US_NUMBER1, _ITALIAN))
144144
# Korean doesn't fall back to English.
145145
self.assertEqual(u("\uB300\uD55C\uBBFC\uAD6D"),
146-
description_for_number(KO_NUMBER3, _KOREAN))
146+
description_for_number(KO_NUMBER3, _KOREAN))
147147

148148
def testGetDescriptionForNumberWithUserRegion(self):
149149
# User in Italy, American number. We should just show United States, in

python/tests/phonenumbermatchertest.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,7 @@ def __str__(self):
137137
]
138138

139139
# Strings with number-like things that should only be found under "possible".
140-
POSSIBLE_ONLY_CASES = [ # US numbers cannot start with 7 in the test metadata to be valid.
141-
NumberTest("7121115678", "US"),
140+
POSSIBLE_ONLY_CASES = [NumberTest("7121115678", "US"), # US numbers cannot start with 7 in the test metadata to be valid.
142141
# 'X' should not be found in numbers at leniencies stricter than POSSIBLE, unless it represents
143142
# a carrier code or extension.
144143
NumberTest("1650 x 253 - 1234", "US"),
@@ -904,7 +903,7 @@ def findValidInContext(self, number, defaultCountry):
904903
NumberContext("Call me on 21.6. at ", ""),
905904
# With a number Month/Day/Year date.
906905
NumberContext("Call me on 06/21/84 at ", ""),
907-
]
906+
]
908907
self.doTestInContext(number, defaultCountry, contextPairs, Leniency.VALID)
909908

910909
def doTestInContext(self, number, defaultCountry, contextPairs, leniency):
@@ -922,9 +921,9 @@ def doTestInContext(self, number, defaultCountry, contextPairs, leniency):
922921

923922
extracted = text[match.start:match.end]
924923
self.assertEqual(start, match.start,
925-
msg="Unexpected phone region in '" + text + "'; extracted '" + extracted + "'")
924+
msg="Unexpected phone region in '" + text + "'; extracted '" + extracted + "'")
926925
self.assertEqual(end, match.end,
927-
msg="Unexpected phone region in '" + text + "'; extracted '" + extracted + "'")
926+
msg="Unexpected phone region in '" + text + "'; extracted '" + extracted + "'")
928927
self.assertEqual(number, extracted)
929928
self.assertEqual(match.raw_string, extracted)
930929

python/tests/phonenumberutiltest.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ def testFormatWithPreferredCarrierCode(self):
618618
# Python version extra test: check string conversion with preferred carrier code
619619
self.assertEqual('Country Code: 54 National Number: 91234125678 '
620620
'Leading Zero(s): False Preferred Domestic Carrier Code: 19',
621-
str(arNumber))
621+
str(arNumber))
622622
self.assertEqual("PhoneNumber(country_code=54, national_number=91234125678, extension=None, "
623623
"italian_leading_zero=False, number_of_leading_zeros=None, "
624624
"country_code_source=None, preferred_domestic_carrier_code='19')",
@@ -2183,12 +2183,12 @@ def testParseAndKeepRaw(self):
21832183
country_code_source=CountryCodeSource.FROM_NUMBER_WITHOUT_PLUS_SIGN,
21842184
preferred_domestic_carrier_code="")
21852185
self.assertEqual(shorterAlphaNumber,
2186-
phonenumbers.parse("1800 six-flag", "US", keep_raw_input=True))
2186+
phonenumbers.parse("1800 six-flag", "US", keep_raw_input=True))
21872187

21882188
shorterAlphaNumber.raw_input = "+1800 six-flag"
21892189
shorterAlphaNumber.country_code_source = CountryCodeSource.FROM_NUMBER_WITH_PLUS_SIGN
21902190
self.assertEqual(shorterAlphaNumber,
2191-
phonenumbers.parse("+1800 six-flag", "NZ", keep_raw_input=True))
2191+
phonenumbers.parse("+1800 six-flag", "NZ", keep_raw_input=True))
21922192

21932193
shorterAlphaNumber.raw_input = "001800 six-flag"
21942194
shorterAlphaNumber.country_code_source = CountryCodeSource.FROM_NUMBER_WITH_IDD
@@ -2607,7 +2607,7 @@ def testMetadataAsString(self):
26072607
leading_digits='123',
26082608
leading_zero_possible=True,
26092609
short_data=True)""",
2610-
str(metadataXX))
2610+
str(metadataXX))
26112611

26122612
# Coverage test: invalid example number for region
26132613
PhoneMetadata._region_metadata['XX'] = metadataXX
@@ -2640,7 +2640,7 @@ def testMetadataAsString(self):
26402640
national_prefix_for_parsing='0',
26412641
number_format=[NumberFormat(pattern='(\\d{4})(\\d{3})(\\d{3})', format='\\1 \\2 \\3', leading_digits_pattern=['1'], national_prefix_formatting_rule='\\1'),
26422642
NumberFormat(pattern='(\\d{1})(\\d{4})(\\d{4})', format='\\1 \\2 \\3', leading_digits_pattern=['[2-478]'], national_prefix_formatting_rule='0\\1')])""",
2643-
str(metadata))
2643+
str(metadata))
26442644

26452645
def testMetadataEval(self):
26462646
# Python version extra tests for string conversions
@@ -2670,7 +2670,7 @@ def testCoverage(self):
26702670
# Python version extra tests
26712671
self.assertTrue(phonenumberutil._region_code_for_number_from_list(GB_NUMBER, ("XX",)) is None)
26722672
self.assertEqual((0, "abcdef"),
2673-
phonenumberutil._extract_country_code("abcdef"))
2673+
phonenumberutil._extract_country_code("abcdef"))
26742674
metadata = PhoneMetadata.metadata_for_region("AU")
26752675
number = PhoneNumber()
26762676
self.assertEqual((0, u("")),

0 commit comments

Comments
 (0)