From 46aee5a97d9c9365906d0526b78d786b19ba1fc6 Mon Sep 17 00:00:00 2001 From: Bas van Beek <43369155+BvB93@users.noreply.github.com> Date: Fri, 30 Sep 2022 22:33:11 +0200 Subject: [PATCH] Avoid deprecated `importlib.resources.path` function (#13783) 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`. --- mypy/util.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/mypy/util.py b/mypy/util.py index 582800621e4d6..d889d3d9340f3 100644 --- a/mypy/util.py +++ b/mypy/util.py @@ -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.]+)")