1. 4
  1.  

  2. 1

    I don’t think that’s exactly what Nystrom is saying. He gives this example for type checking Magpie:

    class Hello
    end
    
    def Hello say(greeting String ->) print(greeting)
    
    var main()
        var hello = Hello new
        hello say("Hello!")
    end
    

    When he says he’s type checking the executed methods, he means that they were loaded into global scope. No metaprogramming happens. In fact, right below that, he shows that metaprogramming will break his system. Arguably what he’s describing is “gradual typing”. This is exactly what mypy does, too:

    def say(greeting: str):
        print(greeting)
    
    say("hello!")
    

    It’s worth noting that the Magpie article came out in 2010, so he was comparing Magpie to Python 2.6 or 2.7. Typechecking and mypy were “added” five years later.

    Right now, there are no real plans to add metaprogramming checking to mypy. If you want to typecheck them you either have to use stubs or a runtime contracts library.

    1. 2

      Hm I’m not sure I follow. The difference between the example you quoted and the one above is that there is no main() function. His point is that type checking is triggered by the existence of the main() function, and it happens AFTER all the top level stuff is run, but BEFORE main() is executed.

      You’re right that there is no metaprogramming in the example, but it seems like he wants to allow that.

      In this blog post he says it more explicitly:

      http://journal.stuffwithstuff.com/2010/10/29/bootstrapping-a-type-system/

      All I wanted was:
      The ability to imperatively modify classes like you can in Python and Ruby.
      Static type-checking (after that imperative modification has happened).
      

      I don’t really know Magpie, or Ruby, but I assume he wants to insert something like this at the top level:

      DynamicallyAddMethodsOrAttributes(Hello)  # pass the class and do metaprogramming
      var main()
      ...
      end
      

      That is essentially what I’m doing with Id and Kind in the oil codebase.

      And he’s saying that metaprogramming like this will break it:

       var main()
          DynamicallyAddMethodsOrAttributes(Hello)  # pass the class and do metaprogramming
       end
      

      Note that it’s inside main, AFTER type checking. But that’s OK to me – the language is designed so metaprogramming happens before main(). I think of it as basically “staged programming”.

      And I understand that he wrote this before Python ever had type checking… my point though was that I wish they had used Magpie’s scheme for mypy. But I think that’s impossible because mypy is not really part of the Python interpreter.