py3: catch specific OSError subclasses instead of checking errno
authorManuel Jacob <me@manueljacob.de>
Wed, 01 Jun 2022 02:21:41 +0200
changeset 49311 defc369d705e
parent 49310 050dc8730858
child 49312 fce591256085
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.
mercurial/windows.py
--- 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)