From 3525b83c6bb7cd0c676e2ebc23c2be614e16e2cb Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 8 Oct 2024 09:41:53 +1100 Subject: [PATCH] Cleanup: use specific exception types where appropriate --- doc/python_api/sphinx_changelog_gen.py | 2 +- scripts/modules/bpy_extras/mesh_utils.py | 2 +- scripts/modules/rna_info.py | 2 +- source/blender/makesrna/rna_cleanup/rna_cleaner_merge.py | 6 +----- source/blender/python/rna_dump.py | 2 +- 5 files changed, 5 insertions(+), 9 deletions(-) diff --git a/doc/python_api/sphinx_changelog_gen.py b/doc/python_api/sphinx_changelog_gen.py index 3e262611b40..0440090170e 100644 --- a/doc/python_api/sphinx_changelog_gen.py +++ b/doc/python_api/sphinx_changelog_gen.py @@ -66,7 +66,7 @@ API_F_ARGS = 7 def api_version(): try: import bpy - except: + except ModuleNotFoundError: return None, None version = tuple(bpy.app.version[:2]) version_key = "%d.%d" % (version[0], version[1]) diff --git a/scripts/modules/bpy_extras/mesh_utils.py b/scripts/modules/bpy_extras/mesh_utils.py index 2cfee71f86e..551d205cde4 100644 --- a/scripts/modules/bpy_extras/mesh_utils.py +++ b/scripts/modules/bpy_extras/mesh_utils.py @@ -152,7 +152,7 @@ def edge_face_count_dict(mesh): key = edges[loops[i].edge_index].key try: face_edge_count[key] += 1 - except: + except KeyError: face_edge_count[key] = 1 return face_edge_count diff --git a/scripts/modules/rna_info.py b/scripts/modules/rna_info.py index f5d72297be4..f1409f427ed 100644 --- a/scripts/modules/rna_info.py +++ b/scripts/modules/rna_info.py @@ -645,7 +645,7 @@ def BuildRNAInfo(): def base_id(rna_struct): try: return rna_struct.base.identifier - except: + except AttributeError: return "" # invalid id # structs = [(base_id(rna_struct), rna_struct.identifier, rna_struct) for rna_struct in bpy.doc.structs.values()] diff --git a/source/blender/makesrna/rna_cleanup/rna_cleaner_merge.py b/source/blender/makesrna/rna_cleanup/rna_cleaner_merge.py index cf6e5f496b2..3760090bc63 100755 --- a/source/blender/makesrna/rna_cleanup/rna_cleaner_merge.py +++ b/source/blender/makesrna/rna_cleanup/rna_cleaner_merge.py @@ -30,11 +30,7 @@ def main(): rna_api_new = [] for key, val_orig in mod_to_dict.items(): - try: - val_new = mod_from_dict.pop(key) - except: - # print("not found", key) - val_new = val_orig + val_new = mod_from_dict.pop(key, val_orig) # always take the class from the base val = list(val_orig) diff --git a/source/blender/python/rna_dump.py b/source/blender/python/rna_dump.py index 5f896522650..3a3012756fe 100644 --- a/source/blender/python/rna_dump.py +++ b/source/blender/python/rna_dump.py @@ -119,7 +119,7 @@ for d in dir(bpy.types): t = getattr(bpy.types, d) try: r = t.bl_rna - except: + except AttributeError: r = None if r: seek(r, 'bpy.types.' + d + '.bl_rna', 0)