Skip to content

Commit

Permalink
pylint: Fix all exception complaints.
Browse files Browse the repository at this point in the history
  • Loading branch information
heinezen committed Jun 30, 2023
1 parent 0e8741c commit 4b85229
Show file tree
Hide file tree
Showing 57 changed files with 380 additions and 384 deletions.
10 changes: 5 additions & 5 deletions buildsystem/codecompliance/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ def parse_args():
help=("check whether all git authors are in copying.md. "
"repo must be a git repository."))
cli.add_argument("--cppstyle", action="store_true",
help=("check the cpp code style"))
help="check the cpp code style")
cli.add_argument("--cython", action="store_true",
help=("check if cython is turned off"))
help="check if cython is turned off")
cli.add_argument("--headerguards", action="store_true",
help="check all header guards")
cli.add_argument("--legal", action="store_true",
Expand All @@ -40,7 +40,7 @@ def parse_args():
help=("check whether files in the repo have the "
"correct access bits (-> 0644) "))
cli.add_argument("--pylint", action="store_true",
help=("run pylint on the python code"))
help="run pylint on the python code")
cli.add_argument("--pystyle", action="store_true",
help=("check whether the python code complies with "
"(a selected subset of) pep8."))
Expand All @@ -51,7 +51,7 @@ def parse_args():
"copyright year matches the git history."))

cli.add_argument("--fix", action="store_true",
help=("try to automatically fix the found issues"))
help="try to automatically fix the found issues")

cli.add_argument("-v", "--verbose", action="count", default=0,
help="increase program verbosity")
Expand Down Expand Up @@ -140,7 +140,7 @@ def get_changed_files(gitref):
file_list = subprocess.check_output(invocation)

except subprocess.CalledProcessError as exc:
raise Exception(
raise SyntaxError(
"could not determine list of recently-changed files with git"
) from exc

Expand Down
4 changes: 2 additions & 2 deletions buildsystem/codecompliance/authors.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2014-2022 the openage authors. See copying.md for legal info.
# Copyright 2014-2023 the openage authors. See copying.md for legal info.

"""
Checks whether all authors are properly listed in copying.md.
Expand Down Expand Up @@ -49,7 +49,7 @@ def get_author_emails_copying_md():

if not any(email.startswith(prefix) for prefix in ("E-Mail", "-" * 15))\
and '@' not in email:
raise Exception(f"no @ or à was found in email: {email}")
raise ValueError(f"no @ or à was found in email: {email}")

yield email

Expand Down
4 changes: 2 additions & 2 deletions buildsystem/codecompliance/legal.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2014-2022 the openage authors. See copying.md for legal info.
# Copyright 2014-2023 the openage authors. See copying.md for legal info.

"""
Checks the legal headers of all files.
Expand Down Expand Up @@ -115,7 +115,7 @@ def year_fix_function():
)

if not success:
raise Exception("copyright year fix did not suceeed")
raise ValueError("copyright year fix did not suceeed")

writefile(filename, fixed_file)

Expand Down
4 changes: 2 additions & 2 deletions buildsystem/codecompliance/util.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2014-2022 the openage authors. See copying.md for legal info.
# Copyright 2014-2023 the openage authors. See copying.md for legal info.

"""
Some utilities.
Expand Down Expand Up @@ -93,7 +93,7 @@ def writefile(filename, new_content):
writes the file and update it in the cache.
"""
if filename in BADUTF8FILES:
raise Exception(f"{filename}: cannot write due to utf8-errors.")
raise ValueError(f"{filename}: cannot write due to utf8-errors.")

with open(filename, 'w', encoding='utf8') as fileobj:
fileobj.write(new_content)
Expand Down
2 changes: 1 addition & 1 deletion buildsystem/pxdgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def handle_state_3(self, token, val, namespace_parts):
state = transitions[state](self, token, val, namespace_parts)

except KeyError as exp:
raise Exception("reached invalid state in pxdgen") from exp
raise ValueError("reached invalid state in pxdgen") from exp

if self.stack:
raise self.parser_error("expected '}', but found EOF")
Expand Down
6 changes: 3 additions & 3 deletions openage/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2013-2022 the openage authors. See copying.md for legal info.
# Copyright 2013-2023 the openage authors. See copying.md for legal info.

"""
The Python part of openage, a free engine re-write of
Expand All @@ -13,8 +13,8 @@

from .log import setup_logging

if py_version < (3, 6):
raise Exception("openage requires python 3.6 or higher.")
if py_version < (3, 9):
raise RuntimeError("openage requires python 3.9 or higher.")


try:
Expand Down
14 changes: 7 additions & 7 deletions openage/cabextract/cab.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2015-2022 the openage authors. See copying.md for legal info.
# Copyright 2015-2023 the openage authors. See copying.md for legal info.

"""
Provides CABFile, an extractor for the MSCAB format.
Expand Down Expand Up @@ -239,8 +239,8 @@ def __init__(self, cab: FileLikeObject):

# verify magic number
if header.signature != b"MSCF":
raise Exception("invalid CAB file signature: " +
repr(header.signature))
raise SyntaxError("invalid CAB file signature: " +
repr(header.signature))

# read reserve header, if present
if header.flags.reserve_present:
Expand Down Expand Up @@ -326,10 +326,10 @@ def read_folder_headers(self, cab: FileLikeObject) -> Generator[CFFolder, None,
folder.plain_stream = compressed_data_stream

elif compression_type == 1:
raise Exception("MSZIP compression is unsupported")
raise SyntaxError("MSZIP compression is unsupported")

elif compression_type == 2:
raise Exception("Quantum compression is unsupported")
raise SyntaxError("Quantum compression is unsupported")

elif compression_type == 3:
window_bits = (folder.typeCompress >> 8) & 0x1f
Expand All @@ -346,7 +346,7 @@ def read_folder_headers(self, cab: FileLikeObject) -> Generator[CFFolder, None,
folder.plain_stream = StreamSeekBuffer(unseekable_plain_stream)

else:
raise Exception(f"Unknown compression type {compression_type:d}")
raise SyntaxError(f"Unknown compression type {compression_type:d}")

dbg(folder)
yield folder
Expand Down Expand Up @@ -397,7 +397,7 @@ def read_file_headers(self, cab: FileLikeObject) -> Generator[CFFile, None, None
day = (fileobj.date >> 0) & 0x001f

# it's sort of sad that there's no bit for AM/PM.
hour = (fileobj.time >> 11)
hour = fileobj.time >> 11
minute = (fileobj.time >> 5) & 0x003f
sec = (fileobj.time << 1) & 0x003f

Expand Down
12 changes: 6 additions & 6 deletions openage/codegen/coord.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2016-2021 the openage authors. See copying.md for legal info.
# Copyright 2016-2023 the openage authors. See copying.md for legal info.

"""
Generates libopenage/coord/coord_{xy, xyz, ne_se, ne_se_up}.{h, cpp}
Expand Down Expand Up @@ -49,11 +49,11 @@ def format_members(formatstring, join_with=", "):
"""
return join_with.join(formatstring.format(m) for m in member_list)

template_dict = dict(
members=member_list,
formatted_members=format_members,
camelcase="".join(member.title() for member in member_list),
)
template_dict = {
"members": member_list,
"formatted_members": format_members,
"camelcase": "".join(member.title() for member in member_list),
}

for template, output_filename_template in templates:
output_filename = output_filename_template.render(template_dict)
Expand Down
3 changes: 3 additions & 0 deletions openage/convert/entity_object/conversion/aoc/genie_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ def contains_creatable(self, line_id: int) -> bool:
elif isinstance(self, GenieBuildingLineGroup):
line = self.data.unit_lines[line_id]

else:
raise ValueError(f"Unknown creatable line ID {line_id} for {repr(self)}")

return line in self.creates

def contains_entity(self, unit_id: int) -> bool:
Expand Down
32 changes: 16 additions & 16 deletions openage/convert/entity_object/conversion/converter_object.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019-2022 the openage authors. See copying.md for legal info.
# Copyright 2019-2023 the openage authors. See copying.md for legal info.

# pylint: disable=too-many-instance-attributes,too-many-branches,too-few-public-methods

Expand Down Expand Up @@ -54,7 +54,7 @@ def __init__(
self.members.update(members)

else:
raise Exception("members must be an instance of ValueMember")
raise TypeError("members must be an instance of ValueMember")

def get_id(self) -> typing.Union[str, int]:
"""
Expand Down Expand Up @@ -104,7 +104,7 @@ def short_diff(self, other: ConverterObject) -> ConverterObject:
that are different. It does not contain NoDiffMembers.
"""
if type(self) is not type(other):
raise Exception(f"type {type(self)} cannot be diffed with type {type(other)}")
raise TypeError(f"type {type(self)} cannot be diffed with type {type(other)}")

obj_diff = {}

Expand All @@ -121,7 +121,7 @@ def diff(self, other: ConverterObject) -> ConverterObject:
Returns the obj_diff between two objects as another ConverterObject.
"""
if type(self) is not type(other):
raise Exception(f"type {type(self)} cannot be diffed with type {type(other)}")
raise TypeError(f"type {type(self)} cannot be diffed with type {type(other)}")

obj_diff = {}

Expand Down Expand Up @@ -228,13 +228,13 @@ def check_readiness(self) -> None:
for raw_api_object in self.raw_api_objects.values():
if not raw_api_object.is_ready():
if not raw_api_object.nyan_object:
raise Exception(f"{raw_api_object}: object is not ready for export: "
"Nyan object not initialized.")
raise ValueError(f"{raw_api_object}: object is not ready for export: "
"Nyan object not initialized.")

uninit_members = raw_api_object.get_nyan_object().get_uninitialized_members()
concat_names = ", ".join(f"'{member.get_name()}'" for member in uninit_members)
raise Exception(f"{raw_api_object}: object is not ready for export: "
f"Member(s) {concat_names} not initialized.")
raise ValueError(f"{raw_api_object}: object is not ready for export: "
f"Member(s) {concat_names} not initialized.")

def execute_raw_member_pushs(self) -> None:
"""
Expand All @@ -255,8 +255,8 @@ def get_raw_api_object(self, obj_id: RawAPIObject) -> RawAPIObject:
return self.raw_api_objects[obj_id]

except KeyError as missing_raw_api_obj:
raise Exception(f"{repr(self)}: Could not find raw API object "
"with obj_id {obj_id}") from missing_raw_api_obj
raise KeyError(f"{repr(self)}: Could not find raw API object "
"with obj_id {obj_id}") from missing_raw_api_obj

def get_raw_api_objects(self) -> dict[str, RawAPIObject]:
"""
Expand Down Expand Up @@ -418,8 +418,8 @@ def extend_raw_member(
break

else:
raise Exception(f"{repr(self)}: Cannot extend raw member {name} "
f"with origin {origin}: member not found")
raise ValueError(f"{repr(self)}: Cannot extend raw member {name} "
f"with origin {origin}: member not found")

def create_nyan_object(self) -> None:
"""
Expand All @@ -442,8 +442,8 @@ def create_nyan_members(self) -> None:
The nyan object has to be created before this function can be called.
"""
if self.nyan_object is None:
raise Exception(f"{repr(self)}: nyan object needs to be created before "
"member values can be assigned")
raise RuntimeError(f"{repr(self)}: nyan object needs to be created before "
"member values can be assigned")

for raw_member in self.raw_members:
member_name = raw_member[0]
Expand All @@ -470,7 +470,7 @@ def link_patch_target(self) -> None:
Set the target NyanObject for a patch.
"""
if not self.is_patch():
raise Exception(f"Cannot link patch target: {self} is not a patch")
raise TypeError(f"Cannot link patch target: {self} is not a patch")

if isinstance(self._patch_target, ForwardRef):
target = self._patch_target.resolve()
Expand Down Expand Up @@ -529,7 +529,7 @@ def get_nyan_object(self) -> NyanObject:
if self.nyan_object:
return self.nyan_object

raise Exception(f"nyan object for {self} has not been created yet")
raise RuntimeError(f"nyan object for {self} has not been created yet")

def is_ready(self) -> bool:
"""
Expand Down
8 changes: 4 additions & 4 deletions openage/convert/entity_object/conversion/modpack.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020-2022 the openage authors. See copying.md for legal info.
# Copyright 2020-2023 the openage authors. See copying.md for legal info.

"""
Defines a modpack that can be exported.
Expand Down Expand Up @@ -38,7 +38,7 @@ def add_data_export(self, export_file: DataDefinition) -> None:
Add a data file to the modpack for exporting.
"""
if not isinstance(export_file, DataDefinition):
raise Exception(f"{repr(self)}: export file must be of type DataDefinition "
raise TypeError(f"{repr(self)}: export file must be of type DataDefinition "
f"not {type(export_file)}")

self.data_export_files.append(export_file)
Expand All @@ -48,7 +48,7 @@ def add_media_export(self, export_request: MediaExportRequest) -> None:
Add a media export request to the modpack.
"""
if not isinstance(export_request, MediaExportRequest):
raise Exception(f"{repr(self)}: export file must be of type MediaExportRequest "
raise TypeError(f"{repr(self)}: export file must be of type MediaExportRequest "
f"not {type(export_request)}")

if export_request.get_type() in self.media_export_files:
Expand All @@ -62,7 +62,7 @@ def add_metadata_export(self, export_file: MetadataExport) -> None:
Add a metadata file to the modpack for exporting.
"""
if not isinstance(export_file, MetadataExport):
raise Exception(f"{repr(self)}: export file must be of type MetadataExport "
raise TypeError(f"{repr(self)}: export file must be of type MetadataExport "
f"not {type(export_file)}")

self.metadata_files.append(export_file)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2021-2022 the openage authors. See copying.md for legal info.
# Copyright 2021-2023 the openage authors. See copying.md for legal info.

"""
Blendtable definition file.
Expand Down Expand Up @@ -98,8 +98,8 @@ def _check_table(self) -> typing.Union[None, typing.NoReturn]:
table_width = self._get_table_width()

if table_width * table_width != len(self.blendtable):
raise Exception(f"blendtable entries malformed: "
f"{len(self.blendtable)} is not an integer square")
raise ValueError(f"blendtable entries malformed: "
f"{len(self.blendtable)} is not an integer square")

def __repr__(self):
return f'BlendtableMetadata<{self.filename}>'
6 changes: 3 additions & 3 deletions openage/convert/entity_object/export/formats/modpack_info.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020-2022 the openage authors. See copying.md for legal info.
# Copyright 2020-2023 the openage authors. See copying.md for legal info.
#
# pylint: disable=too-many-instance-attributes,too-many-arguments

Expand Down Expand Up @@ -219,10 +219,10 @@ def dump(self) -> str:

# info table
if not self.packagename:
raise Exception(f"{self}: packagename needs to be defined before dumping.")
raise RuntimeError(f"{self}: packagename needs to be defined before dumping.")

if not self.version:
raise Exception(f"{self}: version needs to be defined before dumping.")
raise RuntimeError(f"{self}: version needs to be defined before dumping.")

info_table = {"info": {}}
info_table["info"].update(
Expand Down
4 changes: 2 additions & 2 deletions openage/convert/entity_object/export/formats/nyan_file.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019-2022 the openage authors. See copying.md for legal info.
# Copyright 2019-2023 the openage authors. See copying.md for legal info.

"""
Nyan file struct that stores a bunch of objects and
Expand Down Expand Up @@ -51,7 +51,7 @@ def add_nyan_object(self, new_object: NyanObject) -> None:
Adds a nyan object to the file.
"""
if not isinstance(new_object, NyanObject):
raise Exception(f"nyan file cannot contain non-nyan object {new_object}")
raise TypeError(f"nyan file cannot contain non-nyan object {new_object}")

self.nyan_objects.add(new_object)

Expand Down
2 changes: 1 addition & 1 deletion openage/convert/entity_object/export/texture.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def __init__(
for tile in input_data.alphamasks
]
else:
raise Exception("cannot create Texture "
raise TypeError("cannot create Texture "
"from unknown source type: %s" % (type(input_data)))

def _to_subtextures(
Expand Down
Loading

0 comments on commit 4b85229

Please sign in to comment.