gh-65961: Do not rely solely on __cached__ (GH-97990)

Make sure `__spec__.cached` (at minimum) can be used.
This commit is contained in:
Brett Cannon 2022-10-06 15:40:22 -07:00 committed by GitHub
parent f8edc6ff53
commit e1c4d56fdd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 130 additions and 35 deletions

View file

@ -281,30 +281,15 @@ def get_annotations(obj, *, globals=None, locals=None, eval_str=False):
# ----------------------------------------------------------- type-checking
def ismodule(object):
"""Return true if the object is a module.
Module objects provide these attributes:
__cached__ pathname to byte compiled file
__doc__ documentation string
__file__ filename (missing for built-in modules)"""
"""Return true if the object is a module."""
return isinstance(object, types.ModuleType)
def isclass(object):
"""Return true if the object is a class.
Class objects provide these attributes:
__doc__ documentation string
__module__ name of module in which this class was defined"""
"""Return true if the object is a class."""
return isinstance(object, type)
def ismethod(object):
"""Return true if the object is an instance method.
Instance method objects provide these attributes:
__doc__ documentation string
__name__ name with which this method was defined
__func__ function object containing implementation of method
__self__ instance to which this method is bound"""
"""Return true if the object is an instance method."""
return isinstance(object, types.MethodType)
def ismethoddescriptor(object):