(obj, name=None)
return obj2 is obj
Determine if obj can be pickled as attribute of a file-backed module
Determine if obj can be pickled as attribute of a file-backed module
Determine if obj can be pickled as attribute of a file - backed module
def _is_global(obj, name=None):
    """Determine if obj can be pickled as attribute of a file-backed module"""
    if name is None:
        name = getattr(obj, "__qualname__", None)
    if name is None:
        name = getattr(obj, "__name__", None)

    module_name = _whichmodule(obj, name)

    if module_name is None:
        # In this case, obj.__module__ is None AND obj was not found in any
        # imported module. obj is thus treated as dynamic.
        return False

    if module_name == "__main__":
        return False

    module = sys.modules.get(module_name, None)
    if module is None:
        # The main reason why obj's module would not be imported is that this
        # module has been dynamically created, using for example
        # types.ModuleType. The other possibility is that module was removed
        # from sys.modules after obj was created/imported. But this case is not
        # supported, as the standard pickle does not support it either.
        return False

    # module has been added to sys.modules, but it can still be dynamic.
    if _is_dynamic(module):
        return False

    try:
        obj2, parent = _getattribute(module, name)
    except AttributeError:
        # obj was not found inside the module it points to
        return False
    return obj2 is obj
def _is_global ( obj , name = None ) : if name is None : name = getattr ( obj , "__qualname__" , None ) if name is None : name = getattr ( obj , "__name__" , None ) module_name = _whichmodule ( obj , name ) if module_name is None : # In this case, obj.__module__ is None AND obj was not found in any # imported module. obj is thus treated as dynamic. return False if module_name == "__main__" : return False module = sys . modules . get ( module_name , None ) if module is None : # The main reason why obj's module would not be imported is that this # module has been dynamically created, using for example # types.ModuleType. The other possibility is that module was removed # from sys.modules after obj was created/imported. But this case is not # supported, as the standard pickle does not support it either. return False # module has been added to sys.modules, but it can still be dynamic. if _is_dynamic ( module ) : return False try : obj2 , parent = _getattribute ( module , name ) except AttributeError : # obj was not found inside the module it points to return False return obj2 is obj