예제 #1
0
            def args(self):
                """Overwrite the underlying args to match those of the underlying func

                Usually the underlying *func* is a function/method, as in:

                    def test(self):
                        pass

                This has only the *self* parameter but when we access test.__get__
                we get a new object which has two parameters, *self* and *type*.
                """
                nonlocal func
                positional_or_keyword_params = func.args.args.copy()
                positional_or_keyword_params.append(
                    astroid.AssignName(name="type"))

                positional_only_params = func.args.posonlyargs.copy()

                arguments = astroid.Arguments(parent=func.args.parent)
                arguments.postinit(
                    args=positional_or_keyword_params,
                    posonlyargs=positional_only_params,
                    defaults=[],
                    kwonlyargs=[],
                    kw_defaults=[],
                    annotations=[],
                )
                return arguments
예제 #2
0
def arguments_node(draw, annotated=False):
    n = draw(hs.integers(min_value=1, max_value=5))
    args = draw(hs.lists(name_node(None), min_size=n, max_size=n))
    if annotated:
        annotations = draw(
            hs.lists(name_node(annotation), min_size=n, max_size=n))
    else:
        annotations = None
    node = astroid.Arguments()
    node.postinit(args, None, None, None, annotations)
    return node