Skip to content

Refactor: Convert string concatenation to f-strings #469

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions update/cn_loc.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ def group_data(data_collection):
for code, name in sorted(data_collection.items()):
if code.endswith('00'):
continue # county only
province_code = code[:2] + '0000'
prefecture_code = code[:4] + '00'
province_code = f"{code[:2]}0000"
prefecture_code = f"{code[:4]}00"
province_name = data_collection[province_code]
prefecture_name = data_collection[prefecture_code]
yield code, name, prefecture_name, province_name
Expand Down
2 changes: 1 addition & 1 deletion update/iban.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def get_country_codes(line):
bban = bban.replace(' ', '')
cc = data['IBAN prefix country code (ISO 3166)'][:2]
cname = data['Name of country']
if bban.startswith(cc + '2!n'):
if bban.startswith(f"{cc}2!n"):
bban = bban[5:]
# print country line
print('%s country="%s" bban="%s"' % (cc, cname, bban))
Expand Down
17 changes: 3 additions & 14 deletions update/imsi.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,7 @@
remove_ref_re = re.compile(r'<ref>.*?</ref>')
remove_comment_re = re.compile(r'{{.*?}}')
quotes = u'\xab\xbb\u201c\u201d\u2018\u2019'
remove_href_re = re.compile(r'(?i)\b((?:https?://|www\d{0,3}[.]|[a-z0-9.\-]+' +
r'[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|' +
r'(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|' +
r'(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:\'".,<>' +
r'?' + quotes + ']))')
remove_href_re = re.compile("(?i)\b((?:https?://|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|"+|'}(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|"+|'}(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:\'".,<>"<>'}?"'?' + quotes}]))")


def cleanup_value(val):
Expand Down Expand Up @@ -138,14 +134,7 @@ def cleanup_value(val):
# This matches a line containing a MCC/MNC, e.g.
# | 232 || 02 || || A1 Telekom Austria || Reserved || ||
_mnc_line_re = re.compile(
r'^\|\s*(?P<mcc>[0-9]+)' +
r'\s*\\\\\s*(?P<mnc>[0-9]+)' +
r'(\s*\\\\\s*(?P<brand>[^\\]*)' +
r'(\s*\\\\\s*(?P<operator>[^\\]*)' +
r'(\s*\\\\\s*(?P<status>[^\\]*)' +
r'(\s*\\\\\s*(?P<bands>[^\\]*)' +
r'(\s*\\\\\s*(?P<notes>[^\\]*)' +
r')?)?)?)?)?')
"^\|\s*(?P<mcc>[0-9]+)\s*\\\\\s*(?P<mnc>[0-9]+)"+)'}(\s*\\\\\s*(?P<brand>[^\\]*)"*)'}(\s*\\\\\s*(?P<operator>[^\\]*)"*)'}(\s*\\\\\s*(?P<status>[^\\]*)"*)'}(\s*\\\\\s*(?P<bands>[^\\]*)"*)'}(\s*\\\\\s*(?P<notes>[^\\]*)"*)'})?)?)?)?)?")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this makes the code more readable. The original regex already has some readability issues but at least the splitting over multiple lines tries to make it a little better readable.

Also flake8 gives some errors.



def get_mncs_from_wikipedia():
Expand Down Expand Up @@ -187,7 +176,7 @@ def str2range(x):
for part in x.split(','):
if '-' in part:
a, b = part.split('-')
f = '%0' + str(len(b)) + 'd'
f = f'%0{str(len(b))}'b))}d"
a, b = int(a), int(b)
for i in range(a, b + 1):
result.append(f % (i))
Expand Down
Loading