-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[dataclass_transform] support implicit default for "init" parameter i…
…n field specifiers (#15010) (Basic functionality was implemented by @wesleywright in #14870. I added overload resolution.) This note from PEP 681 was missed in the initial implementation of field specifiers: > If unspecified, init defaults to True. Field specifier functions can use overloads that implicitly specify the value of init using a literal bool value type (Literal[False] or Literal[True]). This commit adds support for reading a default from the declared type of the `init` parameter if possible. Otherwise, it continues to use the typical default of `True`. The implementation was non-trivial, since regular overload resolution can't be used in the dataclass plugin, which is applied before type checking. As a workaround, I added a simple overload resolution helper that should be enough to support typical use cases. It doesn't do full overload resolution using types, but it knows about `None`, `Literal[True]` and `Literal[False]` and a few other things. --------- Co-authored-by: Wesley Collin Wright <[email protected]>
- Loading branch information
1 parent
16bd311
commit 0f09be4
Showing
7 changed files
with
299 additions
and
12 deletions.
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
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
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
Oops, something went wrong.