#Python optional values for complex types?

1 messages · Page 1 of 1 (latest)

slim shell
#

I am trying to make a Secret arg optional. So I set it like

        arty_token: Annotated[
            dagger.Secret,
            Doc("Artifactory token for authentication"),
        ]
        | None,

Then validate if it's not None and set it. However, I get runtime errors from beartype.

BeartypeDecorHintNonpepException: Is_bearable() type hint
typing.Optional[dagger.Secret] invalid or unrecognized. This hint is either:
* PEP-noncompliant (and thus invalid). This is your bad. Rejoice! @beartype
isn't to blame for once.
* PEP-compliant but currently unsupported by @beartype (and thus unrecognized).
This is our bad. Disaster! @beartype is to blame like always. You suddenly feel
encouraged to submit a feature request for this unsupported hint to our friendly
issue tracker at:
        https://github.com/beartype/beartype/issues

What am I doing wrong? I am a python newbie so this is taking me for a loop 😦

#

The example in the dagger docs only shows an optional value for a string. It would be good if that can be expanded a bit for future reference

boreal thicket
#

@slim shell Annotated[dagger.Secret | None, Doc("Optional secret")] should work IIRC.

slim shell
#

oh! let me try that

slim shell
#

That worked! Thanks marco. The Annotated put me off. I think this doc can be improved with more examples https://docs.dagger.io/api/arguments/#optional-arguments

Dagger Functions, just like regular functions, can accept arguments. In addition to basic types (string, boolean, integer, arrays...), Dagger also defines powerful core types which Dagger Functions can use for their arguments, such as Directory, Container, Service, Secret, and many more.

compact tree
left isle