Skip to content

Commit 0c1d32e

Browse files
committed
Inline os.PathLike using future annotations.
1 parent b99c9d6 commit 0c1d32e

File tree

2 files changed

+6
-15
lines changed

2 files changed

+6
-15
lines changed

importlib_metadata/__init__.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import os
24
import re
35
import abc
@@ -21,7 +23,6 @@
2123
from ._collections import FreezableDefaultDict, Pair
2224
from ._compat import (
2325
NullFinder,
24-
StrPath,
2526
install,
2627
)
2728
from ._functools import method_cache, pass_none
@@ -387,7 +388,7 @@ def read_text(self, filename) -> Optional[str]:
387388
"""
388389

389390
@abc.abstractmethod
390-
def locate_file(self, path: StrPath) -> SimplePath:
391+
def locate_file(self, path: os.PathLike[str]) -> SimplePath:
391392
"""
392393
Given a path to a file in this distribution, return a SimplePath
393394
to it.
@@ -432,7 +433,7 @@ def discover(
432433
)
433434

434435
@staticmethod
435-
def at(path: StrPath) -> "Distribution":
436+
def at(path: os.PathLike[str]) -> "Distribution":
436437
"""Return a Distribution for the indicated metadata path.
437438
438439
:param path: a string or path-like object
@@ -840,7 +841,7 @@ def __init__(self, path: SimplePath) -> None:
840841
"""
841842
self._path = path
842843

843-
def read_text(self, filename: StrPath) -> Optional[str]:
844+
def read_text(self, filename: os.PathLike[str]) -> Optional[str]:
844845
with suppress(
845846
FileNotFoundError,
846847
IsADirectoryError,
@@ -854,7 +855,7 @@ def read_text(self, filename: StrPath) -> Optional[str]:
854855

855856
read_text.__doc__ = Distribution.read_text.__doc__
856857

857-
def locate_file(self, path: StrPath) -> SimplePath:
858+
def locate_file(self, path: os.PathLike[str]) -> SimplePath:
858859
return self._path.parent / path
859860

860861
@property

importlib_metadata/_compat.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
import os
21
import sys
32
import platform
43

5-
from typing import Union
6-
74

85
__all__ = ['install', 'NullFinder']
96

@@ -58,10 +55,3 @@ def pypy_partial(val):
5855
"""
5956
is_pypy = platform.python_implementation() == 'PyPy'
6057
return val + is_pypy
61-
62-
63-
if sys.version_info >= (3, 9):
64-
StrPath = Union[str, os.PathLike[str]]
65-
else:
66-
# PathLike is only subscriptable at runtime in 3.9+
67-
StrPath = Union[str, "os.PathLike[str]"] # pragma: no cover

0 commit comments

Comments
 (0)