Skip to content

Commit

Permalink
PathLike: make runtime_checkable (#4582)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
hauntsaninja committed Sep 27, 2020
1 parent 734d91f commit 076983e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion stdlib/2/__builtin__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ from typing import (
Union,
ValuesView,
overload,
runtime_checkable,
)
from typing_extensions import Literal

Expand Down Expand Up @@ -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: ...

Expand Down
3 changes: 2 additions & 1 deletion stdlib/2and3/builtins.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ from typing import (
Union,
ValuesView,
overload,
runtime_checkable,
)
from typing_extensions import Literal

Expand Down Expand Up @@ -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: ...

Expand Down

0 comments on commit 076983e

Please sign in to comment.