Yes

I guess it would work with the ongoing jit work, which (as far as I understood..) run the code "as usual", then notice that a specific variable is always a dict (or whatever). Then it patches the code to run the dict-optimized code by default (and fallback to the generic code if, somehow, the variable is no longer a dict).

With typing, the generic code could be avoided altogether. The algorithm would be:

  - notice that some variable can be processed by a dict-optimized code (because its typing is a dict, or something that looks like a dict etc)
  - when processing, check that the variable is indeed a "dict", raise an exception if not
  - run the optimized code
  - if the typing information changes (because the class has been redefined and the variable is no longer a "dict"), then go to step 1 and either stick with the current optimized code, use another one, or use the generic one
This would:

  - enforce types (you said that variable is a Thing but a Thing was not given: exception)
  - improve the jit by removing the bootstrap phase (where the jit watches and then try to guess what could be improved)

(or perhaps this is a stupid idea that cannot work :) )

There are already some bits of this with specific bytecode and the upcoming jit, it's not using annotations at all though