THIS IS SUPER HACKY. DO NOT EVEN THINK ABOUT LANDING YET.
Now that we have a custom module importer on Python 2 and that importer
is using Python 3.7's tokenizer, it is possible for us to analyze the
source code token stream and transform it to valid Python 2.7 source
before it is compiled into a code object.
This commit teaches the token stream transformer to recognize the tokens
for a function return type annotation and to strip those tokens from the
token stream. As far as Python 2's code compiler is concerned, the original
source didn't contain a type annotation!
To prove it works, we define a type annotation in the dispatch module.
Python 2 is able to import the module just fine.
This feature means we could start adding type annotations throughout the
code base while still remaining Python 2 compatible.
But why stop at type annotations? We could also rewrite the token stream
so we can leverage other Python 3 only features. This includes "yield from"
super() without arguments, class definitions without "(object)", etc. We
could also "invert" our source transformer strategy and make the code base
native Python 3 and source transform to remain compatible with Python 2.