How to use the monkeytype.stubs.update_signature_args 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
def test_nonetype_annotation(self):
        """NoneType should always be rendered as None"""
        sig = Signature.from_callable(UpdateSignatureHelper.has_annos)
        sig = update_signature_args(sig, {'a': Dict[str, NoneType]}, has_self=False,
                                    existing_annotation_strategy=ExistingAnnotationStrategy.IGNORE)
        stub = FunctionStub('test', sig, FunctionKind.MODULE)
        expected = 'def test(a: Dict[str, None], b) -> int: ...'
        assert stub.render() == expected
github Instagram / MonkeyType / tests / test_stubs.py View on Github external
def test_update_arg_ignore_existing_anno(self):
        """Update stubs only bases on traces."""
        sig = Signature.from_callable(UpdateSignatureHelper.has_annos)
        sig = update_signature_args(
            sig, {'a': str, 'b': bool}, has_self=False, existing_annotation_strategy=ExistingAnnotationStrategy.IGNORE)
        params = [
            Parameter('a', Parameter.POSITIONAL_OR_KEYWORD, annotation=str),
            Parameter('b', Parameter.POSITIONAL_OR_KEYWORD, annotation=bool),
        ]
        assert sig == Signature(parameters=params, return_annotation=int)
github Instagram / MonkeyType / tests / test_stubs.py View on Github external
def test_update_arg_avoid_incompatible_anno(self):
        """Can generate stub with no annotations where they already exist in the source."""
        sig = Signature.from_callable(UpdateSignatureHelper.has_annos)
        sig = update_signature_args(
            sig, {'a': int, 'b': int}, has_self=False, existing_annotation_strategy=ExistingAnnotationStrategy.OMIT)
        params = [
            Parameter('a', Parameter.POSITIONAL_OR_KEYWORD, annotation=inspect.Parameter.empty),
            Parameter('b', Parameter.POSITIONAL_OR_KEYWORD, annotation=int)
        ]
        assert sig == Signature(parameters=params, return_annotation=int)
github Instagram / MonkeyType / tests / test_stubs.py View on Github external
def test_update_class(self):
        """Don't annotate the first arg of classmethods"""
        sig = Signature.from_callable(UpdateSignatureHelper.a_class_method.__func__)
        sig = update_signature_args(sig, {'cls': Type[UpdateSignatureHelper]}, True)
        expected = Signature(parameters=[Parameter('cls', Parameter.POSITIONAL_OR_KEYWORD)])
        assert sig == expected
github Instagram / MonkeyType / tests / test_stubs.py View on Github external
def test_update_arg_ignore_existing_anno_None(self):
        """Update arg annotations from types"""
        sig = Signature.from_callable(UpdateSignatureHelper.has_annos)
        sig = update_signature_args(
            sig, {'a': None, 'b': int}, has_self=False, existing_annotation_strategy=ExistingAnnotationStrategy.IGNORE)
        params = [
            Parameter('a', Parameter.POSITIONAL_OR_KEYWORD, annotation=inspect.Parameter.empty),
            Parameter('b', Parameter.POSITIONAL_OR_KEYWORD, annotation=int),
        ]
        assert sig == Signature(parameters=params, return_annotation=int)
github Instagram / MonkeyType / tests / test_stubs.py View on Github external
def test_update_arg_with_anno(self):
        """Leave existing arg annotations alone"""
        sig = Signature.from_callable(UpdateSignatureHelper.has_annos)
        sig = update_signature_args(sig, {'a': str}, False)
        expected = Signature(
            parameters=[
                Parameter('a', Parameter.POSITIONAL_OR_KEYWORD, annotation=int),
                Parameter('b', Parameter.POSITIONAL_OR_KEYWORD)
            ],
            return_annotation=int
        )
        assert sig == expected
github Instagram / MonkeyType / tests / test_stubs.py View on Github external
def test_update_self(self):
        """Don't annotate first arg of instance methods"""
        sig = Signature.from_callable(UpdateSignatureHelper.an_instance_method)
        sig = update_signature_args(sig, {'self': UpdateSignatureHelper}, True)
        expected = Signature(parameters=[Parameter('self', Parameter.POSITIONAL_OR_KEYWORD)])
        assert sig == expected
github Instagram / MonkeyType / tests / test_stubs.py View on Github external
def test_update_arg(self):
        """Update arg annotations from types"""
        sig = Signature.from_callable(UpdateSignatureHelper.has_annos)
        sig = update_signature_args(sig, {'b': int}, False)
        params = [
            Parameter('a', Parameter.POSITIONAL_OR_KEYWORD, annotation=int),
            Parameter('b', Parameter.POSITIONAL_OR_KEYWORD, annotation=int),
        ]
        assert sig == Signature(parameters=params, return_annotation=int)
github Instagram / MonkeyType / tests / test_stubs.py View on Github external
def test_update_self_ignore_existing_anno(self):
        """Don't annotate first arg of instance methods if asked to ignore"""
        sig = Signature.from_callable(UpdateSignatureHelper.an_instance_method)
        sig = update_signature_args(sig, {'self': UpdateSignatureHelper}, has_self=True,
                                    existing_annotation_strategy=ExistingAnnotationStrategy.IGNORE)
        expected = Signature(parameters=[Parameter('self', Parameter.POSITIONAL_OR_KEYWORD)])
        assert sig == expected