@@ -39,6 +39,18 @@ Glossary
39
39
and loaders (in the :mod: `importlib.abc ` module). You can create your own
40
40
ABCs with the :mod: `abc ` module.
41
41
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
+
42
54
argument
43
55
A value passed to a :term: `function ` (or :term: `method `) when calling the
44
56
function. There are two kinds of argument:
@@ -175,6 +187,15 @@ Glossary
175
187
normally contain method definitions which operate on instances of the
176
188
class.
177
189
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
+
178
199
coercion
179
200
The implicit conversion of an instance of one type to another during an
180
201
operation which involves two arguments of the same type. For example,
@@ -367,16 +388,19 @@ Glossary
367
388
and the :ref: `function ` section.
368
389
369
390
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
374
399
375
- See also the :term: ` variable annotation ` glossary entry .
400
+ Its syntax is explained in section :ref: ` function ` .
376
401
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.
380
404
381
405
__future__
382
406
A pseudo-module which programmers can use to enable new language features
@@ -1009,6 +1033,18 @@ Glossary
1009
1033
:attr: `~instance.__class__ ` attribute or can be retrieved with
1010
1034
``type(obj) ``.
1011
1035
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
+
1012
1048
universal newlines
1013
1049
A manner of interpreting text streams in which all of the following are
1014
1050
recognized as ending a line: the Unix end-of-line convention ``'\n' ``,
@@ -1017,17 +1053,21 @@ Glossary
1017
1053
:func: `bytes.splitlines ` for an additional use.
1018
1054
1019
1055
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
1025
1066
1026
- See also the :term: ` function annotation ` glossary entry .
1067
+ Its syntax is explained in section :ref: ` annassign ` .
1027
1068
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.
1031
1071
1032
1072
virtual environment
1033
1073
A cooperatively isolated runtime environment that allows Python users
0 commit comments