bpo-33261: guard access to __code__ attribute in inspect by jdemeyer · Pull Request #6448 · python/cpython

The isgeneratorfunction docstring now says:

 Generator function objects provide the same attributes as functions.
 See help(isfunction) for a list of attributes

I don't think the PR as it is (i.e. checking for __code__) gives a strong enough guarantee for that. It's not apparent that __code__ is reserved for functions only. I'm worried about us adding __code__ to something unrelated in the future, without regard to how inspect uses it.

So I'm leaning towards the alternative solution, keeping the isfunction/ismethod calls.