Mercurial > public > mercurial-scm > hg-stable
diff setup.py @ 52913:6ee3c401882b
vfs: avoid passing None to `shutil.rmtree()` for the exception handler
Even though the code looks like it will handle it, pytype 2024.10.11 complains.
So the simplest thing to do is pass along a no-op function that it would use
internally if it was explicitly provided None.
The specific error was:
/home/mharbison/projects/mercurial/mercurial-devel/mercurial/vfs.py:360:20:
error: in rmtree: Function _RmtreeType.__call__ was called with the wrong arguments [wrong-arg-types]
Expected: (self, path, ignore_errors, *, dir_fd, onexc: Callable[[Callable, str, Exception], object])
Actually passed: (self, path, ignore_errors, onexc: Optional[Callable[[Any, bytes, Any], Any]])
Attributes of protocol Callable[[Callable, str, Exception], object] are not implemented on None: __call__
return shutil.rmtree(
~~~~~~~~~~~~~~
self.join(path), ignore_errors=ignore_errors, onexc=onexc
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
)
~~~~~~~~~~~~~
Note that it expects a str on the callback. I thought maybe there would be an
@overload, and it could handle both. But looking at the code in Python 3.11,
they call `os.fsdecode(path)` on some platforms when given bytes, and pass that
str to the callback. So adjust the typehint accordingly, and leave a note.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Tue, 11 Feb 2025 22:44:21 -0500 |
parents | 0977c6e612fe |
children | 53ae4495e5f0 |