Created
August 24, 2020 03:11
-
-
Save mitsuse/c3ba46d6aaebe388d2c9eb92cf9a07d1 to your computer and use it in GitHub Desktop.
Revisions
-
mitsuse created this gist
Aug 24, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ from __future__ import annotations from typing_extensions import Final from dataclasses import dataclass @dataclass class A: x: Final[int] = 100 # x: Final[int] # error: Final name must be initialized with a value class B: x: Final[int] def __init__(self, x: int) -> None: self.x = x a = A(200) # error: Cannot assign to final attribute "x" # a.x = 20 print(a) # A(x=200)