[New-bugs-announce] [issue44137] importlib.resources.path raises RuntimeError import FileNotFoundError is raise in context manager

Nils Kattenbeck report at bugs.python.org
Fri May 14 15:29:20 EDT 2021


New submission from Nils Kattenbeck <nilskemail at gmail.com>:

When a FileNotFoundError is raised inside while the importlib.resources.path context manager is active a RuntimeError is raised.
Looking at the (3.8) code it seems that FileNotFound exceptions are handled specially from all other exceptions which may lead to this behaviour. While the code in 3.9 changed significantly the same behaviour can be observed.

Files:
.
└── my_package
    ├── data.txt (empty)
    ├── __init__.py (empty)
    └── test.py

Content of test.py:
import importlib.resources
def main():
    with importlib.resources.path('my_package', 'data.txt') as p:
        raise FileNotFoundError()
if __name__ == '__main__':
    main()

Exact error message:
RuntimeError: generator didn't stop after throw()

----------
components: Library (Lib)
messages: 393686
nosy: Nils Kattenbeck, brett.cannon, jaraco
priority: normal
severity: normal
status: open
title: importlib.resources.path raises RuntimeError import FileNotFoundError is raise in context manager
type: behavior
versions: Python 3.8, Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44137>
_______________________________________


More information about the New-bugs-announce mailing list