<div dir="ltr"><p style="color:rgb(0,0,0)"><span style="font-family:arial,sans-serif">Hi,</span></p><p style="color:rgb(0,0,0)"><span style="font-family:arial,sans-serif">Thank you for accepting the patch — I appreciate it.</span></p><p style="color:rgb(0,0,0)"><span style="font-family:arial,sans-serif">I noticed that the merged change keeps the conditional guard in</span><span class="gmail-Apple-converted-space" style="font-family:arial,sans-serif"> </span><code>close()</code><span style="font-family:arial,sans-serif">, but does not include:</span><br><span style="font-family:arial,sans-serif">    self._close = _close</span><br><span style="font-family:arial,sans-serif">That line was intended to cache the</span><span class="gmail-Apple-converted-space" style="font-family:arial,sans-serif"> </span><code>magic_close</code><span class="gmail-Apple-converted-space" style="font-family:arial,sans-serif"> </span><span style="font-family:arial,sans-serif">function on the instance. The current</span><span class="gmail-Apple-converted-space" style="font-family:arial,sans-serif"> </span><code>if _close:</code><span class="gmail-Apple-converted-space" style="font-family:arial,sans-serif"> </span><span style="font-family:arial,sans-serif">avoids the traceback, but it still relies on the module-global</span><span class="gmail-Apple-converted-space" style="font-family:arial,sans-serif"> </span><code>_close</code><span style="font-family:arial,sans-serif">, which may already be cleared during interpreter shutdown. Storing the function on the instance ensures it remains available when</span><span class="gmail-Apple-converted-space" style="font-family:arial,sans-serif"> </span><code>__del__</code><span class="gmail-Apple-converted-space" style="font-family:arial,sans-serif"> </span><span style="font-family:arial,sans-serif">runs.</span></p><p style="color:rgb(0,0,0)"><span style="font-family:arial,sans-serif">Would you consider also adding the</span><span class="gmail-Apple-converted-space" style="font-family:arial,sans-serif"> </span><code>self._close = _close</code><span class="gmail-Apple-converted-space" style="font-family:arial,sans-serif"> </span><span style="font-family:arial,sans-serif">line?</span></p><p style="color:rgb(0,0,0)"><span style="font-family:arial,sans-serif">Best regards,</span><br><span style="font-family:arial,sans-serif">Vincent</span><br></p></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Tue, Feb 10, 2026 at 1:52 PM Vincent Mihalkovic <<a href="mailto:vmihalko@redhat.com">vmihalko@redhat.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><p><span style="color:rgb(0,0,0)">Hi,</span><br><font color="#000000"><span><br></span></font><span style="color:rgb(0,0,0)">I am seeing a</span><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(0,0,0)">TypeError</span><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(0,0,0)">at Python interpreter shutdown when using the Python bindings shipped with file (</span><span style="color:rgb(0,0,0)">python/magic.py</span><span style="color:rgb(0,0,0)">).</span><br><font color="#000000"><span><br></span></font><span style="color:rgb(0,0,0)">MagicDetect.__del__()</span><span style="color:rgb(0,0,0)"><span> </span>calls<span> </span></span><span style="color:rgb(0,0,0)">Magic.close()</span><span style="color:rgb(0,0,0)"><span> </span>(see</span><span> </span><span style="color:rgb(0,0,0)"><a href="https://github.com/file/file/blob/master/python/magic.py#L300-L310" target="_blank">https://github.com/file/file/blob/master/python/magic.py#L300-L310</a>), </span><span style="color:rgb(0,0,0)">which in turn calls the module-global</span><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(0,0,0)">_close</span><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(0,0,0)">in</span><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(0,0,0)">Magic.close()</span><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(0,0,0)">(see </span><span style="color:rgb(0,0,0)"><a href="https://github.com/file/file/blob/master/python/magic.py#L130-L136" target="_blank">https://github.com/file/file/blob/master/python/magic.py#L130-L136</a>).</span></p><p><span style="color:rgb(0,0,0)">During interpreter shutdown, module globals may already be cleared, so</span><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(0,0,0)">_close</span><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(0,0,0)">can become</span><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(0,0,0)">None</span><span style="color:rgb(0,0,0)">, resulting in: </span><span style="color:rgb(0,0,0)">TypeError: ‘NoneType’ object is not callable</span><br><font color="#000000"><span><br></span></font><span style="color:rgb(0,0,0)">The attached patch avoids relying on the module-global</span><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(0,0,0)">_close</span><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(0,0,0)">during finalization by caching the</span><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(0,0,0)">magic_close</span><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(0,0,0)">function pointer on the</span><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(0,0,0)">Magic</span><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(0,0,0)">instance and using that in</span><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(0,0,0)">close()</span><span style="color:rgb(0,0,0)">. This prevents the shutdown exception without changing normal runtime behavior.</span><br><font color="#000000"><span><br></span></font><span style="color:rgb(0,0,0)">Related downstream report:</span><br><span style="color:rgb(0,0,0)"><a href="https://bugzilla.redhat.com/show_bug.cgi?id=2419719" target="_blank">https://bugzilla.redhat.com/show_bug.cgi?id=2419719</a></span><br><font color="#000000"><span><br></span></font><span style="color:rgb(0,0,0)">Best regards,</span><br><span style="color:rgb(0,0,0)">Vincent</span><br></p></div>
</blockquote></div>