Cleanup: quiet Python linter warnings

This commit is contained in:
Campbell Barton
2024-12-11 11:26:24 +11:00
parent 560b6e2831
commit a7bc3e3418
25 changed files with 49 additions and 38 deletions

View File

@@ -229,7 +229,7 @@ class DNACatalogHTML:
return structure_field
def indent(self, input, dent, startswith=''):
def indent(self, input, dent):
output = ''
if dent < 0:
for line in input.split('\n'):

View File

@@ -15,7 +15,7 @@ def main():
import bpy
from bpy.types import Operator
def dummy_func(test):
def dummy_func(_test):
pass
kw_dummy = dict(fget=dummy_func, fset=dummy_func, fdel=dummy_func)

View File

@@ -45,6 +45,6 @@ class RestrictBlend:
_bpy.data = _data_restrict
_bpy.context = _context_restrict
def __exit__(self, type, value, traceback):
def __exit__(self, _type, _value, _traceback):
_bpy.data = self.data
_bpy.context = self.context

View File

@@ -31,7 +31,7 @@ class _TempModuleOverride:
self.module = sys.modules.get(self.module_name)
sys.modules[self.module_name] = self.module_override
def __exit__(self, type, value, traceback):
def __exit__(self, _type, _value, _traceback):
if self.module is None:
# Account for removal of `module_override` (albeit unlikely).
sys.modules.pop(self.module_name, None)

View File

@@ -99,7 +99,7 @@ _node_categories = {}
def register_node_categories(identifier, cat_list):
if identifier in _node_categories:
raise KeyError("Node categories list '{:s}' already registered".format(identifier))
return
# return
# works as draw function for menus
def draw_node_item(self, context):

View File

@@ -350,7 +350,7 @@ def xml2rna(
# print(elems)
if len(elems) == 1:
# sub node named by its type
child_xml_real, = elems
child_xml_real = elems[0]
# print(child_xml_real, subvalue)
xml2rna_node(child_xml_real, subvalue)

View File

@@ -392,7 +392,7 @@ class UpdateAnimatedTransformConstraint(Operator):
to_paths = {"to_max_x", "to_max_y", "to_max_z", "to_min_x", "to_min_y", "to_min_z"}
paths = from_paths | to_paths
def update_cb(base, class_name, old_path, fcurve, options):
def update_cb(base, _class_name, old_path, fcurve, options):
# print(options)
def handle_deg2rad(fcurve):

View File

@@ -174,7 +174,7 @@ class POSE_OT_selection_set_assign(_PoseModeOnlyMixin, Operator):
bl_description = "Add selected bones to Selection Set"
bl_options = {'UNDO', 'REGISTER'}
def invoke(self, context, event):
def invoke(self, context, _event):
arm = context.object
if not (arm.active_selection_set < len(arm.selection_sets)):

View File

@@ -217,7 +217,7 @@ def align_uv_rotation_island(bm, uv_layer, faces, method, axis, aspect_y):
return True
def align_uv_rotation_bmesh(mesh, bm, method, axis, aspect_y):
def align_uv_rotation_bmesh(bm, method, axis, aspect_y):
import bpy_extras.bmesh_utils
uv_layer = bm.loops.layers.uv.active
@@ -260,7 +260,7 @@ def align_uv_rotation(context, method, axis, correct_aspect):
for ob in ob_list:
bm = bmesh.from_edit_mesh(ob.data)
if bm.loops.layers.uv:
if align_uv_rotation_bmesh(ob.data, bm, method, axis, aspect_y):
if align_uv_rotation_bmesh(bm, method, axis, aspect_y):
bmesh.update_edit_mesh(ob.data)
return {'FINISHED'}

View File

@@ -266,7 +266,7 @@ class UI_MT_list_item_context_menu(bpy.types.Menu):
bl_label = "List Item"
bl_idname = "UI_MT_list_item_context_menu"
def draw(self, context):
def draw(self, _context):
# Dummy function. This type is just for scripts to append their own
# context menu items.
pass
@@ -282,7 +282,7 @@ class UI_MT_button_context_menu(bpy.types.Menu):
bl_label = "List Item"
bl_idname = "UI_MT_button_context_menu"
def draw(self, context):
def draw(self, _context):
# Draw menu entries created with the legacy `WM_MT_button_context` class.
# This is deprecated, and support will be removed in a future release.
if hasattr(bpy.types, "WM_MT_button_context"):

View File

@@ -8,7 +8,7 @@ from bpy.types import Menu
class ANIM_MT_keyframe_insert_pie(Menu):
bl_label = "Keyframe Insert Pie"
def draw(self, context):
def draw(self, _context):
layout = self.layout
pie = layout.menu_pie()

View File

@@ -379,7 +379,7 @@ class POSE_PT_selection_sets(Panel):
class POSE_UL_selection_set(UIList):
def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
def draw_item(self, _context, layout, _data, item, icon, _active_data, _active_propname, _index):
row = layout.row()
row.prop(item, "name", text="", emboss=False)
if self.layout_type in ('DEFAULT', 'COMPACT'):
@@ -389,7 +389,7 @@ class POSE_UL_selection_set(UIList):
class POSE_MT_selection_set_create(Menu):
bl_label = "Choose Selection Set"
def draw(self, context):
def draw(self, _context):
layout = self.layout
layout.operator("pose.selection_set_add_and_assign",
text="New Selection Set")

View File

@@ -294,7 +294,7 @@ class AddModifierMenu(Operator):
return False
return space and space.type == 'PROPERTIES' and space.context == 'MODIFIER'
def invoke(self, context, event):
def invoke(self, _context, _event):
return bpy.ops.wm.call_menu(name="OBJECT_MT_modifier_add")

View File

@@ -785,7 +785,7 @@ class GREASE_PENCIL_MT_draw_delete(Menu):
class GREASE_PENCIL_MT_stroke_simplify(Menu):
bl_label = "Simplify Stroke"
def draw(self, context):
def draw(self, _context):
layout = self.layout
layout.operator("grease_pencil.stroke_simplify", text="Fixed").mode = 'FIXED'
layout.operator("grease_pencil.stroke_simplify", text="Adaptive").mode = 'ADAPTIVE'

View File

@@ -149,7 +149,7 @@ class WORKSPACE_UL_addons_items(UIList):
indices = self._sort_addons_by_category_name(addons)
return flags, indices
def draw_item(self, context, layout, _data, addon, icon, _active_data, _active_propname, _index):
def draw_item(self, context, layout, _data, addon, _icon, _active_data, _active_propname, _index):
row = layout.row()
row.active = context.workspace.use_filter_by_owner
row.emboss = 'NONE'

View File

@@ -8,7 +8,7 @@ from bpy.types import Header
class STATUSBAR_HT_header(Header):
bl_space_type = 'STATUSBAR'
def draw(self, context):
def draw(self, _context):
layout = self.layout
# input status

View File

@@ -610,7 +610,7 @@ class VIEW3D_PT_slots_paint_canvas(SelectPaintSlotHelper, View3DPanel, Panel):
def get_mode_settings(self, context):
return context.tool_settings.paint_mode
def draw_image_interpolation(self, **kwargs):
def draw_image_interpolation(self, **_kwargs):
pass
def draw_header(self, context):

View File

@@ -15,6 +15,9 @@ from check_utils import sliceCommandLineArguments
def load_tests(loader, standard_tests, pattern):
# Unused.
del pattern
standard_tests.addTests(loader.loadTestsFromTestCase(
check_module_enabled.UnitTesting))
standard_tests.addTests(loader.loadTestsFromTestCase(

View File

@@ -5,6 +5,10 @@
# Note: this code should be cleaned up / refactored.
__all__ = (
"main",
)
import sys
if sys.version_info.major < 3:
print("\nPython3.x needed, found %s.\nAborting!\n" %
@@ -51,7 +55,7 @@ for k, v in IGNORE_SOURCE_MISSING_FLAT:
del IGNORE_SOURCE_MISSING_FLAT
def replace_line(f: str, i: int, text: str, keep_indent: bool = True) -> None:
def replace_line(f: str, i: int, text: str) -> None:
file_handle = open(f, 'r')
data = file_handle.readlines()
file_handle.close()
@@ -95,12 +99,15 @@ def is_c(filename: str) -> bool:
return (ext in {".c", ".cpp", ".cxx", ".m", ".mm", ".rc", ".cc", ".inl", ".metal", ".msl"})
def is_c_any(filename: str) -> bool:
return is_c(filename) or is_c_header(filename)
# def is_c_any(filename: str) -> bool:
# return is_c(filename) or is_c_header(filename)
def cmake_get_src(f: str) -> None:
# TODO: only partially implemented, needs work.
do_replace_text = False
sources_h = []
sources_c = []
@@ -272,8 +279,9 @@ def cmake_get_src(f: str) -> None:
if new_path_rel != l:
print("overly relative path:\n %s:%d\n %s\n %s" % (f, line_number, l, new_path_rel))
# # Save time. just replace the line
# replace_line(f, line_number - 1, new_path_rel)
# Save time. just replace the line.
if do_replace_text:
replace_line(f, line_number - 1, new_path_rel)
else:
raise Exception("non existent include %s:%d -> %s" % (f, line_number, new_file))

View File

@@ -48,11 +48,12 @@ def remove_comments(string: str) -> str:
regex = re.compile(pattern, re.MULTILINE | re.DOTALL)
def _replacer(m: re.Match[str]) -> str:
# if the 2nd group (capturing comments) is not None,
# it means we have captured a non-quoted (real) comment string.
# If the 2nd group (capturing comments) is not None,
# It means we have captured a non-quoted (real) comment string.
if m.group(2) is not None:
return "" # so we will return empty to remove the comment
else: # otherwise, we will return the 1st group
# So we will return empty to remove the comment.
return ""
# Otherwise, we will return the 1st group.
return m.group(1) # capture
return regex.sub(_replacer, string)
@@ -69,8 +70,7 @@ def extract_terms(fn: str, data_src: str) -> None:
for m in re_defines.finditer(data_src_nocomments):
defines[m.group(1)] = fn
# Don't edit the file.
return None
# Returning None indicates the file is not edited.
def main() -> int:

View File

@@ -101,7 +101,7 @@ class BlendFile:
def __enter__(self):
return self
def __exit__(self, type, value, traceback):
def __exit__(self, _type, _value, _traceback):
self.close()
def find_blocks_from_code(self, code):
@@ -594,7 +594,7 @@ class BlendFileRaw:
def __enter__(self):
return self
def __exit__(self, type, value, traceback):
def __exit__(self, _type, _value, _traceback):
self.close()
def find_blocks_from_code(self, code):

View File

@@ -174,7 +174,7 @@ def is_ignore_dna_name(name):
return False
def write_member(fw, indent, b, theme, ls):
def write_member(fw, indent, _blend, _theme, ls):
path_old = ()
for key, value in ls:

View File

@@ -30,7 +30,7 @@ class PrintStructC99(gdb.Command):
first_line = string.split('\n')[0]
return first_line.split('=')[1][:-1].strip()
def invoke(self, arg, from_tty):
def invoke(self, arg, _from_tty):
ret_ptype = gdb.execute('ptype {}'.format(arg), to_string=True)
tname = self.extract_typename(ret_ptype)
print('{} {} = {{'.format(tname, arg))

View File

@@ -292,7 +292,7 @@ class App:
def main() -> int:
root = Tk()
app = App(root)
_app = App(root)
root.title("Cursor Maker")
root.mainloop()

View File

@@ -449,7 +449,7 @@ class EditGenerator:
def edit_list_from_file(_source: str, _data: str, _shared_edit_data: Any) -> list[Edit]:
# The `__init_subclass__` function ensures this is always overridden.
raise RuntimeError("This function must be overridden by it's subclass!")
return []
# return []
@staticmethod
def setup() -> Any: