Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.

Support TypeVar bound - #1463

Merged
Cameron Trando (CTrando) merged 8 commits into
microsoft:masterfrom
CTrando:scratch/TypeVarBoundSupport
Aug 26, 2019
Merged

Cameron Trando (CTrando) merged 8 commits into
microsoft:masterfrom
CTrando:scratch/TypeVarBoundSupport

Conversation

@CTrando

@CTrando Cameron Trando (CTrando) commented Aug 20, 2019 •

Copy link
Copy Markdown
Contributor

Added support for return values as well.

Fixes #1242

The reason it fixes #1242 is that the typeshed says:

_P = TypeVar('_P', bound='PurePath')

if sys.version_info >= (3, 6):
    _PurePathBase = os.PathLike[str]
else:
    _PurePathBase = object

class PurePath(_PurePathBase):
    # ...
    def __truediv__(self: _P, key: Union[str, PurePath]) -> _P: ...
    if sys.version_info < (3,):
        def __div__(self: _P, key: Union[str, PurePath]) -> _P: ...

So the division operator returns _P, but the class is not generic on anything, so we are forced to use the upper bound PurePath for the return value of _P. Also, I added generic self capabilities to fix some test failures.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

3 participants