(object)
Return the filename that can be used to locate an object's source.
    Return None if no way can be identified to get the source.
Return the filename that can be used to locate an object's source.
    Return None if no way can be identified to get the source.
Return the filename that can be used to locate an object s source . Return None if no way can be identified to get the source .
def getsourcefile(object):
    """Return the filename that can be used to locate an object's source.
    Return None if no way can be identified to get the source.
    """
    filename = getfile(object)
    all_bytecode_suffixes = importlib.machinery.DEBUG_BYTECODE_SUFFIXES[:]
    all_bytecode_suffixes += importlib.machinery.OPTIMIZED_BYTECODE_SUFFIXES[:]
    if any(filename.endswith(s) for s in all_bytecode_suffixes):
        filename = (os.path.splitext(filename)[0] +
                    importlib.machinery.SOURCE_SUFFIXES[0])
    elif any(filename.endswith(s) for s in
                 importlib.machinery.EXTENSION_SUFFIXES):
        return None
    if os.path.exists(filename):
        return filename
    # only return a non-existent filename if the module has a PEP 302 loader
    module = getmodule(object, filename)
    if getattr(module, '__loader__', None) is not None:
        return filename
    elif getattr(getattr(module, "__spec__", None), "loader", None) is not None:
        return filename
    # or it is in the linecache
    elif filename in linecache.cache:
        return filename
def getsourcefile ( object ) : filename = getfile ( object ) all_bytecode_suffixes = importlib . machinery . DEBUG_BYTECODE_SUFFIXES [ : ] all_bytecode_suffixes += importlib . machinery . OPTIMIZED_BYTECODE_SUFFIXES [ : ] if any ( filename . endswith ( s ) for s in all_bytecode_suffixes ) : filename = ( os . path . splitext ( filename ) [ 0 ] + importlib . machinery . SOURCE_SUFFIXES [ 0 ] ) elif any ( filename . endswith ( s ) for s in importlib . machinery . EXTENSION_SUFFIXES ) : return None if os . path . exists ( filename ) : return filename # only return a non-existent filename if the module has a PEP 302 loader module = getmodule ( object , filename ) if getattr ( module , '__loader__' , None ) is not None : return filename elif getattr ( getattr ( module , "__spec__" , None ) , "loader" , None ) is not None : return filename # or it is in the linecache elif filename in linecache . cache : return filename