Commit 811a867 1 parent 8d3f041 commit 811a867 Copy full SHA for 811a867
File tree 1 file changed +28
-0
lines changed
1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -207,6 +207,34 @@ following should be allowed::
207
207
item or a :ref: `NamedTuple <namedtuple >` field. Such usage also generates
208
208
an error at runtime.
209
209
210
+
211
+ Importing ``Final `` Variables
212
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
213
+
214
+ If a module declares a ``Final `` variable and another module imports that
215
+ variable in an import statement by name or wildcard, the imported symbol
216
+ inherits the ``Final `` type qualifier. Any attempt to assign a different value
217
+ to this symbol should be flagged as an error by a type checker::
218
+
219
+ # lib/submodule.py
220
+ from typing import Final
221
+ PI: Final = 3.14
222
+
223
+ # lib/__init__.py
224
+ from .submodule import PI # PI is Final
225
+
226
+ # test1.py
227
+ from lib import PI
228
+ PI = 0 # Error: Can't assign to Final value
229
+
230
+ from lib import PI as PI2
231
+ PI2 = 0 # Error: Can't assign to Final value
232
+
233
+ # test2.py
234
+ from lib import *
235
+ PI = 0 # Error: Can't assign to Final value
236
+
237
+
210
238
.. _`annotated` :
211
239
212
240
``Annotated ``
You can’t perform that action at this time.
0 commit comments