Mercurial > public > mercurial-scm > hg
comparison mercurial/windows.py @ 49311:defc369d705e
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.
author | Manuel Jacob <me@manueljacob.de> |
---|---|
date | Wed, 01 Jun 2022 02:21:41 +0200 |
parents | 53e9422a9b45 |
children | 709e5f7eec1f |
comparison
equal
deleted
inserted
replaced
49310:050dc8730858 | 49311:defc369d705e |
---|---|
574 dmap = { | 574 dmap = { |
575 normcase(n): s | 575 normcase(n): s |
576 for n, k, s in listdir(dir, True) | 576 for n, k, s in listdir(dir, True) |
577 if getkind(s.st_mode) in _wantedkinds | 577 if getkind(s.st_mode) in _wantedkinds |
578 } | 578 } |
579 except OSError as err: | 579 except (FileNotFoundError, NotADirectoryError): |
580 # Python >= 2.5 returns ENOENT and adds winerror field | |
581 # EINVAL is raised if dir is not a directory. | |
582 if err.errno not in (errno.ENOENT, errno.EINVAL, errno.ENOTDIR): | |
583 raise | |
584 dmap = {} | 580 dmap = {} |
585 cache = dircache.setdefault(dir, dmap) | 581 cache = dircache.setdefault(dir, dmap) |
586 yield cache.get(base, None) | 582 yield cache.get(base, None) |
587 | 583 |
588 | 584 |