py: Clean up and simplify functions in scope; add STATIC in compiler.

Some small code clean-ups that result in about 80 bytes ROM saving for
stmhal.