Skip to content

Commit 076983e

Browse files
authored
PathLike: make runtime_checkable (#4582)
I made PathLike a protocol in #4447, but it should also be runtime_checkable. Caught by mypy_primer: src/werkzeug/utils.py:646: error: Only @runtime_checkable protocols can be used with instance and class checks
1 parent 734d91f commit 076983e

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

stdlib/2/__builtin__.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ from typing import (
5656
Union,
5757
ValuesView,
5858
overload,
59+
runtime_checkable,
5960
)
6061
from typing_extensions import Literal
6162

@@ -1211,7 +1212,7 @@ if sys.version_info < (3,):
12111212
# but we define it here as _PathLike to avoid import cycle issues.
12121213
# See https://github.com/python/typeshed/pull/991#issuecomment-288160993
12131214
_AnyStr_co = TypeVar("_AnyStr_co", str, bytes, covariant=True)
1214-
1215+
@runtime_checkable
12151216
class _PathLike(Protocol[_AnyStr_co]):
12161217
def __fspath__(self) -> _AnyStr_co: ...
12171218

stdlib/2and3/builtins.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ from typing import (
5656
Union,
5757
ValuesView,
5858
overload,
59+
runtime_checkable,
5960
)
6061
from typing_extensions import Literal
6162

@@ -1211,7 +1212,7 @@ if sys.version_info < (3,):
12111212
# but we define it here as _PathLike to avoid import cycle issues.
12121213
# See https://github.com/python/typeshed/pull/991#issuecomment-288160993
12131214
_AnyStr_co = TypeVar("_AnyStr_co", str, bytes, covariant=True)
1214-
1215+
@runtime_checkable
12151216
class _PathLike(Protocol[_AnyStr_co]):
12161217
def __fspath__(self) -> _AnyStr_co: ...
12171218

0 commit comments

Comments
 (0)