@@ -903,9 +903,9 @@ def format_by_pattern(numobj, number_format, user_defined_formats):
903903 # replacements for different numbers have the appropriate national
904904 # prefix.
905905 np_formatting_rule = formatting_pattern .national_prefix_formatting_rule
906- if ( np_formatting_rule is not None and len ( np_formatting_rule ) > 0 ) :
906+ if np_formatting_rule :
907907 national_prefix = metadata .national_prefix
908- if ( national_prefix is not None and len ( national_prefix ) > 0 ) :
908+ if national_prefix :
909909 # Replace $NP with national prefix and $FG with the first
910910 # group (\1) matcher.
911911 np_formatting_rule = re .sub (_NP_PATTERN ,
@@ -1218,8 +1218,7 @@ def format_in_original_format(numobj, region_calling_from):
12181218 # If no digit is inserted/removed/modified as a result of our formatting,
12191219 # we return the formatted phone number; otherwise we return the raw input
12201220 # the user entered.
1221- if (formatted_number is not None and
1222- num_raw_input is not None and len (num_raw_input ) > 0 ):
1221+ if (formatted_number is not None and num_raw_input ):
12231222 normalized_formatted_number = _normalize_diallable_chars_only (formatted_number )
12241223 normalized_raw_input = _normalize_diallable_chars_only (num_raw_input )
12251224 if normalized_formatted_number != normalized_raw_input :
@@ -1418,7 +1417,7 @@ def format_out_of_country_keeping_alpha_chars(numobj, region_calling_from):
14181417 metadata_for_region ,
14191418 PhoneNumberFormat .INTERNATIONAL ,
14201419 num_raw_input )
1421- if i18n_prefix_for_formatting is not None and len ( i18n_prefix_for_formatting ) > 0 :
1420+ if i18n_prefix_for_formatting :
14221421 formatted_number = (i18n_prefix_for_formatting + U_SPACE +
14231422 unicod (country_code ) + U_SPACE + formatted_number )
14241423 else :
@@ -1447,7 +1446,7 @@ def national_significant_number(numobj):
14471446 # If leading zero(s) have been set, we prefix this now. Note this is not a
14481447 # national prefix.
14491448 national_number = U_EMPTY_STRING
1450- if numobj .italian_leading_zero is not None and numobj . italian_leading_zero :
1449+ if numobj .italian_leading_zero :
14511450 num_zeros = numobj .number_of_leading_zeros
14521451 if num_zeros is None :
14531452 num_zeros = 1
@@ -1515,10 +1514,8 @@ def _format_nsn_using_pattern(national_number, formatting_pattern, number_format
15151514 m_re = re .compile (formatting_pattern .pattern )
15161515 formatted_national_number = U_EMPTY_STRING
15171516
1518- if (number_format == PhoneNumberFormat .NATIONAL and
1519- carrier_code is not None and len (carrier_code ) > 0 and
1520- formatting_pattern .domestic_carrier_code_formatting_rule is not None and
1521- len (formatting_pattern .domestic_carrier_code_formatting_rule ) > 0 ):
1517+ if (number_format == PhoneNumberFormat .NATIONAL and carrier_code and
1518+ formatting_pattern .domestic_carrier_code_formatting_rule ):
15221519 # Replace the $CC in the formatting rule with the desired
15231520 # carrier code.
15241521 cc_format_rule = formatting_pattern .domestic_carrier_code_formatting_rule
@@ -1539,8 +1536,7 @@ def _format_nsn_using_pattern(national_number, formatting_pattern, number_format
15391536 # Use the national prefix formatting rule instead.
15401537 national_prefix_formatting_rule = formatting_pattern .national_prefix_formatting_rule
15411538 if (number_format == PhoneNumberFormat .NATIONAL and
1542- national_prefix_formatting_rule is not None and
1543- len (national_prefix_formatting_rule ) > 0 ):
1539+ national_prefix_formatting_rule ):
15441540 first_group_rule = re .sub (_FIRST_GROUP_PATTERN ,
15451541 national_prefix_formatting_rule ,
15461542 number_format_rule ,
@@ -1721,7 +1717,7 @@ def _maybe_append_formatted_extension(numobj, metadata, num_format, number):
17211717 """Appends the formatted extension of a phone number to formatted number,
17221718 if the phone number had an extension specified.
17231719 """
1724- if ( numobj .extension is not None and len ( numobj . extension ) > 0 ) :
1720+ if numobj .extension :
17251721 if num_format == PhoneNumberFormat .RFC3966 :
17261722 return number + _RFC3966_EXTN_PREFIX + numobj .extension
17271723 else :
0 commit comments