From 5f640457d880cdaa38831400b366ba4d8a10b10e Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 4 Jan 2025 21:17:29 +1100 Subject: [PATCH] Cleanup: suppress various pylint warnings --- source/blender/nodes/intern/discover_nodes.py | 2 +- source/blender/python/rna_dump.py | 2 +- tools/utils/autopep8_clean_config.py | 5 --- tools/utils/git_log_review_commits.py | 1 + .../utils/git_log_review_commits_advanced.py | 4 +-- tools/utils_ide/project_info.py | 2 +- tools/utils_maintenance/clang_format_paths.py | 31 +++++++++---------- 7 files changed, 21 insertions(+), 26 deletions(-) diff --git a/source/blender/nodes/intern/discover_nodes.py b/source/blender/nodes/intern/discover_nodes.py index 7279c8509dc..2af4ed81fb7 100644 --- a/source/blender/nodes/intern/discover_nodes.py +++ b/source/blender/nodes/intern/discover_nodes.py @@ -112,7 +112,7 @@ def main() -> int: try: with open(output_cc_file, "r", encoding="utf-8") as fh: old_generated_code = fh.read() - except: + except Exception: old_generated_code = "" new_generated_code = "\n".join(include_lines + decl_lines + [""] + func_lines) diff --git a/source/blender/python/rna_dump.py b/source/blender/python/rna_dump.py index 3a3012756fe..8f0da121c54 100644 --- a/source/blender/python/rna_dump.py +++ b/source/blender/python/rna_dump.py @@ -51,7 +51,7 @@ def seek(r, txt, recurs): print(txt + ' -> ' + str(r)) return - if type_r == str: + if type_r is str: if PRINT_DATA: print(txt + ' -> "' + str(r) + '"') return diff --git a/tools/utils/autopep8_clean_config.py b/tools/utils/autopep8_clean_config.py index cd848a2b86c..5cb04c180cb 100644 --- a/tools/utils/autopep8_clean_config.py +++ b/tools/utils/autopep8_clean_config.py @@ -10,11 +10,6 @@ __all__ = ( import os -from collections.abc import ( - Callable, - Iterator, -) - PATHS: tuple[str, ...] = ( "build_files", "doc", diff --git a/tools/utils/git_log_review_commits.py b/tools/utils/git_log_review_commits.py index 354f81bd47b..f5c9c637514 100755 --- a/tools/utils/git_log_review_commits.py +++ b/tools/utils/git_log_review_commits.py @@ -57,6 +57,7 @@ class _GetchWindows: def __init__(self): import msvcrt + del msvcrt def __call__(self): import msvcrt diff --git a/tools/utils/git_log_review_commits_advanced.py b/tools/utils/git_log_review_commits_advanced.py index 05e3f4ac784..a1bd376728a 100755 --- a/tools/utils/git_log_review_commits_advanced.py +++ b/tools/utils/git_log_review_commits_advanced.py @@ -78,10 +78,9 @@ class _GetchUnix: def __init__(self): import tty - import sys + del tty def __call__(self): - import sys import tty import termios fd = sys.stdin.fileno() @@ -98,6 +97,7 @@ class _GetchWindows: def __init__(self): import msvcrt + del msvcrt def __call__(self): import msvcrt diff --git a/tools/utils_ide/project_info.py b/tools/utils_ide/project_info.py index 9be072acc73..ae095442292 100755 --- a/tools/utils_ide/project_info.py +++ b/tools/utils_ide/project_info.py @@ -171,7 +171,7 @@ def cmake_advanced_info() -> ( # Enable to check on nicer XML. use_pretty_xml = False if use_pretty_xml: - with open(".cproject_pretty", 'w') as fh: + with open(".cproject_pretty", 'w', encoding="utf-8") as fh: fh.write(tree.toprettyxml(indent=" ", newl="")) ELEMENT_NODE = tree.ELEMENT_NODE diff --git a/tools/utils_maintenance/clang_format_paths.py b/tools/utils_maintenance/clang_format_paths.py index 8bf22b1c98a..9b9011da858 100755 --- a/tools/utils_maintenance/clang_format_paths.py +++ b/tools/utils_maintenance/clang_format_paths.py @@ -104,23 +104,22 @@ def convert_tabs_to_spaces(files: Sequence[str]) -> None: print("TabExpand", f) with open(f, 'r', encoding="utf-8") as fh: data = fh.read() - if False: - # Simple 4 space - data = data.expandtabs(4) - else: - # Complex 2 space - # because some comments have tabs for alignment. - def handle(l: str) -> str: - ls = l.lstrip("\t") - d = len(l) - len(ls) - if d != 0: - return (" " * d) + ls.expandtabs(4) - else: - return l.expandtabs(4) + # Simple 4 space (but we're using 2 spaces). + # `data = data.expandtabs(4)` - lines = data.splitlines(keepends=True) - lines = [handle(l) for l in lines] - data = "".join(lines) + # Complex 2 space + # because some comments have tabs for alignment. + def handle(l: str) -> str: + ls = l.lstrip("\t") + d = len(l) - len(ls) + if d != 0: + return (" " * d) + ls.expandtabs(4) + else: + return l.expandtabs(4) + + lines = data.splitlines(keepends=True) + lines = [handle(l) for l in lines] + data = "".join(lines) with open(f, 'w', encoding="utf-8") as fh: fh.write(data)