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

Merge the specification portion of the "Type Stubs" doc into the spec #1815

Merged
merged 46 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
7f260c8
Type Stubs: move intro and syntax to spec.
rchen152 Jun 28, 2024
1d29334
Move "Stub Contents" to writing_stubs.
rchen152 Jun 28, 2024
065c3d3
Moves "Style Guide" to writing_stubs doc.
rchen152 Jun 28, 2024
d283c38
Change :ref:`stubs` occurrences to :ref:`stub-files`.
rchen152 Jul 2, 2024
01b34ca
Move a few "Supported Constructs" sections into spec.
rchen152 Jul 3, 2024
be35ffe
Migrated "Imports" and "Module Level Attributes" supported constructs.
rchen152 Jul 12, 2024
00766db
Migrate "Enums" supported construct section.
rchen152 Jul 13, 2024
c524da4
Move "Classes" and "Decorators" supported constructs sections.
rchen152 Jul 20, 2024
abd198f
Port "Functions and Methods" supported constructs section.
rchen152 Jul 20, 2024
e0b16d9
Adds an "Import Conventions" section (deduplication).
rchen152 Jul 20, 2024
b3e9b9c
Remove missed reference to deleted stubs doc.
rchen152 Jul 22, 2024
31c52c0
Fix broken refs.
rchen152 Jul 22, 2024
90170aa
Formatting fix to docs/guides/writing_stubs.rst
rchen152 Jul 23, 2024
e9d3211
Reword paragraph on argument names to be more concise.
rchen152 Jul 23, 2024
4c7fee2
Wording clarification in docs/guides/writing_stubs.rst
rchen152 Jul 23, 2024
60d80d8
Modernize code example in docs/guides/writing_stubs.rst
rchen152 Jul 23, 2024
a2a9d72
Typo fix in docs/spec/distributing.rst
rchen152 Jul 23, 2024
0c3bd2c
Typo fix in docs/spec/distributing.rst
rchen152 Jul 23, 2024
da4571e
Grammar fixes
rchen152 Jul 23, 2024
1e609fe
Property deleters should also be understood.
rchen152 Jul 23, 2024
05434ed
Address future notes.
rchen152 Jul 24, 2024
6a8a26e
Fix silly formatting error.
rchen152 Jul 24, 2024
2a927e6
Merge branch 'main' into stubs
rchen152 Jul 26, 2024
10cb969
Undelete stubs.rst.
rchen152 Jul 27, 2024
026f2a1
Merge branch 'main' into stubs
rchen152 Jul 29, 2024
46e133f
Address review comments.
rchen152 Jul 29, 2024
8a9eda8
Address more review comments.
rchen152 Jul 30, 2024
14966d2
Remove no-longer-needed anchor.
rchen152 Jul 30, 2024
1ab8a33
And add back an accidentally deleted newline...
rchen152 Jul 30, 2024
df94e57
Slight rewording of Decorators advice.
rchen152 Jul 31, 2024
93ce31d
Address more reviewer comments.
rchen152 Jul 31, 2024
61dafc4
Remove extra colon.
rchen152 Jul 31, 2024
fe4c850
Revert changes to wrting_stubs that should be made separately.
rchen152 Jul 31, 2024
99df017
Merge branch 'main' into stubs
rchen152 Aug 1, 2024
7bf4ce5
Delete unnecessary sentence.
rchen152 Aug 1, 2024
6bbcff7
Clarify some language and terminology.
rchen152 Aug 1, 2024
15adb5b
Merge branch 'main' into stubs
rchen152 Aug 9, 2024
98a72e7
Address reviewer feedback.
rchen152 Aug 9, 2024
a448b4a
Formatting
rchen152 Aug 9, 2024
eaaade2
Drop "annotation contexts."
rchen152 Aug 9, 2024
f270102
Merge branch 'main' into stubs
rchen152 Aug 9, 2024
8d18706
Add "in annotation expressions" to newer syntax explanation.
rchen152 Aug 9, 2024
783b435
Update docs/spec/distributing.rst
rchen152 Aug 13, 2024
6f030ad
Reword syntax section.
rchen152 Aug 15, 2024
fb8c354
Update docs/spec/distributing.rst
rchen152 Aug 20, 2024
4723972
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 20, 2024
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
49 changes: 3 additions & 46 deletions docs/guides/libraries.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ library:

Inline type annotations simply refers to the use of annotations within your
``.py`` files. In contrast, with type stub files, type information lives in
separate ``.pyi`` files; see :ref:`stubs` and :ref:`writing_stubs` for more
separate ``.pyi`` files; see :ref:`stub-files` and :ref:`writing_stubs` for more
details.

We recommend using the inline type annotations approach, since it has the
Expand Down Expand Up @@ -193,51 +193,8 @@ How much of my library needs types?
A "py.typed" library should aim to be type complete so that type
checking and inspection can work to their full extent. Here we say that a
library is “type complete” if all of the symbols
that comprise its interface have type annotations that refer to types
that are fully known. Private symbols are exempt.

Library interface (public and private symbols)
----------------------------------------------

If a ``py.typed`` module is present, a type checker will treat all modules
within that package (i.e. all files that end in ``.py`` or ``.pyi``) as
importable unless the file name begins with an underscore. These modules
comprise the supported interface for the library.

Each module exposes a set of symbols. Some of these symbols are
considered "private” — implementation details that are not part of the
library’s interface. Type checkers can use the following rules
to determine which symbols are visible outside of the package.

- Symbols whose names begin with an underscore (but are not dunder
names) are considered private.
- Imported symbols are considered private by default. If they use the
``import A as A`` (a redundant module alias), ``from X import A as A`` (a
redundant symbol alias), or ``from . import A`` forms, symbol ``A`` is
not private unless the name begins with an underscore. If a file
``__init__.py`` uses form ``from .A import X``, symbol ``A`` is treated
likewise. If a wildcard import (of the form ``from X import *``) is
used, all symbols referenced by the wildcard are not private.
- A module can expose an ``__all__`` symbol at the module level that
provides a list of names that are considered part of the interface.
This overrides all other rules above, allowing imported symbols or
symbols whose names begin with an underscore to be included in the
interface.
- Local variables within a function (including nested functions) are
always considered private.

The following idioms are supported for defining the values contained
within ``__all__``. These restrictions allow type checkers to statically
determine the value of ``__all__``.

- ``__all__ = ('a', b')``
- ``__all__ = ['a', b']``
- ``__all__ += ['a', b']``
- ``__all__ += submodule.__all__``
- ``__all__.extend(['a', b'])``
- ``__all__.extend(submodule.__all__)``
- ``__all__.append('a')``
- ``__all__.remove('a')``
that comprise its :ref:`interface <library-interface>` have type annotations
that refer to types that are fully known. Private symbols are exempt.

Type Completeness
-----------------
Expand Down
2 changes: 1 addition & 1 deletion docs/guides/writing_stubs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Writing and Maintaining Stub Files
**********************************

Stub files are a means of providing type information for Python modules.
For a full reference, refer to :ref:`stubs`.
For a full reference, refer to :ref:`stub-files`.

Maintaining stubs can be a little cumbersome because they are separated from the
implementation. This page lists some tools that make writing and maintaining
Expand Down
1 change: 0 additions & 1 deletion docs/reference/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ Type System Reference

generics
protocols
stubs
best_practices
quality
typing Module Documentation <https://docs.python.org/3/library/typing.html>
Loading