當前位置: 首頁>>代碼示例>>Python>>正文


Python inspect.getmodule方法代碼示例

本文整理匯總了Python中inspect.getmodule方法的典型用法代碼示例。如果您正苦於以下問題:Python inspect.getmodule方法的具體用法?Python inspect.getmodule怎麽用?Python inspect.getmodule使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在inspect的用法示例。


在下文中一共展示了inspect.getmodule方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: handle_method

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import getmodule [as 別名]
def handle_method(method, method_name, class_name):
    method_errors = []

    # Skip out-of-library inherited methods
    module = inspect.getmodule(method)
    if module is not None:
        if not module.__name__.startswith('pylearn2'):
            return method_errors

    docstring = inspect.getdoc(method)
    if docstring is None:
        method_errors.append((class_name, method_name,
                              '**missing** method-level docstring'))
    else:
        method_errors = [
            (class_name, method_name, e) for e in
            NumpyFunctionDocString(docstring, method).get_errors()
        ]
    return method_errors 
開發者ID:StephanZheng,項目名稱:neural-fingerprinting,代碼行數:21,代碼來源:docscrape.py

示例2: handle_class

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import getmodule [as 別名]
def handle_class(val, class_name):
    cls_errors = []
    docstring = inspect.getdoc(val)
    if docstring is None:
        cls_errors.append((class_name,
                           '**missing** class-level docstring'))
    else:
        cls_errors = [
            (e,) for e in
            NumpyClassDocString(docstring, class_name, val).get_errors()
        ]
        # Get public methods and parse their docstrings
        methods = dict(((name, func) for name, func in inspect.getmembers(val)
                        if not name.startswith('_') and callable(func) and
                        type(func) is not type))
        for m_name, method in six.iteritems(methods):
            # skip error check if the method was inherited
            # from a parent class (which means it wasn't
            # defined in this source file)
            if inspect.getmodule(method) is not None:
                continue
            cls_errors.extend(handle_method(method, m_name, class_name))
    return cls_errors 
開發者ID:StephanZheng,項目名稱:neural-fingerprinting,代碼行數:25,代碼來源:docscrape.py

示例3: validate_error_func

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import getmodule [as 別名]
def validate_error_func(self):
        if self.error_func:
            if isinstance(self.error_func,types.FunctionType):
                ismethod = 0
            elif isinstance(self.error_func, types.MethodType):
                ismethod = 1
            else:
                self.log.error("'p_error' defined, but is not a function or method")
                self.error = 1
                return

            eline = func_code(self.error_func).co_firstlineno
            efile = func_code(self.error_func).co_filename
            module = inspect.getmodule(self.error_func)
            self.modules[module] = 1

            argcount = func_code(self.error_func).co_argcount - ismethod
            if argcount != 1:
                self.log.error("%s:%d: p_error() requires 1 argument",efile,eline)
                self.error = 1

    # Get the tokens map 
開發者ID:nojanath,項目名稱:SublimeKSP,代碼行數:24,代碼來源:yacc.py

示例4: get_pfunctions

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import getmodule [as 別名]
def get_pfunctions(self):
        p_functions = []
        for name, item in self.pdict.items():
            if not name.startswith('p_'): continue
            if name == 'p_error': continue
            if isinstance(item,(types.FunctionType,types.MethodType)):
                line = func_code(item).co_firstlineno
                module = inspect.getmodule(item)
                p_functions.append((line,module,name,item.__doc__))

        # Sort all of the actions by line number
        p_functions.sort()
        self.pfuncs = p_functions


    # Validate all of the p_functions 
開發者ID:nojanath,項目名稱:SublimeKSP,代碼行數:18,代碼來源:yacc.py

示例5: get_extended_info

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import getmodule [as 別名]
def get_extended_info(error_message, prefix):
    # noinspection PyProtectedMember
    caller_stack_frame = sys._getframe(2)
    caller = caller_stack_frame.f_code.co_name
    line = caller_stack_frame.f_lineno
    module = inspect.getmodule(caller_stack_frame)
    error_code = get_error_constant_name(module.__dict__, error_message, prefix)
    if error_code is None:
        error_code = get_error_constant_name(caller_stack_frame.f_globals, error_message, prefix)

    result = {
        "Caller": caller,
        "Module": module.__name__,
        "Line": line
    }
    if error_code is not None:
        result["Code"] = error_code

    return result 
開發者ID:awslabs,項目名稱:aws-ops-automator,代碼行數:21,代碼來源:__init__.py

示例6: tap

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import getmodule [as 別名]
def tap(fn):
    """Decorate a function/method to call any associated taps that have been registered in the ``TapManager``.

    Functional behavior is not changed.

    """
    fn_id = inspect.getmodule(fn).__name__ + "." + fn.__qualname__

    @wraps(fn)
    def tapped(*args, **kwargs):
        tap = TapManager.get(fn_id)
        if tap is not None:
            tap.pre(fn_id, args, kwargs)
        result = fn(*args, **kwargs)
        if tap is not None:
            tap.post(fn_id, args, kwargs, result)
        return result

    return tapped 
開發者ID:erp12,項目名稱:pyshgp,代碼行數:21,代碼來源:tap.py

示例7: render_doc

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import getmodule [as 別名]
def render_doc(thing, title='Python Library Documentation: %s', forceload=0,
        renderer=None):
    """Render text documentation, given an object or a path to an object."""
    if renderer is None:
        renderer = text
    object, name = resolve(thing, forceload)
    desc = describe(object)
    module = inspect.getmodule(object)
    if name and '.' in name:
        desc += ' in ' + name[:name.rfind('.')]
    elif module and module is not object:
        desc += ' in module ' + module.__name__

    if not (inspect.ismodule(object) or
              inspect.isclass(object) or
              inspect.isroutine(object) or
              inspect.isgetsetdescriptor(object) or
              inspect.ismemberdescriptor(object) or
              isinstance(object, property)):
        # If the passed object is a piece of data or an instance,
        # document its available methods instead of its value.
        object = type(object)
        desc += ' object'
    return title % desc + '\n\n' + renderer.document(object, name) 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:26,代碼來源:pydoc.py

示例8: nice_classname

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import getmodule [as 別名]
def nice_classname(obj):
    """Returns a nice name for class object or class instance.

        >>> nice_classname(Exception()) # doctest: +ELLIPSIS
        '...Exception'
        >>> nice_classname(Exception) # doctest: +ELLIPSIS
        '...Exception'

    """
    if inspect.isclass(obj):
        cls_name = obj.__name__
    else:
        cls_name = obj.__class__.__name__
    mod = inspect.getmodule(obj)
    if mod:
        name = mod.__name__
        # jython
        if name.startswith('org.python.core.'):
            name = name[len('org.python.core.'):]
        return "%s.%s" % (name, cls_name)
    else:
        return cls_name 
開發者ID:ionelmc,項目名稱:nose-htmloutput,代碼行數:24,代碼來源:__init__.py

示例9: validate_error_func

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import getmodule [as 別名]
def validate_error_func(self):
        if self.error_func:
            if isinstance(self.error_func, types.FunctionType):
                ismethod = 0
            elif isinstance(self.error_func, types.MethodType):
                ismethod = 1
            else:
                self.log.error("'p_error' defined, but is not a function or method")
                self.error = True
                return

            eline = self.error_func.__code__.co_firstlineno
            efile = self.error_func.__code__.co_filename
            module = inspect.getmodule(self.error_func)
            self.modules.add(module)

            argcount = self.error_func.__code__.co_argcount - ismethod
            if argcount != 1:
                self.log.error('%s:%d: p_error() requires 1 argument', efile, eline)
                self.error = True

    # Get the tokens map 
開發者ID:remg427,項目名稱:misp42splunk,代碼行數:24,代碼來源:yacc.py

示例10: get_pfunctions

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import getmodule [as 別名]
def get_pfunctions(self):
        p_functions = []
        for name, item in self.pdict.items():
            if not name.startswith('p_') or name == 'p_error':
                continue
            if isinstance(item, (types.FunctionType, types.MethodType)):
                line = getattr(item, 'co_firstlineno', item.__code__.co_firstlineno)
                module = inspect.getmodule(item)
                p_functions.append((line, module, name, item.__doc__))

        # Sort all of the actions by line number; make sure to stringify
        # modules to make them sortable, since `line` may not uniquely sort all
        # p functions
        p_functions.sort(key=lambda p_function: (
            p_function[0],
            str(p_function[1]),
            p_function[2],
            p_function[3]))
        self.pfuncs = p_functions

    # Validate all of the p_functions 
開發者ID:remg427,項目名稱:misp42splunk,代碼行數:23,代碼來源:yacc.py

示例11: get_module_things

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import getmodule [as 別名]
def get_module_things(module):
    module_name = module.__name__

    for func_name, func in get_module_functions(module):
        if inspect.getmodule(func) != module:
            continue
        yield (module_name + "." + func_name, func)

    for class_name, klass in get_module_classes(module):
        if inspect.getmodule(klass) != module:
            continue
        yield (module_name + "." + class_name, klass)

        for method_name, method in get_class_methods(klass):
            if method_name not in klass.__dict__:
                continue
            yield (module_name + "." + class_name + ":" + method_name, method) 
開發者ID:wglass,項目名稱:collectd-haproxy,代碼行數:19,代碼來源:test_docstrings.py

示例12: _from_module

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import getmodule [as 別名]
def _from_module(self, module, object):
        """
        Return true if the given object is defined in the given
        module.
        """
        if module is None:
            return True
        elif inspect.isfunction(object):
            return module.__dict__ is object.func_globals
        elif inspect.isclass(object):
            return module.__name__ == object.__module__
        elif inspect.getmodule(object) is not None:
            return module is inspect.getmodule(object)
        elif hasattr(object, '__module__'):
            return module.__name__ == object.__module__
        elif isinstance(object, property):
            return True # [XX] no way not be sure.
        else:
            raise ValueError("object must be a class or function") 
開發者ID:linuxscout,項目名稱:mishkal,代碼行數:21,代碼來源:doctest24.py

示例13: inject_dtype

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import getmodule [as 別名]
def inject_dtype(dtype):
    def inner(func):
        @wraps(func)
        def call(*tensors, **kw):
            kw['dtype'] = np.dtype(dtype)
            ret = func(*tensors, **kw)
            if ret is NotImplemented:
                reverse_func = getattr(inspect.getmodule(func), 'r{0}'.format(func.__name__), None)
                if reverse_func is not None:
                    ret = reverse_func(*tensors[::-1], **kw)
                if ret is NotImplemented:
                    raise TypeError(
                        "unsupported operand type(s) for {0}: '{1}' and '{2}".format(
                            func.__name__, *[type(t) for t in tensors]))
            return ret

        return call

    return inner 
開發者ID:mars-project,項目名稱:mars,代碼行數:21,代碼來源:utils.py

示例14: get_calling_module_name

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import getmodule [as 別名]
def get_calling_module_name(depth=3):
    """
    Get the name of the 'calling' module

    Args:
        depth (int): How many levels to look 'up' from the current module. Remember that the enclosing 'helpers' \
        module is counted as 1.

    Returns:
        str: The calling module name

    """
    assert isinstance(depth, int), u'depth should be an int'
    frame = inspect.stack()[depth]
    LOG.debug(u'Got calling frame %r', frame)
    module = inspect.getmodule(frame[0])
    if module:
        return module.__name__ 
開發者ID:yahoo,項目名稱:panoptes,代碼行數:20,代碼來源:helpers.py

示例15: render_doc

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import getmodule [as 別名]
def render_doc(thing, title='Python Library Documentation: %s', forceload=0):
    """Render text documentation, given an object or a path to an object."""
    object, name = resolve(thing, forceload)
    desc = describe(object)
    module = inspect.getmodule(object)
    if name and '.' in name:
        desc += ' in ' + name[:name.rfind('.')]
    elif module and module is not object:
        desc += ' in module ' + module.__name__
    if type(object) is _OLD_INSTANCE_TYPE:
        # If the passed object is an instance of an old-style class,
        # document its available methods instead of its value.
        object = object.__class__
    elif not (inspect.ismodule(object) or
              inspect.isclass(object) or
              inspect.isroutine(object) or
              inspect.isgetsetdescriptor(object) or
              inspect.ismemberdescriptor(object) or
              isinstance(object, property)):
        # If the passed object is a piece of data or an instance,
        # document its available methods instead of its value.
        object = type(object)
        desc += ' object'
    return title % desc + '\n\n' + text.document(object, name) 
開發者ID:glmcdona,項目名稱:meddle,代碼行數:26,代碼來源:pydoc.py


注:本文中的inspect.getmodule方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。