Skip to content

Commit cfc2827

Browse files
committed
address review comments
1 parent 958bb7e commit cfc2827

File tree

1 file changed

+14
-32
lines changed

1 file changed

+14
-32
lines changed

docs/guides/writing_stubs.rst

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,8 @@ Liskov substitutability or detecting problematic overloads.
9393
It may be instructive to examine `typeshed <https://github.com/python/typeshed/>`__'s
9494
`setup for testing stubs <https://github.com/python/typeshed/blob/main/tests/README.md>`__.
9595

96-
To suppress type errors on stubs:
97-
* use mypy error codes for mypy-specific `# type: ignore` annotations, e.g. `# type: ignore[override]` for Liskov Substitution Principle violations.
98-
* use pyright error codes for pyright-specific suppressions, e.g. `# pyright: ignore[reportGeneralTypeIssues]`. Pyright is configured to discard `# type: ignore` annotations.
99-
* If you need both on the same line, mypy's annotation needs to go first, e.g. `# type: ignore[override] # pyright: ignore[reportGeneralTypeIssues]`.
96+
To suppress type errors on stubs, use a `# type: ignore` comment. Refer to the style guide for
97+
error suppression formats specific to individual typecheckers.
10098

10199
..
102100
TODO: consider adding examples and configurations for specific type checkers
@@ -538,7 +536,7 @@ No::
538536

539537
class Foo: # leave only one empty line above
540538
x: int
541-
class MyError(Exception): ...
539+
class MyError(Exception): ... # leave an empty line between the classes
542540

543541
Module Level Attributes
544542
-----------------------
@@ -802,37 +800,21 @@ into any of those categories, use your best judgement.
802800
* Use `HasX` for protocols that have readable and/or writable attributes
803801
or getter/setter methods (e.g. `HasItems`, `HasFileno`).
804802

803+
Type Checker Error Suppression formats
804+
--------------------------------------
805+
806+
* Use mypy error codes for mypy-specific `# type: ignore` annotations, e.g. `# type: ignore[override]` for Liskov Substitution Principle violations.
807+
* Use pyright error codes for pyright-specific suppressions, e.g. `# pyright: ignore[reportGeneralTypeIssues]`. Pyright is configured to discard `# type: ignore` annotations.
808+
* If you need both on the same line, mypy's annotation needs to go first, e.g. `# type: ignore[override] # pyright: ignore[reportGeneralTypeIssues]`.
809+
810+
805811
`@deprecated`
806812
-------------
807813

808814
The `@typing_extensions.deprecated` decorator (`@warnings.deprecated`
809815
since Python 3.13) can be used to mark deprecated functionality; see
810816
[PEP 702](https://peps.python.org/pep-0702/).
811817

812-
A few guidelines for how to use it:
813-
814-
* In the standard library, apply the decorator only in Python versions
815-
where an appropriate replacement for the deprecated functionality
816-
exists. If in doubt, apply the decorator only on versions where the
817-
functionality has been explicitly deprecated, either through runtime
818-
warnings or in the documentation. Use `if sys.version_info` checks to
819-
apply the decorator only to some versions.
820-
* Keep the deprecation message concise, but try to mention the projected
821-
version when the functionality is to be removed, and a suggested
822-
replacement.
823-
824-
Imports
825-
-------
826-
827-
Imports in stubs are considered private (not part of the exported API)
828-
unless:
829-
* they use the form ``from library import name as name`` (sic, using explicit ``as`` even if the name stays the same); or
830-
* they use the form ``from library import *`` which means all names from that library are exported.
831-
832-
Forward References
833-
------------------
834-
835-
Stub files support forward references natively. In other words, the
836-
order of class declarations and type aliases does not matter in
837-
a stub file. Unlike regular Python files, you can use the name of the class within its own
838-
body without writing it as a comment.
818+
Keep the deprecation message concise, but try to mention the projected
819+
version when the functionality is to be removed, and a suggested
820+
replacement.

0 commit comments

Comments
 (0)