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

Support TypeVar bound #1463

Merged
CTrando merged 8 commits intomicrosoft:masterfrom
CTrando:scratch/TypeVarBoundSupport
Aug 26, 2019
Merged

Support TypeVar bound #1463
CTrando merged 8 commits intomicrosoft:masterfrom
CTrando:scratch/TypeVarBoundSupport

Conversation

@CTrando
Copy link
Copy Markdown
Contributor

@CTrando CTrando commented Aug 20, 2019

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Using the slash "/" operator between a PurePath and a str should have an inferred type of PurePath

3 participants