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
This commit is contained in:
Shantanu
2020-09-26 22:50:56 -07:00
committed by GitHub
parent 734d91f90b
commit 076983eec4
2 changed files with 4 additions and 2 deletions

View File

@@ -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: ...

View File

@@ -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: ...