Skip to content

Commit

Permalink
use importlib instead of pkgutil
Browse files Browse the repository at this point in the history
  • Loading branch information
davidism committed Jun 7, 2023
1 parent 367e1df commit 84e11a1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ Version 2.3.3

Unreleased

- Python 3.12 compatibility.


Version 2.3.2
-------------
Expand Down
5 changes: 3 additions & 2 deletions src/flask/helpers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import importlib.util
import os
import pkgutil
import socket
import sys
import typing as t
Expand Down Expand Up @@ -575,7 +575,8 @@ def get_root_path(import_name: str) -> str:
return os.path.dirname(os.path.abspath(mod.__file__))

# Next attempt: check the loader.
loader = pkgutil.get_loader(import_name)
spec = importlib.util.find_spec(import_name)
loader = spec.loader if spec is not None else None

# Loader does not exist or we're referring to an unloaded main
# module or a main module without path (interactive sessions), go
Expand Down
4 changes: 2 additions & 2 deletions src/flask/scaffold.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import importlib.util
import os
import pathlib
import pkgutil
import sys
import typing as t
from collections import defaultdict
Expand Down Expand Up @@ -856,7 +855,8 @@ def _find_package_path(import_name):
return os.path.dirname(root_spec.origin)

# we were unable to find the `package_path` using PEP 451 loaders
loader = pkgutil.get_loader(root_mod_name)
spec = importlib.util.find_spec(root_mod_name)
loader = spec.loader if spec is not None else None

if loader is None or root_mod_name == "__main__":
# import name is not found, or interactive/main module
Expand Down

0 comments on commit 84e11a1

Please sign in to comment.