Miguel Brito <miguel.mdebr...@gmail.com> added the comment:

I can reproduce this. From what I can see the issue is that 
`importlib.resources.path` intentionally suppresses `FileNotFoundError` errors.

https://github.com/python/cpython/blob/main/Lib/importlib/resources.py#L138

Based on `importlib.resources.path` docstring I think this is to avoid raising 
an exception if the file is deleted before the context manager exits.

On contextlib.py, since type is not None, it will try to throw the exception 
but since it's supressed nothing will happen and the code will reach the end by 
raising the RuntimeError.

https://github.com/python/cpython/blob/main/Lib/contextlib.py#L151

If I'm not mistaken, this is the test that verifies that behaviour: 
https://github.com/python/cpython/blob/main/Lib/test/test_importlib/test_path.py#L51


I'm not a core dev but it looks like it's an intentional behaviour.

Maybe the docs should be more clear about this. It's not obvious to me when I 
read the docs.

----------
nosy: +miguendes

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue44137>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to