Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.


The 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.


I 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]]




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: