Further optimizations in typing.py