Compiling Typed Python

  • I would like to note in this code example:

        class C(int):
            def __add__(self, other):
                return "no"  # sigh
    
    ->

        class C(int):
            def __add__(self, other: int) -> str:
                return "no"  # sigh
    
    Proper type annotations and using strict mypy type checking will throw an error.

        test.py:2: error: Return type "str" of "__add__" incompatible with return type "int" in supertype "int"  [override]
    
    This is again brought up later in the article.

    I also thought it was odd to diverge into attempts to compile (against?) non-typed code. That seems at odds with the premise of the article.

    This is still a really good article. Just a little meandering.

  • I like how with python you need to put quotes around "pseudocode" because the pseudocode is actually functional.

  • If you look the example code you will also immediately understand why Python is “slow”. Also for some easy performance gains Python should forfeit some of this dynamism and optionality and just give types like int (no subclassing).

  • I like to say that it would be nice if python had as much money invested as javascript.

  • I hate when people say "python is a simple language" when having this opinion requires ignoring everything about how python is designed (more like patched together), and requires using some non-standard definition of "simple".

  • OP you mentioned mojo, have you tried it yet? Jeremy from fast ai (one of their advisors) overhyped it so much I’m taking their claims with a grain of salt for now.

  • Interesting that you mention TorchScript, but not TorchDynamo+TorchInductor from PT2.

  • I immediately did a whois search on the domain, unfortunately couldn't prove it came from the Berenstein bears universe