@@ -43,11 +43,11 @@ neither of the above use cases can be solved with it.
43
43
.. note ::
44
44
45
45
This is an experimental feature. Some details might change in later
46
- versions of mypy. The final qualifiers are available in `` typing_extensions ``
47
- module .
46
+ versions of mypy. The final qualifiers are available in the
47
+ `` typing_extensions `` package available on PyPI .
48
48
49
- Definition syntax
50
- *****************
49
+ Syntax variants
50
+ ***************
51
51
52
52
The ``typing_extensions.Final `` qualifier indicates that a given name or
53
53
attribute should never be re-assigned, re-defined, nor overridden. It can be
@@ -64,10 +64,10 @@ used in one of these forms:
64
64
classes this is *not * the same as ``Final[Any] ``. Here mypy will infer
65
65
type ``int ``.
66
66
67
- * In stub files one can omit the right hand side and just write
67
+ * In stub files you can omit the right hand side and just write
68
68
``ID: Final[float] ``.
69
69
70
- * Finally, one can define ``self.id: Final = 1 `` (also with a type argument),
70
+ * Finally, you can define ``self.id: Final = 1 `` (also with a type argument),
71
71
but this is allowed *only * in ``__init__ `` methods.
72
72
73
73
Definition rules
@@ -104,14 +104,15 @@ The are two rules that should be always followed when defining a final name:
104
104
ID = 1
105
105
ID : Final = 2 # Error!
106
106
107
- * A final attribute declared in class body without r.h.s. must be initialized
108
- in the ``__init__ `` method (one can skip initializer in stub files):
107
+ * A final attribute declared in class body without an initializer must
108
+ be initialized in the ``__init__ `` method (you can skip the initializer
109
+ in stub files):
109
110
110
111
.. code-block :: python
111
112
112
113
class SomeCls :
113
- x: Final
114
- y: Final # Error: final attribute without an initializer
114
+ x: Final[ int ]
115
+ y: Final[ int ] # Error: final attribute without an initializer
115
116
def __init__ (self ) -> None :
116
117
self .x = 1 # Good
117
118
0 commit comments