Skip to content

Commit

Permalink
Avoid deprecated importlib.resources.path function (#13783)
Browse files Browse the repository at this point in the history
The
[`importlib.resources.path`](https://docs.python.org/3.11/library/importlib.resources.html#importlib.resources.path)
function is deprecated as of Python 3.11; substitute it with
`importlib.resources.files`.
  • Loading branch information
BvB93 authored Sep 30, 2022
1 parent 24aab8e commit 46aee5a
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions mypy/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@

T = TypeVar("T")

with importlib_resources.path(
"mypy", # mypy-c doesn't support __package__
"py.typed", # a marker file for type information, we assume typeshed to live in the same dir
) as _resource:
TYPESHED_DIR: Final = str(_resource.parent / "typeshed")
if sys.version_info >= (3, 9):
TYPESHED_DIR: Final = str(importlib_resources.files("mypy") / "typeshed")
else:
with importlib_resources.path(
"mypy", # mypy-c doesn't support __package__
"py.typed", # a marker file for type information, we assume typeshed to live in the same dir
) as _resource:
TYPESHED_DIR = str(_resource.parent / "typeshed")


ENCODING_RE: Final = re.compile(rb"([ \t\v]*#.*(\r\n?|\n))??[ \t\v]*#.*coding[:=][ \t]*([-\w.]+)")
Expand Down

0 comments on commit 46aee5a

Please sign in to comment.