Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds docs about types module #11285

Closed
wants to merge 1 commit into from
Closed

Adds docs about types module #11285

wants to merge 1 commit into from

Conversation

sobolevn
Copy link
Member

@sobolevn sobolevn commented Oct 6, 2021

Closes #11275

``typing`` is used for type annotations,
while ``types`` is used to define useful runtime types and primitives.

Types from ``types`` module are not recognised by a type checker,
Copy link
Member

Choose a reason for hiding this comment

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

This isn't always true; a few types in types are useful in annotations (e.g. TracebackType, which is used in __exit__ annotations).

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh no 😆

I was not aware of that. Any others?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think some people use types.FunctionType? Also I think I've seen types.ModuleType a few times.

Copy link
Contributor

Choose a reason for hiding this comment

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

Various types in types are properly typed and recognized by type checkers, such as GeneratorType, MappingProxyType, EllipsisType.

Copy link
Member Author

Choose a reason for hiding this comment

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

@ethanhs ok, then we need a new plan. Maybe we can focus on "valid" usecases of using types? Experience from typeshed will totally help! 👍

@hauntsaninja
Copy link
Collaborator

I also don't know that this is a particularly common issue.

@KotlinIsland
Copy link
Contributor

KotlinIsland commented Oct 7, 2021

I also don't know that this is a particularly common issue.

From my experience it is common, people be seeing a module called types and thing that it's good for typing, but it isn't 😳😳😳😳.

@KotlinIsland
Copy link
Contributor

related: #11288

@hauntsaninja
Copy link
Collaborator

hauntsaninja commented Oct 7, 2021

I'm not saying confusion isn't understandable, nor that we shouldn't have documentation addressing this. Just that few users have even heard of types in the first place, so not sure this is the right page for it... For context, other material on the common issues page includes "if you don't put a type on your code, mypy won't check it", which is something nearly every user of mypy will run into.

@sobolevn
Copy link
Member Author

sobolevn commented Oct 7, 2021

I also don't know that this is a particularly common issue.

Citing @erictraut #11286 (comment)

Symbols within the types module are not meant to be used in type annotations within typical code. We regularly need to explain in mypy and pyright issue trackers not to use FunctionType, CoroutineType, etc. repeatedly.

@sobolevn sobolevn marked this pull request as draft October 7, 2021 09:27
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None alias for NoneType doesn't work on generic bound when using type of the generic
5 participants