Feature request: treat absent values for dataclasses as default
See original GitHub issueSuppose we have a config like this:
some_key {
importantProperty = some_value
}
and trying to read data class by some_key
:
data class SomeKeyConfig(
val importantProperty: String,
val minorProperty: Int = 500
)
val config = Config.extract<SomeKeyConfig>("some_key")
Current behavior is IllegalArgumentException
. So, one should mark minorProperty
as nullable and provide custom getter. It would be nice to avoid that and simply get a data class with default values where needed.
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
dataclasses — Data Classes — Python 3.11.1 documentation
If dataclass() is used just as a simple decorator with no parameters, it acts as if it has the default values documented in...
Read more >Support dataclass default None as allowed type #99 - GitHub
marshmallow_dataclass seems to support optional declaration through default None in both cases. Is it forbidden in desert by design?
Read more >dataclasses — Data Classes — Stackless-Python 3.7.9 ...
If dataclass() is used just as a simple decorator with no parameters, it acts as if it has the default values documented in...
Read more >Data Classes in Python 3.7+ (Guide)
Data classes are one of the new features of Python 3.7. ... How to add default values to data class fields; How data...
Read more >Class inheritance in Python 3.7 dataclasses - Stack Overflow
When a dataclass inherits from another dataclass, and the base class has fields with default values, then all of the fields in the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Looks good for my use-case. Looking at code - isn’t there a possible caveat with
null
values? HOCON allows to usenull
value. There may be a problem with (may be you should write a test for it)From this config,
Person(10, null)
is expected.Fixed in 263a89a494e3a7101517c30afbc1c39a9acf53fe