Enhanced gen_stubs.py