Skip to content

How to assert the type of loaded value? #92

@koterpillar

Description

@koterpillar

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions