-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added special-case handling for instance variables in a dataclass tha…
…t are marked `Final`. Previously, these were flagged as an error because there was no explicit value assigned to them, but the synthesized `__init__` method implicitly initializes them.
- Loading branch information
1 parent
248b8d2
commit a45b8dc
Showing
3 changed files
with
45 additions
and
1 deletion.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# This sample tests that instance variables declared as Final within | ||
# a dataclass do not need to have an explicit assignment because | ||
# the generated __init__ method will assign them. | ||
|
||
from dataclasses import dataclass | ||
from typing import Final | ||
|
||
|
||
class Foo1: | ||
x: Final[int] | ||
|
||
def __init__(self, x: int) -> None: | ||
self.x = x | ||
|
||
|
||
@dataclass | ||
class Foo2: | ||
x: Final[int] |
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