4 ms·
Can someone help me understand why the author is making it sound like def foo(bar, baz): if bar == “thing1” baz.methodFromTypeX() elif
by Spivak 6y ago
Can someone help me understand why the author is making it sound like
def foo(bar, baz):
if bar == “thing1”
baz.methodFromTypeX()
elif bar == “thing2”:
baz.methodFromTypeY()
is something super complicated? Like I get that in some respects the type signature for this method is funky and seems nigh impossible to encode in a type system (which I guess is the point) but this kind of thing is not at all hard to grok as a human.
- emptysea 6y agoI think if you settle for the args being combined into a tuple you could essentially create a tagged union and the type checker should be able to refine off the comparison. Type would be something like: Union[Tuple[Literal[“thing1”], TypeX], Tuple[Literal[“thing2”], TypeY]]
- t-writescode 6y agoThe problem comes when you have 500,000 lines of code across 10,000 files, all written with that style. Add in no comments or out of date comments or comments that were always wrong about function inputs and outputs and you get ... frustration.