Skip to content

Commit ca52662

Browse files
authored
Handle PermissionError in fallback code for old import name (#182)
1 parent 8764067 commit ca52662

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

multipart/__init__.py

+11-8
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,17 @@
77

88
for p in sys.path:
99
file_path = Path(p, "multipart.py")
10-
if file_path.is_file():
11-
spec = importlib.util.spec_from_file_location("multipart", file_path)
12-
assert spec is not None, f"{file_path} found but not loadable!"
13-
module = importlib.util.module_from_spec(spec)
14-
sys.modules["multipart"] = module
15-
assert spec.loader is not None, f"{file_path} must be loadable!"
16-
spec.loader.exec_module(module)
17-
break
10+
try:
11+
if file_path.is_file():
12+
spec = importlib.util.spec_from_file_location("multipart", file_path)
13+
assert spec is not None, f"{file_path} found but not loadable!"
14+
module = importlib.util.module_from_spec(spec)
15+
sys.modules["multipart"] = module
16+
assert spec.loader is not None, f"{file_path} must be loadable!"
17+
spec.loader.exec_module(module)
18+
break
19+
except PermissionError:
20+
pass
1821
else:
1922
warnings.warn("Please use `import python_multipart` instead.", PendingDeprecationWarning, stacklevel=2)
2023
from python_multipart import *

0 commit comments

Comments
 (0)