How to use the monkeytype.stubs.FunctionDefinition function in MonkeyType

To help you get started, we’ve selected a few MonkeyType examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Instagram / MonkeyType / tests / test_stubs.py View on Github external
            (Dummy.a_cached_property.func, FunctionDefinition(
                'tests.util', 'Dummy.a_cached_property', FunctionKind.DJANGO_CACHED_PROPERTY,
                Signature.from_callable(Dummy.a_cached_property.func))),
            (a_module_func, FunctionDefinition(
                'tests.test_stubs', 'a_module_func', FunctionKind.MODULE,
                Signature.from_callable(a_module_func))),
            (an_async_func, FunctionDefinition(
                'tests.test_stubs', 'an_async_func', FunctionKind.MODULE,
                Signature.from_callable(a_module_func), is_async=True)),
        ],
    )
    def test_from_callable(self, func, expected):
        defn = FunctionDefinition.from_callable(func)
        assert defn == expected
github Instagram / MonkeyType / tests / test_stubs.py View on Github external
            (an_async_func, FunctionDefinition(
                'tests.test_stubs', 'an_async_func', FunctionKind.MODULE,
                Signature.from_callable(a_module_func), is_async=True)),
        ],
    )
    def test_from_callable(self, func, expected):
        defn = FunctionDefinition.from_callable(func)
        assert defn == expected
github Instagram / MonkeyType / tests / test_stubs.py View on Github external
            (Dummy.a_property.fget, FunctionDefinition(
                'tests.util', 'Dummy.a_property', FunctionKind.PROPERTY,
                Signature.from_callable(Dummy.a_property.fget))),
            (Dummy.a_cached_property.func, FunctionDefinition(
                'tests.util', 'Dummy.a_cached_property', FunctionKind.DJANGO_CACHED_PROPERTY,
                Signature.from_callable(Dummy.a_cached_property.func))),
            (a_module_func, FunctionDefinition(
                'tests.test_stubs', 'a_module_func', FunctionKind.MODULE,
                Signature.from_callable(a_module_func))),
            (an_async_func, FunctionDefinition(
                'tests.test_stubs', 'an_async_func', FunctionKind.MODULE,
                Signature.from_callable(a_module_func), is_async=True)),
        ],
    )
    def test_from_callable(self, func, expected):
        defn = FunctionDefinition.from_callable(func)
        assert defn == expected
github Instagram / MonkeyType / tests / test_stubs.py View on Github external
                FunctionDefinition(
                    'tests.util',
                    'Dummy.an_instance_method',
                    FunctionKind.INSTANCE,
                    Signature(
                        parameters=[
                            Parameter(name='self', kind=Parameter.POSITIONAL_OR_KEYWORD, annotation=Parameter.empty),
                            Parameter(name='foo', kind=Parameter.POSITIONAL_OR_KEYWORD, annotation=int),
                            Parameter(name='bar', kind=Parameter.POSITIONAL_OR_KEYWORD, annotation=List[str]),
                        ],
                        return_annotation=int,
                    ),
                    False,
                    [],
                )
            ),
            # TypedDict: Add class definitions and use the class names as types.
github Instagram / MonkeyType / tests / test_stubs.py View on Github external
            (Dummy.a_class_method.__func__, FunctionDefinition(
                'tests.util', 'Dummy.a_class_method', FunctionKind.CLASS,
                Signature.from_callable(Dummy.a_class_method.__func__))),
            (Dummy.an_instance_method, FunctionDefinition(
                'tests.util', 'Dummy.an_instance_method', FunctionKind.INSTANCE,
                Signature.from_callable(Dummy.an_instance_method))),
            (Dummy.a_property.fget, FunctionDefinition(
                'tests.util', 'Dummy.a_property', FunctionKind.PROPERTY,
                Signature.from_callable(Dummy.a_property.fget))),
            (Dummy.a_cached_property.func, FunctionDefinition(
                'tests.util', 'Dummy.a_cached_property', FunctionKind.DJANGO_CACHED_PROPERTY,
                Signature.from_callable(Dummy.a_cached_property.func))),
            (a_module_func, FunctionDefinition(
                'tests.test_stubs', 'a_module_func', FunctionKind.MODULE,
                Signature.from_callable(a_module_func))),
            (an_async_func, FunctionDefinition(
                'tests.test_stubs', 'an_async_func', FunctionKind.MODULE,
github Instagram / MonkeyType / tests / test_stubs.py View on Github external
            (Dummy.an_instance_method, FunctionDefinition(
                'tests.util', 'Dummy.an_instance_method', FunctionKind.INSTANCE,
                Signature.from_callable(Dummy.an_instance_method))),
            (Dummy.a_property.fget, FunctionDefinition(
                'tests.util', 'Dummy.a_property', FunctionKind.PROPERTY,
                Signature.from_callable(Dummy.a_property.fget))),
            (Dummy.a_cached_property.func, FunctionDefinition(
                'tests.util', 'Dummy.a_cached_property', FunctionKind.DJANGO_CACHED_PROPERTY,
                Signature.from_callable(Dummy.a_cached_property.func))),
            (a_module_func, FunctionDefinition(
                'tests.test_stubs', 'a_module_func', FunctionKind.MODULE,
                Signature.from_callable(a_module_func))),
            (an_async_func, FunctionDefinition(
                'tests.test_stubs', 'an_async_func', FunctionKind.MODULE,
                Signature.from_callable(a_module_func), is_async=True)),
        ],
    )
github Instagram / MonkeyType / tests / test_stubs.py View on Github external
            (a_module_func, FunctionDefinition(
                'tests.test_stubs', 'a_module_func', FunctionKind.MODULE,
                Signature.from_callable(a_module_func))),
            (an_async_func, FunctionDefinition(
                'tests.test_stubs', 'an_async_func', FunctionKind.MODULE,
                Signature.from_callable(a_module_func), is_async=True)),
        ],
    )
    def test_from_callable(self, func, expected):
        defn = FunctionDefinition.from_callable(func)
        assert defn == expected
github Instagram / MonkeyType / monkeytype / stubs.py View on Github external
typ = make_forward_ref(class_name)
            new_arg_types[name] = typ

        if return_type and is_anonymous_typed_dict(return_type):
            # Replace the dot in a qualified name.
            class_name = get_typed_dict_class_name(func.__qualname__.replace('.', '_'))
            typed_dict_class_stubs.extend(ClassStub.stubs_from_typed_dict(return_type, class_name))
            return_type = make_forward_ref(class_name)

        if yield_type and is_anonymous_typed_dict(yield_type):
            # Replace the dot in a qualified name.
            class_name = get_typed_dict_class_name(func.__qualname__.replace('.', '_') + 'Yield')
            typed_dict_class_stubs.extend(ClassStub.stubs_from_typed_dict(yield_type, class_name))
            yield_type = make_forward_ref(class_name)

        function = FunctionDefinition.from_callable(func)
        signature = function.signature
        signature = update_signature_args(signature, new_arg_types,
                                          function.has_self, existing_annotation_strategy)
        signature = update_signature_return(signature, return_type,
                                            yield_type, existing_annotation_strategy)
        return FunctionDefinition(function.module, function.qualname,
                                  function.kind, signature,
                                  function.is_async, typed_dict_class_stubs)
github Instagram / MonkeyType / monkeytype / stubs.py View on Github external
def from_callable(cls, func: Callable, kind: FunctionKind = None) -> 'FunctionDefinition':
        kind = FunctionKind.from_callable(func)
        sig = inspect.Signature.from_callable(func)
        is_async = asyncio.iscoroutinefunction(func)
        return FunctionDefinition(func.__module__, func.__qualname__, kind, sig, is_async)
github Instagram / MonkeyType / monkeytype / stubs.py View on Github external
typed_dict_class_stubs.extend(ClassStub.stubs_from_typed_dict(return_type, class_name))
            return_type = make_forward_ref(class_name)

        if yield_type and is_anonymous_typed_dict(yield_type):
            # Replace the dot in a qualified name.
            class_name = get_typed_dict_class_name(func.__qualname__.replace('.', '_') + 'Yield')
            typed_dict_class_stubs.extend(ClassStub.stubs_from_typed_dict(yield_type, class_name))
            yield_type = make_forward_ref(class_name)

        function = FunctionDefinition.from_callable(func)
        signature = function.signature
        signature = update_signature_args(signature, new_arg_types,
                                          function.has_self, existing_annotation_strategy)
        signature = update_signature_return(signature, return_type,
                                            yield_type, existing_annotation_strategy)
        return FunctionDefinition(function.module, function.qualname,
                                  function.kind, signature,
                                  function.is_async, typed_dict_class_stubs)