New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scala sealed trait ability (mostly) in dataconf using dataclass #10
Conversation
…sealed trait case class behavior with pureconfig
added the ability to read nested dataclass configs replicating Scala …
…ry toml; incremented to 0.1.6
@zifeo the lint test failed. Not sure why
|
@zifeo I see that from import dataconf
print(dataconf.__version__) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- pytest raise failure: which env/python version are you using? I see there are gone now.
- linting: some colons were missing. You can run the lint locally with
pre-commit run --all-files
and before every commit withpre-commit install
(run once for setup) - z-imports is a bit tricky, but including it in the explicit listing should do it.
Now regarding the global pull request, thank you for suggesting that change. Although I never used pure config, I get the idea. I see that you went for data classes nested under a classical class. Does this provide any advantage over simple inheritance (InputType.__subclasses__()
) or union type (InputType = Union[StringImpl, IntImpl]
)?
I was replicating the idea one would have using pureconfig with Hocon when I wrote Why I picked this method was just solely based on my experience from Scala. Anyone on data engineering side working with Scala would easily pick this up where I work since it would mimic our dataflow library usage. That was the motivation. If there is a better way, let me know. @zifeo |
…st comp from the for loop arg break down the for loop resulting in 0.4-0.35 test times to 0.25
@dwsmith1983 What kind of failure do you get from the subclass approach? Currently if you use the union type, it does not use https://github.com/zifeo/dataconf/pull/10/files#diff-4198c13639f9dd31ef7b259b7e7167468728b79898427be0fa2e3be56f4526acR116-R127, right? |
With union, correct it skips it. With |
@dwsmith1983 I was thinking of something like class Parent:
pass
@dataclass
class StringImpl(Parent):
name: Text
age: Text
@dataclass
class IntImpl(Parent):
area_code: int
phone_num: Text
@dataclass
class Base:
location: Text
input_source: Parent
str_conf = """
{
location: Europe
input_source {
name: Thailand
age: "12"
}
}
""" |
@zifeo wouldn't need to make parent then an ABC class which would be nice with the abstract methods and overriding. That would be seamless transition from Scala/Java hocon with traits to Python. |
@dwsmith1983 not really fan of the |
@zifeo have you tested the syntax you suggested? I just gave it try. I didn't step through it but from the error, it looks like the same is occurring I just stepped through it. It is class but the overriding classes of StringImp and IntImpl aren't seen from |
@dwsmith1983 can you push your changes? I will give it a try. |
@zifeo pushed |
@zifeo any updates? |
@dwsmith1983 What about the following?
|
@zifeo I added it over. I removed |
child_failures.append(str(f)) | ||
|
||
# no need to check length; false if empty | ||
if child_failures: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here I removed the length check @zifeo
try: | ||
return __parse(value, child_clazz, path) | ||
except TypeConfigException as f: | ||
child_failures.append(str(f)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zifeo also changed f
to str(f)
for the join. We will need a test for failure too to make sure all is working.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's update the doc and all good.
@zifeo updated doc and added a fail test check for the abstract class trait |
@zifeo added the ability for nested dataclass methods (sealed trait pureconfig functionality in Scala), updated README, incremented to 0.1.6, and created version.py which will provide version and get the latest from the pyproject.toml
Also, on my local, the following test always fails. How do I get it to pass?