# HG changeset patch # User Manuel Jacob # Date 1654042901 -7200 # Node ID defc369d705e6824de3908082f52e571baf5f636 # Parent 050dc87308589371c429b936579c40700a8661fc 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. diff -r 050dc8730858 -r defc369d705e 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)