Skip to content

Adds docs about types module - #11285

Closed
sobolevn wants to merge 1 commit into
python:masterfrom
sobolevn:issue-11275
Closed

sobolevn wants to merge 1 commit into
python:masterfrom
sobolevn:issue-11275

Conversation

@sobolevn

@sobolevn sobolevn commented Oct 6, 2021

Copy link
Copy Markdown
Member

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
Copy Markdown
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
Copy Markdown
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
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 some people use types.FunctionType? Also I think I've seen types.ModuleType a few times.

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Collaborator

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

@KotlinIsland

KotlinIsland commented Oct 7, 2021 •

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor

related: #11288

@hauntsaninja

hauntsaninja commented Oct 7, 2021 •

Copy link
Copy Markdown
Collaborator

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

sobolevn commented Oct 7, 2021 •

Copy link
Copy Markdown
Member Author

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