serhii.net

In the middle of the desert you can say anything you want

07 Sep 2022

Python pattern fail on multiple conditions

From OmegaConf source:

def fail() -> None:
	raise ValueError("Input list must be a list or a tuple of strings")

if not isinstance(dotlist, (list, tuple)):
	fail()

for arg in dotlist:
	if not isinstance(arg, str):
		fail()

I don’t know if I like this or not, but it’s interesting. But I did write similar things with a parametrized fail()

Nel mezzo del deserto posso dire tutto quello che voglio.