@@ -25,8 +25,8 @@ Final names
25
25
26
26
You can use the ``typing.Final `` qualifier to indicate that
27
27
a name or attribute should not be reassigned, redefined, or
28
- overridden. This is often useful for module and class level constants
29
- as a way to prevent unintended modification. Mypy will prevent
28
+ overridden. This is often useful for module and class- level
29
+ constants to prevent unintended modification. Mypy will prevent
30
30
further assignments to final names in type-checked code:
31
31
32
32
.. code-block :: python
@@ -70,23 +70,23 @@ You can use ``Final`` in one of these forms:
70
70
71
71
ID : Final[int ] = 1
72
72
73
- Here mypy will infer type ``int `` for ``ID ``.
73
+ Here, mypy will infer type ``int `` for ``ID ``.
74
74
75
75
* You can omit the type:
76
76
77
77
.. code-block :: python
78
78
79
79
ID : Final = 1
80
80
81
- Here mypy will infer type ``Literal[1] `` for ``ID ``. Note that unlike for
82
- generic classes this is *not * the same as ``Final[Any] ``.
81
+ Here, mypy will infer type ``Literal[1] `` for ``ID ``. Note that unlike for
82
+ generic classes, this is *not * the same as ``Final[Any] ``.
83
83
84
- * In class bodies and stub files you can omit the right hand side and just write
84
+ * In class bodies and stub files, you can omit the right- hand side and just write
85
85
``ID: Final[int] ``.
86
86
87
87
* Finally, you can write ``self.id: Final = 1 `` (also optionally with
88
88
a type in square brackets). This is allowed *only * in
89
- :py:meth: `__init__ <object.__init__> ` methods, so that the final instance attribute is
89
+ :py:meth: `__init__ <object.__init__> ` methods so the final instance attribute is
90
90
assigned only once when an instance is created.
91
91
92
92
Details of using ``Final ``
@@ -129,7 +129,7 @@ the scope of a final declaration automatically depending on whether it was
129
129
initialized in the class body or in :py:meth: `__init__ <object.__init__> `.
130
130
131
131
A final attribute can't be overridden by a subclass (even with another
132
- explicit final declaration). Note however that a final attribute can
132
+ explicit final declaration). Note, however, that a final attribute can
133
133
override a read-only property:
134
134
135
135
.. code-block :: python
@@ -176,12 +176,12 @@ overriding. You can use the ``typing.final`` decorator for this purpose:
176
176
This ``@final `` decorator can be used with instance methods, class methods,
177
177
static methods, and properties.
178
178
179
- For overloaded methods you should add ``@final `` on the implementation
179
+ For overloaded methods, you should add ``@final `` on the implementation
180
180
to make it final (or on the first overload in stubs):
181
181
182
182
.. code-block :: python
183
183
184
- from typing import Any , overload
184
+ from typing import final , overload
185
185
186
186
class Base :
187
187
@overload
@@ -224,7 +224,7 @@ Here are some situations where using a final class may be useful:
224
224
225
225
An abstract class that defines at least one abstract method or
226
226
property and has ``@final `` decorator will generate an error from
227
- mypy, since those attributes could never be implemented.
227
+ mypy since those attributes could never be implemented.
228
228
229
229
.. code-block :: python
230
230
0 commit comments