Skip to content
Verified Commit ba670a07 authored by Matthew Clarkson's avatar Matthew Clarkson
Browse files

fix: correct temporary output move when using YAML `SafeDumper`

When a `CSafeDumper` is not available, we fallback to `SafeDumper`.

This correctly invokes the `__del__` function in the order that the garbage collector runs.

It results in the following error:

```
Exception ignored in: <function Closer.__del__ at 0x7f9547c3b420>
Traceback (most recent call last):
  File ".../pre-commit/config/cli.runfiles/_main/pre-commit/config/cli.py", line 175, in __del__
    self.close()
  File ".../pre-commit/config/cli.runfiles/_main/pre-commit/config/cli.py", line 170, in close
    self.__file.flush()
  File ".../python3.13/tempfile.py", line 499, in func_wrapper
    return func(*args, **kwargs)
ValueError: I/O operation on closed file.
```

This occurs because the `NamedTemporaryFile.__del__` runs before the `Closer.__del__`.

The `NamedTemporaryFile.__del__` closes then, then deletes the file. Setting `delete=False` will not help.

We move the `NamedTemporaryFile` into the `Closer` (renamed to `TemporaryRedirectFile`) to correct the closing order.
parent b4fecbec
Loading
Loading
Loading
Loading
  • GITLAB_TOKEN @group_3575_bot_1fa64dd2caebb37307063a803b95a420

    mentioned in commit 7c2a9195

    ·

    mentioned in commit 7c2a9195

    Toggle commit list
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment