fix: silence ENOTDIR in Config.from_file() to match from_pyfile()

from_pyfile() already silences errno.ENOTDIR when silent=True, but
from_file() was missing it. Both methods should behave consistently
when a path component is a regular file rather than a directory.

Fixes #6023
This commit is contained in:
Nilesh Patil 2026-05-16 20:07:54 +05:30
parent 9fcd34c9f3
commit a06c847ace

View file

@ -293,7 +293,7 @@ class Config(dict): # type: ignore[type-arg]
with open(filename, "r" if text else "rb") as f:
obj = load(f)
except OSError as e:
if silent and e.errno in (errno.ENOENT, errno.EISDIR):
if silent and e.errno in (errno.ENOENT, errno.EISDIR, errno.ENOTDIR):
return False
e.strerror = f"Unable to load configuration file ({e.strerror})"