Ejemplo n.º 1
0
    def _argreprs(self):
        if self.__argreprs is not None:
            return self.__argreprs

        # get arguments to display from __init__ functions
        spec = getfullargspec(type(self).__init__)
        defaults = {}
        if spec.defaults is not None:
            defaults.update(
                zip(spec.args[-len(spec.defaults):], spec.defaults)
            )

        self.__argreprs = []
        for arg in spec.args[1:]:  # start at 1 to drop `self`
            if not hasattr(self, arg):
                # We rely on storing the initial arguments. If we don't have
                # them, we don't auto-generate a repr.
                self.__argreprs = "Cannot find %r" % arg
                break
            value = getattr(self, arg)

            param = self._paramdict.get(arg, None)
            if arg in defaults:
                not_default = not equal(value, defaults[arg])
            elif param is not None and param.default is not Unconfigurable:
                not_default = not equal(value, param.default)
            else:
                not_default = True

            if not_default:
                self.__argreprs.append("%s=%r" % (arg, value))

        return self.__argreprs
Ejemplo n.º 2
0
    def check_callable_args_list(self, node, output):
        # not all callables provide an argspec, such as numpy
        try:
            func_argspec = getfullargspec(output)
        except (TypeError, ValueError):
            pass
        else:
            args_len = len(func_argspec.args)
            if inspect.ismethod(output) or not inspect.isroutine(output):
                # don't count self as an argument
                args_len -= 1

            defaults_len = 0
            if func_argspec.defaults is not None:
                defaults_len = len(func_argspec.defaults)

            required_len = args_len - defaults_len
            expected_len = 2 if node.size_in > 0 else 1

            if func_argspec.varargs:
                args_len = max(expected_len, args_len)

            if not required_len <= expected_len <= args_len:
                raise self._fn_args_validation_error(output, self.name, node)
Ejemplo n.º 3
0
 def check_init_args(cls, args):
     assert getfullargspec(cls.__init__).args[1:] == args