Skip to content

Commit

Permalink
Merge branch 'DimitriPapadopoulos-pyupgrade'
Browse files Browse the repository at this point in the history
  • Loading branch information
martinblech committed Oct 8, 2024
2 parents ec7d5b6 + 5b1b511 commit efe6060
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 11 deletions.
11 changes: 5 additions & 6 deletions ez_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def _build_egg(egg, archive_filename, to_dir):
# returning the result
log.warn(egg)
if not os.path.exists(egg):
raise IOError('Could not build the egg.')
raise OSError('Could not build the egg.')


class ContextualZipFile(zipfile.ZipFile):
Expand All @@ -92,7 +92,7 @@ def __new__(cls, *args, **kwargs):
"""Construct a ZipFile or ContextualZipFile as appropriate."""
if hasattr(zipfile.ZipFile, '__exit__'):
return zipfile.ZipFile(*args, **kwargs)
return super(ContextualZipFile, cls).__new__(cls)
return super().__new__(cls)


@contextlib.contextmanager
Expand Down Expand Up @@ -131,7 +131,7 @@ def archive_context(filename):

def _do_download(version, download_base, to_dir, download_delay):
"""Download Setuptools."""
py_desig = 'py{sys.version_info[0]}.{sys.version_info[1]}'.format(sys=sys)
py_desig = f'py{sys.version_info[0]}.{sys.version_info[1]}'
tp = f'setuptools-{version}-{py_desig}.egg'
egg = os.path.join(to_dir, tp.format(**locals()))
if not os.path.exists(egg):
Expand Down Expand Up @@ -245,8 +245,7 @@ def download_file_powershell(url, target):
ps_cmd = (
"[System.Net.WebRequest]::DefaultWebProxy.Credentials = "
"[System.Net.CredentialCache]::DefaultCredentials; "
'(new-object System.Net.WebClient).DownloadFile("%(url)s", "%(target)s")'
% locals()
'(new-object System.Net.WebClient).DownloadFile("{url}", "{target}")'.format(**locals())
)
cmd = [
'powershell',
Expand Down Expand Up @@ -346,7 +345,7 @@ def download_setuptools(
"""
# making sure we use the absolute path
to_dir = os.path.abspath(to_dir)
zip_name = "setuptools-%s.zip" % version
zip_name = f"setuptools-{version}.zip"
url = download_base + zip_name
saveto = os.path.join(to_dir, zip_name)
if not os.path.exists(saveto): # Avoid repeated downloads
Expand Down
2 changes: 0 additions & 2 deletions tests/test_dicttoxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,6 @@ def test_non_string_attr(self):
self.assertEqual('<a attr="1"></a>', _strip(unparse(obj)))

def test_short_empty_elements(self):
if sys.version_info[0] < 3:
return
obj = {'a': None}
self.assertEqual('<a/>', _strip(unparse(obj, short_empty_elements=True)))

Expand Down
4 changes: 2 additions & 2 deletions tests/test_xmltodict.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,14 @@ def test_unicode(self):
except NameError:
value = chr(39321)
self.assertEqual({'a': value},
parse('<a>%s</a>' % value))
parse(f'<a>{value}</a>'))

def test_encoded_string(self):
try:
value = unichr(39321)
except NameError:
value = chr(39321)
xml = '<a>%s</a>' % value
xml = f'<a>{value}</a>'
self.assertEqual(parse(xml),
parse(xml.encode('utf-8')))

Expand Down
2 changes: 1 addition & 1 deletion xmltodict.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ def _emit(key, value, content_handler,
attr_prefix)
if ik == '@xmlns' and isinstance(iv, dict):
for k, v in iv.items():
attr = 'xmlns{}'.format(':{}'.format(k) if k else '')
attr = 'xmlns{}'.format(f':{k}' if k else '')
attrs[attr] = str(v)
continue
if not isinstance(iv, str):
Expand Down

0 comments on commit efe6060

Please sign in to comment.