-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Scala sealed trait ability (mostly) in dataconf using dataclass (#10)
* added the ability to read nested dataclass configs replicating Scala sealed trait case class behavior with pureconfig * removed print statment * updated README to demostrate sealed traits usage with dataconf and dataclasses * created version.py for __version__ which will populate from the library toml; incremented to 0.1.6 * called InputType and added return to sealed_trait * added a second method to test for nested dataclass * cleaned up fixed todo for the sealed trait mock testing * pre-commit doesnt __version__ is there a way to override this? * I see pre-commit looks at __all__; not really familiar with this library * fixed relative to abs import in test, removed old comment, removed list comp from the for loop arg break down the for loop resulting in 0.4-0.35 test times to 0.25 * updated the readme example to parallel the test * need to grab string name __name__ for getattr to use the new for loop * abstract input class with dataclass override * added @zifeo suggestion * updated README * removed conf assignment
- Loading branch information
1 parent
18e350a
commit 1a5257a
Showing
7 changed files
with
178 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import importlib.metadata | ||
|
||
__version__ = importlib.metadata.version("dataconf") |
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,30 @@ | ||
from dataclasses import dataclass | ||
from typing import Text | ||
|
||
|
||
class InputType: | ||
pass | ||
|
||
|
||
@dataclass(init=True, repr=True) | ||
class StringImpl(InputType): | ||
name: Text | ||
age: Text | ||
|
||
def test_method(self): | ||
return f"{self.name} is {self.age} years old." | ||
|
||
def test_complex(self): | ||
return int(self.age) * 3 | ||
|
||
|
||
@dataclass(init=True, repr=True) | ||
class IntImpl(InputType): | ||
area_code: int | ||
phone_num: Text | ||
|
||
def test_method(self): | ||
return f"The area code for {self.phone_num} is {str(self.area_code)}" | ||
|
||
def test_complex(self): | ||
return self.area_code - 10 |
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