>
> For an example. Anyone is free to use, but I'm not claiming it's
> necessarily the best. This is from... well, probably not yesterday like I
> said in other comment, but a couple days ago. The module `jsonschema` has
> an API where it raises an exception if `validate()` doesn't succeed (None
> if things are happy). I don't love that API, so want to wrap it.
>
> def not_valid(instance, schema):
> try:
> return validate(instance, schema)
> except ValidationError as err:
> return str(err)
>
> I really wanted that to be one line rather than a helper function, and it
> really feels like it should be possible... and yet.
>
Incidentally, this is also helped greatly by the Walrus operator. With the
support function I write:
if msg := not_valid(instance, schema):
print("The problem is:", msg) # The exception contains detailed
diagnosis
else:
do_json_stuff(instance)
--
The dead increasingly dominate and strangle both the living and the
not-yet born. Vampiric capital and undead corporate persons abuse
the lives and control the thoughts of homo faber. Ideas, once born,
become abortifacients against new conceptions.
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/37XWNBFW5WQQI32TONYES6GZTNYU5W3I/
Code of Conduct: http://python.org/psf/codeofconduct/