File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
Expand file tree Collapse file tree 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::
207207item or a :ref: `NamedTuple <namedtuple >` field. Such usage also generates
208208an error at runtime.
209209
210+
211+ Importing ``Final `` Variables
212+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
213+
214+ If a module declares a ``Final `` variable and another module imports that
215+ variable by name or by wildcard import, the imported symbol inherits the
216+ ``Final `` type qualifier. Any attempt to assign a different value to this
217+ 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+
210238.. _`annotated` :
211239
212240``Annotated ``
You can’t perform that action at this time.
0 commit comments