question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature request: treat absent values for dataclasses as default

See original GitHub issue

Suppose 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:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ov7acommented, Apr 9, 2018

Looks good for my use-case. Looking at code - isn’t there a possible caveat with null values? HOCON allows to use null value. There may be a problem with (may be you should write a test for it)

key = {
    age = 10
    name = null
}
data class Person(val age:Int, val name: String? = "Sir Null")

From this config, Person(10, null) is expected.

0reactions
mmorihirocommented, May 17, 2018

Fixed in 263a89a494e3a7101517c30afbc1c39a9acf53fe

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found