Esempio n. 1
0
    def __new__(cls, classname, bases, classdict):

        # Ensure that '_sid_contains_cycles' and 'sid' are contained in sid_ignore.
        # Otherwise sids of objects in reference cycles may depend on the order in which
        # generate_sid is called upon these objects.
        if 'sid_ignore' in classdict:
            classdict['sid_ignore'] = set(
                classdict['sid_ignore']) | {'_sid_contains_cycles', 'sid'}

        c = UberMeta.__new__(cls, classname, bases, classdict)

        c._implements_reduce = ('__reduce__' in classdict
                                or '__reduce_ex__' in classdict or any(
                                    getattr(base, '_implements_reduce', False)
                                    for base in bases))

        # set __signature__ attribute on newly created class c to ensure that
        # inspect.signature(c) returns the signature of its __init__ arguments and not
        # the signature of ImmutableMeta.__call__
        if config.PY3:
            sig = inspect.signature(c.__init__)
            c.__signature__ = sig.replace(
                parameters=tuple(sig.parameters.values())[1:])
        else:
            try:
                from IPython.utils.signatures import signature
                sig = signature(c.__init__)
                c.__signature__ = sig.replace(
                    parameters=tuple(sig.parameters.values())[1:])
            except ImportError:
                pass
        return c
Esempio n. 2
0
    def _getdef(self,obj,oname=''):
        """Return the call signature for any callable object.

        If any exception is generated, None is returned instead and the
        exception is suppressed."""
        try:
            hdef = oname + str(signature(obj))
            return cast_unicode(hdef)
        except:
            return None
Esempio n. 3
0
    def _getdef(self,obj,oname=''):
        """Return the call signature for any callable object.

        If any exception is generated, None is returned instead and the
        exception is suppressed."""
        try:
            hdef = oname + str(signature(obj))
            return cast_unicode(hdef)
        except:
            return None
Esempio n. 4
0
def _function_pprint(obj, p, cycle):
    """Base pprint for all functions and builtin functions."""
    name = _safe_getattr(obj, '__qualname__', obj.__name__)
    mod = obj.__module__
    if mod and mod not in ('__builtin__', 'builtins', 'exceptions'):
        name = mod + '.' + name
    try:
        func_def = name + str(signature(obj))
    except ValueError:
        func_def = name
    p.text('<function %s>' % func_def)
Esempio n. 5
0
def _function_pprint(obj, p, cycle):
    """Base pprint for all functions and builtin functions."""
    name = _safe_getattr(obj, '__qualname__', obj.__name__)
    mod = obj.__module__
    if mod and mod not in ('__builtin__', 'builtins', 'exceptions'):
        name = mod + '.' + name
    try:
       func_def = name + str(signature(obj))
    except ValueError:
       func_def = name
    p.text('<function %s>' % func_def)
Esempio n. 6
0
    def __init__(self, view, f, block=None, **flags):
        self.view = view
        self.func = f
        self.block=block
        self.flags=flags

        # copy function attributes for nicer inspection
        # of decorated functions
        self.__name__ = getname(f)
        if getattr(f, '__doc__', None):
            self.__doc__ = '{} wrapping:\n{}'.format(
                self.__class__.__name__, f.__doc__,
            )
        if getattr(f, '__signature__', None):
            self.__signature__ = f.__signature__
        else:
            try:
                self.__signature__ = signature(f)
            except Exception:
                # no signature, but that's okay
                pass
Esempio n. 7
0
    def __init__(self, view, f, block=None, **flags):
        self.view = view
        self.func = f
        self.block = block
        self.flags = flags

        # copy function attributes for nicer inspection
        # of decorated functions
        self.__name__ = getname(f)
        if getattr(f, '__doc__', None):
            self.__doc__ = '{} wrapping:\n{}'.format(
                self.__class__.__name__,
                f.__doc__,
            )
        if getattr(f, '__signature__', None):
            self.__signature__ = f.__signature__
        else:
            try:
                self.__signature__ = signature(f)
            except Exception:
                # no signature, but that's okay
                pass