Skip to content

Commit f2290fb

Browse files
andresdelfinoilevkivskyi
authored andcommitted
bpo-32769: Write annotation entry for glossary (GH-6657)
https://bugs.python.org/issue32769
1 parent 0ded580 commit f2290fb

File tree

1 file changed

+57
-17
lines changed

1 file changed

+57
-17
lines changed

Doc/glossary.rst

Lines changed: 57 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@ Glossary
3939
and loaders (in the :mod:`importlib.abc` module). You can create your own
4040
ABCs with the :mod:`abc` module.
4141

42+
annotation
43+
A metadata value associated with a global variable, a class attribute or a
44+
function or method parameter or return value, that stores a
45+
:term:`type hint`.
46+
47+
Annotations are stored in the :attr:`__annotations__` special attribute
48+
of a module (when annotating a global variable), class (when annotating
49+
one of its attributes) or function or method (when annotating a parameter or a
50+
return value) and can be accessed using :func:`typing.get_type_hints`.
51+
52+
See :pep:`484` and :pep:`526` which describe this functionality.
53+
4254
argument
4355
A value passed to a :term:`function` (or :term:`method`) when calling the
4456
function. There are two kinds of argument:
@@ -175,6 +187,15 @@ Glossary
175187
normally contain method definitions which operate on instances of the
176188
class.
177189

190+
class variable
191+
A variable defined in a class and intended to be modified only at
192+
class level (i.e., not in an instance of the class).
193+
194+
Class variables can be specified as such through
195+
:term:`type hints <type hint>`.
196+
197+
See :pep:`526` which describes class variable annotations.
198+
178199
coercion
179200
The implicit conversion of an instance of one type to another during an
180201
operation which involves two arguments of the same type. For example,
@@ -367,16 +388,19 @@ Glossary
367388
and the :ref:`function` section.
368389

369390
function annotation
370-
An arbitrary metadata value associated with a function parameter or return
371-
value. Its syntax is explained in section :ref:`function`. Annotations
372-
may be accessed via the :attr:`__annotations__` special attribute of a
373-
function object.
391+
An :term:`annotation` of a function, or a method.
392+
393+
For example, this function has its parameters annotated as taking
394+
:class:`int` arguments and its return value annotated as being an
395+
:class:`int` as well::
396+
397+
def sum_two_numbers(a: int, b: int) -> int:
398+
return a + b
374399

375-
See also the :term:`variable annotation` glossary entry.
400+
Its syntax is explained in section :ref:`function`.
376401

377-
Annotations are meant to provide a standard way for programmers to
378-
document types of functions they design. See :pep:`484`, which
379-
describes this functionality.
402+
See also the :term:`variable annotation` glossary entry, and :pep:`484`,
403+
which describes this functionality.
380404

381405
__future__
382406
A pseudo-module which programmers can use to enable new language features
@@ -1009,6 +1033,18 @@ Glossary
10091033
:attr:`~instance.__class__` attribute or can be retrieved with
10101034
``type(obj)``.
10111035

1036+
type hint
1037+
A specification about the expected type for a global variable, class
1038+
variable, function or method parameter or return value.
1039+
1040+
While type hints are optional and are not enforced by Python when used,
1041+
they are useful for static type analysis tools, and aid IDEs on code
1042+
completion and refactoring.
1043+
1044+
Type hints are stored in :term:`annotations <annotation>`.
1045+
1046+
See also :pep:`483` which describe this functionality.
1047+
10121048
universal newlines
10131049
A manner of interpreting text streams in which all of the following are
10141050
recognized as ending a line: the Unix end-of-line convention ``'\n'``,
@@ -1017,17 +1053,21 @@ Glossary
10171053
:func:`bytes.splitlines` for an additional use.
10181054

10191055
variable annotation
1020-
A type metadata value associated with a module global variable or
1021-
a class attribute. Its syntax is explained in section :ref:`annassign`.
1022-
Annotations are stored in the :attr:`__annotations__` special
1023-
attribute of a class or module object and can be accessed using
1024-
:func:`typing.get_type_hints`.
1056+
An :term:`annotation` of a global variable, or a class attribute.
1057+
1058+
For example, this variable is annotated as taking :class:`int` values::
1059+
1060+
count: int = 0
1061+
1062+
When annotating variables, assignment is optional::
1063+
1064+
class C:
1065+
field: int
10251066

1026-
See also the :term:`function annotation` glossary entry.
1067+
Its syntax is explained in section :ref:`annassign`.
10271068

1028-
Annotations are meant to provide a standard way for programmers to
1029-
document types of functions they design. See :pep:`484` and :pep:`526`
1030-
which describe this functionality.
1069+
See also the :term:`function annotation` glossary entry, and :pep:`484`
1070+
and :pep:`526` which describe this functionality.
10311071

10321072
virtual environment
10331073
A cooperatively isolated runtime environment that allows Python users

0 commit comments

Comments
 (0)