py3: catch specific OSError subclasses instead of checking errno
On Python 3, the "not a directory" error is mapped to ENOTDIR instead of
EINVAL. Therefore, catching the NotADirectoryError subclass is sufficient.
--- a/mercurial/windows.py Wed Jun 01 00:47:25 2022 +0200
+++ b/mercurial/windows.py Wed Jun 01 02:21:41 2022 +0200
@@ -576,11 +576,7 @@
for n, k, s in listdir(dir, True)
if getkind(s.st_mode) in _wantedkinds
}
- except OSError as err:
- # Python >= 2.5 returns ENOENT and adds winerror field
- # EINVAL is raised if dir is not a directory.
- if err.errno not in (errno.ENOENT, errno.EINVAL, errno.ENOTDIR):
- raise
+ except (FileNotFoundError, NotADirectoryError):
dmap = {}
cache = dircache.setdefault(dir, dmap)
yield cache.get(base, None)