Skip to content

Support more complex types by using generics #93

@matts1

Description

@matts1

It's currently very hard to work with custom providers. One example of somewhere seriously lacking is if I want to do assertions on the following type:

FooInfo = provider(fields = {"name": "str")
BarInfo = provider(fields = {
    "foos": "(depset[Foo]) the foos",
})

I would like to be able to write something like:

env.expect.that_provider(BarInfo).foos()
  .contains_at_least_predicates(lambda foo: foo.name().equals("foo"))

I propose that we allow generics by turning generic types into functions. For example:

FooInfoSubject = subjects.struct(name = subjects.string)
BarInfoSubject = subjects.struct(
    foos = subjects.depset(FooInfoSubject)
)

This would make the above predicates far more easily implemented (although the caveat is that it would require a change in matchers so that you could simply use them as a boolean predicate - at the moment, not matching simply fails the test).

We could also use this to easily solve #63 via the generic type subjects.optional (eg. subjects.optional(subjects.string)).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions