From 076983eec45e739c68551cb6119fd7d85fd4afa9 Mon Sep 17 00:00:00 2001 From: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Date: Sat, 26 Sep 2020 22:50:56 -0700 Subject: [PATCH] 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 --- stdlib/2/__builtin__.pyi | 3 ++- stdlib/2and3/builtins.pyi | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/stdlib/2/__builtin__.pyi b/stdlib/2/__builtin__.pyi index a79300956..7a7245396 100644 --- a/stdlib/2/__builtin__.pyi +++ b/stdlib/2/__builtin__.pyi @@ -56,6 +56,7 @@ from typing import ( Union, ValuesView, overload, + runtime_checkable, ) from typing_extensions import Literal @@ -1211,7 +1212,7 @@ if sys.version_info < (3,): # but we define it here as _PathLike to avoid import cycle issues. # See https://github.com/python/typeshed/pull/991#issuecomment-288160993 _AnyStr_co = TypeVar("_AnyStr_co", str, bytes, covariant=True) - +@runtime_checkable class _PathLike(Protocol[_AnyStr_co]): def __fspath__(self) -> _AnyStr_co: ... diff --git a/stdlib/2and3/builtins.pyi b/stdlib/2and3/builtins.pyi index a79300956..7a7245396 100644 --- a/stdlib/2and3/builtins.pyi +++ b/stdlib/2and3/builtins.pyi @@ -56,6 +56,7 @@ from typing import ( Union, ValuesView, overload, + runtime_checkable, ) from typing_extensions import Literal @@ -1211,7 +1212,7 @@ if sys.version_info < (3,): # but we define it here as _PathLike to avoid import cycle issues. # See https://github.com/python/typeshed/pull/991#issuecomment-288160993 _AnyStr_co = TypeVar("_AnyStr_co", str, bytes, covariant=True) - +@runtime_checkable class _PathLike(Protocol[_AnyStr_co]): def __fspath__(self) -> _AnyStr_co: ...