mirror of
https://github.com/ansible-collections/community.docker.git
synced 2026-07-29 03:46:55 +00:00
Python code modernization, 5/n (#1165)
* Address raise-missing-from. * Address simplifiable-if-expression. * Address unnecessary-dunder-call. * Address unnecessary-pass. * Address use-list-literal. * Address unused-variable. * Address use-dict-literal.
This commit is contained in:
@@ -107,8 +107,8 @@ def create_archive(root, files=None, fileobj=None, gzip=False, extra_files=None)
|
||||
try:
|
||||
with open(full_path, "rb") as f:
|
||||
t.addfile(i, f)
|
||||
except IOError:
|
||||
raise IOError(f"Can not read file in context: {full_path}")
|
||||
except IOError as exc:
|
||||
raise IOError(f"Can not read file in context: {full_path}") from exc
|
||||
else:
|
||||
# Directories, FIFOs, symlinks... do not need to be read.
|
||||
t.addfile(i, None)
|
||||
|
||||
@@ -85,4 +85,4 @@ def split_buffer(stream, splitter=None, decoder=lambda a: a):
|
||||
try:
|
||||
yield decoder(buffered)
|
||||
except Exception as e:
|
||||
raise StreamParseError(e)
|
||||
raise StreamParseError(e) from e
|
||||
|
||||
@@ -420,10 +420,10 @@ def parse_bytes(s):
|
||||
if suffix in units or suffix.isdigit():
|
||||
try:
|
||||
digits = float(digits_part)
|
||||
except ValueError:
|
||||
except ValueError as exc:
|
||||
raise errors.DockerException(
|
||||
f"Failed converting the string value for memory ({digits_part}) to an integer."
|
||||
)
|
||||
) from exc
|
||||
|
||||
# Reconvert to long for the final result
|
||||
s = int(digits * units[suffix])
|
||||
|
||||
Reference in New Issue
Block a user