Skip to content

Commit 151e151

Browse files
committed
fix(bar): give ProgressBarBase an explicit __del__ chain (CodeQL missing-call-to-delete)
CodeQL flagged ProgressBarBase (Iterable + ProgressBarMixinBase multiple inheritance) for finalizing without an explicit __del__ calling the base finalizer. Revert the earlier wrong-class guarded super().__del__() in ProgressBarMixinBase and define ProgressBarBase.__del__ = super().__del__(), which resolves to the same ProgressBarMixinBase.__del__ reached by inheritance — behaviourally identical, MI chain now explicit.
1 parent 1395a47 commit 151e151

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

progressbar/bar.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,6 @@ def __del__(self):
175175
except Exception: # noqa: BLE001, S110
176176
pass
177177

178-
# Cooperatively chain to a superclass finalizer when one exists. This
179-
# class's bases (abc.ABC, object) define no __del__, so the call is a
180-
# no-op today; the guard keeps finalization cooperative — and avoids
181-
# an AttributeError — should a base with __del__ ever be introduced.
182-
if hasattr(super(), '__del__'): # pragma: no cover
183-
super().__del__() # pyright: ignore[reportAttributeAccessIssue]
184-
185178
def __getstate__(self):
186179
return self.__dict__
187180

@@ -214,6 +207,15 @@ def __repr__(self):
214207
label = f': {self.label}' if self.label else ''
215208
return f'<{self.__class__.__name__}#{self.index}{label}>'
216209

210+
def __del__(self) -> None:
211+
# ProgressBarBase mixes collections.abc.Iterable in alongside
212+
# ProgressBarMixinBase (which defines the real finalizer). Define
213+
# __del__ here so that finalizer is reached explicitly through the MRO
214+
# instead of only by attribute inheritance — behaviourally identical
215+
# (super() resolves to the same ProgressBarMixinBase.__del__), but it
216+
# makes the multiple-inheritance finalizer chain unambiguous.
217+
super().__del__() # pragma: no cover
218+
217219

218220
class DefaultFdMixin(ProgressBarMixinBase):
219221
# The file descriptor to write to. Defaults to `sys.stderr`

0 commit comments

Comments
 (0)