Skip to content

Various improvements to the Type Stubs document#846

Merged
srittau merged 1 commit intopython:masterfrom
srittau:stub-docs
Aug 24, 2021
Merged

Various improvements to the Type Stubs document#846
srittau merged 1 commit intopython:masterfrom
srittau:stub-docs

Conversation

@srittau
Copy link
Collaborator

@srittau srittau commented Aug 23, 2021

  • Rename "Abstract" to "Introduction" and remove fluff originally intended
    for the PEP.
  • "This PEP" -> "This document"
  • Remove note about the living document status. This is a given, not that
    it isn't a PEP anymore.
  • Third-party stubs are now distributed via PyPI.
  • Mention "# type: ignore[xxx]".
  • Fix indentation.
  • Reformulate sentence about cyclic imports.
  • Use type vars correctly in example.
  • Use new union syntax.
  • Remove "we" from sentence and slightly reformulate.
  • Clarify that "# incomplete" is mainly intended for stub authors.
  • Mention "X | Any" return type. Still needs to be explained.

* Rename "Abstract" to "Introduction" and remove fluff originally intended
  for the PEP.
* "This PEP" -> "This document"
* Remove note about the living document status. This is a given, not that
  it isn't a PEP anymore.
* Third-party stubs are now distributed via PyPI.
* Mention "# type: ignore[xxx]".
* Fix indentation.
* Reformulate sentence about cyclic imports.
* Use type vars correctly in example.
* Use new union syntax.
* Remove "we" from sentence and slightly reformulate.
* Clarify that "# incomplete" is mainly intended for stub authors.
* Mention "X | Any" return type. Still needs to be explained.
@srittau
Copy link
Collaborator Author

srittau commented Aug 23, 2021

This includes most of @Akuli's comments, although a few still need to be incorporated.

variable annotations are preferred over type comments.
* A ``# type: ignore`` comment at the end of any line, which suppresses all type
errors in that line.
errors in that line. The type checker mypy supports suppressing certain
Copy link
Member

Choose a reason for hiding this comment

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

If I recall correctly some other type checkers support similar constructs. A comparison table could be a useful part of the typing docs.

Avoid ``Union`` return types, since they require ``isinstance()`` checks.
Use ``Any`` if necessary.
Avoid union return types, since they require ``isinstance()`` checks.
Use ``Any`` or ``X | Any`` if necessary.
Copy link
Member

Choose a reason for hiding this comment

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

It would be useful to explain more about how the X | Any trick works: when should you use it? what does it do?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Indeed, but as this is not stubs-specific, probably in a best practices document?

@srittau srittau merged commit ce2ea20 into python:master Aug 24, 2021
@srittau srittau deleted the stub-docs branch August 24, 2021 06:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants