Skip to content
Myr

use importlib instead of pkgutil

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Lord · committed by David Lord · parent 367e1df · Browse files · 3 files+7 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+7 added−4 removed

  • other:+7 added−4 removed

3 files+7 added−4 removed

modified:src/flask/helpers.py+3 added-2 removed
1from __future__ import annotations23import importlib.util4import os4import pkgutil5import socket6import sys7import typing as t8import warnings
565 unmodified lines
574 if mod is not None and hasattr(mod, "__file__") and mod.__file__ is not None:575 return os.path.dirname(os.path.abspath(mod.__file__))576577 # Next attempt: check the loader.578 loader = pkgutil.get_loader(import_name)578 spec = importlib.util.find_spec(import_name)579 loader = spec.loader if spec is not None else None580581 # Loader does not exist or we're referring to an unloaded main582 # module or a main module without path (interactive sessions), go583 # with the current working directory.
111 unmodified lines
modified:src/flask/scaffold.py+2 added-2 removed
1 unmodified line
23import importlib.util4import os5import pathlib6import pkgutil6import sys7import typing as t8from collections import defaultdict9from datetime import timedelta
844 unmodified lines
854 else:855 return os.path.dirname(root_spec.origin)856857 # we were unable to find the `package_path` using PEP 451 loaders859 loader = pkgutil.get_loader(root_mod_name)858 spec = importlib.util.find_spec(root_mod_name)859 loader = spec.loader if spec is not None else None860861 if loader is None or root_mod_name == "__main__":862 # import name is not found, or interactive/main module863 return os.getcwd()
60 unmodified lines
modified:CHANGES.rst+2 added
1 unmodified line
2-------------34Unreleased56- Python 3.12 compatibility.789Version 2.3.210-------------1112Released 2023-05-01
1501 unmodified lines