Missing cleanup pattern (ARCH2082)
Key python.performance.dispose-pattern · Severity warning · Category performance
A class that owns a closeable resource but offers no close or context manager to release it never frees the resource. Implement the cleanup contract.
Incorrect
Section titled “Incorrect”class Exporter: def __init__(self, path): self.file = open(path, "w")
def write(self, row): self.file.write(row)Correct
Section titled “Correct”class Exporter: def __init__(self, path): self.file = open(path, "w")
def write(self, row): self.file.write(row)
def __enter__(self): return self
def __exit__(self, *exc): self.file.close()Add __enter__/__exit__ or close to the resource-owning class to release owned handles.