Closed as not planned
Description
Python 3.6.6 x64
Windows 10 x64
mypy 0.630
mypy-extensions 0.4.1
typing 3.6.6
typing-extensions 3.6.6
https://mail.python.org/pipermail/python-ideas/2018-October/054134.html
Ivan Levkivskyi's suggested solution to handling a "PathLike" protocol:
from typing import AnyStr
from typing_extensions import Protocol
class PathLike(Protocol[AnyStr]):
def __fspath__(self) -> AnyStr: ...
Produces an error unexpected error:
> mypy fsp.py
fsp.py:3: error: Invariant type variable 'AnyStr' used in protocol where covariant one is expected
Ivan's response
Hm, it looks like mypy overreacts here. I think it should be safe to use a constrained type variable if there are no constraints that are subtypes of other constraints (which is the case for AnyStr on Python 3, where bytes is not a subtype of str).