dhall-python icon indicating copy to clipboard operation
dhall-python copied to clipboard

How to assert the type of loaded value?

Open koterpillar opened this issue 3 years ago • 0 comments

In Haskell bindings, I can use some typeclasses to load a Dhall value of an expected type (official example). I would like to do the same in Python:

@dataclass
class Example:
    foo: int
    bar: list[double]

x = dhall.load(open('./config'), type_=Example)

The intended result:

  • success if ./config defines a record with foo and bar
  • failure if ./config doesn't exist or isn't valid Dhall
  • failure if ./config defines any other Dhall value (number, boolean, different fields, etc.)

How do I do this with dhall-python? If it's not currently possible, any pointers on implementation?

koterpillar avatar Sep 15 '22 11:09 koterpillar