Created
August 24, 2020 03:11
-
-
Save mitsuse/c3ba46d6aaebe388d2c9eb92cf9a07d1 to your computer and use it in GitHub Desktop.
`typing_extensions.Final` cannot be used for dataclasses.
This file contains 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 characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment