Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add stub for typing_extensions module
  • Loading branch information
Michael0x2a committed Jul 21, 2017
commit 45f63936687570970ad547e8759ab982d69ae506
32 changes: 32 additions & 0 deletions third_party/2and3/typing_extensions.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import sys
import typing
from typing import (
ClassVar, ContextManager, Counter, DefaultDict, Deque,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To re-export this name, you need to say ClassVar as ClassVar (this also goes for the rest of this file).

@Michael0x2a Michael0x2a Jul 8, 2017 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure? The stub seemed to work when I tried using it with mypy -- all the types seemed to be correctly re-exported and I was able to successfully typecheck my test files. Or is there something I'm missing?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think mypy doesn't implement that part of PEP 484 correctly.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, you're right! I did not know PEP 484 said that. Fixed.

NewType, overload, Text, TYPE_CHECKING,
)

if sys.version_info >= (3, 3):
from typing import ChainMap

if sys.version_info >= (3, 5):
from typing import (
AsyncIterable, AsyncIterator, AsyncContextManager, Coroutine,
)

if sys.version_info >= (3, 6):
from typing import AsyncGenerator

if sys.version_info >= (3, 6):
from typing import Collection
else:
_T_co = typing.TypeVar('_T_co', covariant=True)
class Collection(typing.Sized,
typing.Iterable[_T_co],
typing.Container[_T_co],
typing.Generic[_T_co]):
...

# Return type that indicates a function does not return.
# This type is equivalent to the None type, but the no-op Union is necessary to
# distinguish the None type from the None value.
NoReturn = typing.Union[None]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not from typing import NoReturn as NoReturn?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The stubs for typing currently don't define NoReturn. I've added a TODO note mentioning that in my new commit. (Alternatively, I could do from mypy_extensions import NoReturn as NoReturn, though that seems a little backwards).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, any reason it isn't in typing.pyi yet? Maybe we can just fix that in this PR. If you'd prefer not to, I'll just merge this.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be my fault. I probably just forgot to add the stub when I added NoReturn to typing.

@Michael0x2a Michael0x2a Jul 20, 2017 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...now that I think about it, I have no idea -- it seems like an oversight?

I'd prefer keeping that change separate from this PR to keep the git history clean -- I made a separate pull request to add NoReturn and can rebase/fix this one once the other one is merged? (Or vice-versa)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I merged your other PR, so the comment and this line can now be replaced.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, I updated this pull request.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JelleZijlstra Ping -- not sure if you saw my comment up above?