Skip to content

Commit 59d35e3

Browse files
committed
Simplify conditions with get and getattr optional arguments
1 parent 28c909c commit 59d35e3

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

tools/targets/__init__.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -385,17 +385,15 @@ def get_post_build_hook(self, toolchain_labels):
385385
# "class_name" must refer to a class in this file, so check if the
386386
# class exists
387387
mdata = self.get_module_data()
388-
if class_name not in mdata or \
389-
not inspect.isclass(mdata[class_name]):
388+
if not inspect.isclass(mdata.get(class_name, None)):
390389
raise HookError(
391390
("Class '%s' required by '%s' in target '%s'"
392391
% (class_name, hook_data["function"], self.name)) +
393392
" not found in targets.py")
394393
# "function_name" must refer to a static function inside class
395394
# "class_name"
396395
cls = mdata[class_name]
397-
if (not hasattr(cls, function_name)) or \
398-
(not inspect.isfunction(getattr(cls, function_name))):
396+
if not inspect.isfunction(getattr(cls, function_name, None)):
399397
raise HookError(
400398
("Static function '%s' " % function_name) +
401399
("required by '%s' " % hook_data["function"]) +

0 commit comments

Comments
 (0)