In general, this is easy to do with the help of a inspect.getsourcemodule, class, method, function, trace, frame, or code object. The source they represent must, of course, be written in Python, otherwise an error occurs.
In this particular case, you are just unlucky because when Callabledetermined in _collections_abc a nameCallable.__module__ callections.abc :
>>> Callable.__module__
'collections.abc'
getsource, _collections_abc, Callable, collections.abc, _collections_abc:
>>> print(getsource(collections.abc))
from _collections_abc import *
from _collections_abc import __all__
getsource , , :
>>> print(getsource(getsource))
def getsource(object):
"""Return the text of the source code for an object.
The argument may be a module, class, method, function, traceback, frame,
or code object. The source code is returned as a single string. An
OSError is raised if the source code cannot be retrieved."""
lines, lnum = getsourcelines(object)
return ''.join(lines)
, , (- Callable.__module__ collections.abc.) __module__ '_collections_abc' :
>>> Callable.__module__ = '_collections_abc'
>>> src = getsource(Callable)
>>> print(src)
class Callable(metaclass=ABCMeta):
__slots__ = ()
@abstractmethod
def __call__(self, *args, **kwds):
return False
@classmethod
def __subclasshook__(cls, C):
if cls is Callable:
return _check_methods(C, "__call__")
return NotImplemented
.