How can I export function signatures with mypy?











up vote
2
down vote

favorite
1












I would like to see what function signatures mypy infers. Is there a way to export all of them for my package?










share|improve this question


























    up vote
    2
    down vote

    favorite
    1












    I would like to see what function signatures mypy infers. Is there a way to export all of them for my package?










    share|improve this question
























      up vote
      2
      down vote

      favorite
      1









      up vote
      2
      down vote

      favorite
      1






      1





      I would like to see what function signatures mypy infers. Is there a way to export all of them for my package?










      share|improve this question













      I would like to see what function signatures mypy infers. Is there a way to export all of them for my package?







      python mypy






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked yesterday









      Martin Thoma

      38.6k50278493




      38.6k50278493
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          Mypy does not attempt to infer function signatures. Instead, mypy (and all PEP-484 compliant type checkers) treat the function signatures themselves as the "source of truth" and conduct all type-checking based on the available signatures.



          Specifically, once a function has been (manually) assigned type hints, mypy will use that information to a) perform type checks within the function and b) make sure any other typed functions are calling that function in a type-safe way.



          If you omit type signatures from a method, mypy skip checking that function entirely. You can override this behavior by calling mypy with either the --strict or --check-untyped-defs flag. Once you do so, mypy will assume that the function's parameters and return are all of type Any, the dynamic type.





          If you are working on a sufficiently large codebase, it may be onerous to add type hints to all of your existing functions by hand. In that case, you can try:




          1. Performing whole-program type inference to try and infer type hints for your functions, try using pytype instead. That said, keep in mind that pytype is still very much a work-in-progress. Whole-program type inference is a far more challenging problem to solve vs the more local type inference PEP 484 type-checkers perform.


          2. Using Monkeytype or pyannotate -- these programs hook into your code at runtime and will try and infer types based on the runtime behavior of your code.



          Both of these approaches should generate draft-quality type hints you can iterate on.



          The mypy docs have more info about strategies for adopting mypy to larger codebases: https://mypy.readthedocs.io/en/latest/existing_code.html






          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














             

            draft saved


            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53238088%2fhow-can-i-export-function-signatures-with-mypy%23new-answer', 'question_page');
            }
            );

            Post as a guest
































            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote













            Mypy does not attempt to infer function signatures. Instead, mypy (and all PEP-484 compliant type checkers) treat the function signatures themselves as the "source of truth" and conduct all type-checking based on the available signatures.



            Specifically, once a function has been (manually) assigned type hints, mypy will use that information to a) perform type checks within the function and b) make sure any other typed functions are calling that function in a type-safe way.



            If you omit type signatures from a method, mypy skip checking that function entirely. You can override this behavior by calling mypy with either the --strict or --check-untyped-defs flag. Once you do so, mypy will assume that the function's parameters and return are all of type Any, the dynamic type.





            If you are working on a sufficiently large codebase, it may be onerous to add type hints to all of your existing functions by hand. In that case, you can try:




            1. Performing whole-program type inference to try and infer type hints for your functions, try using pytype instead. That said, keep in mind that pytype is still very much a work-in-progress. Whole-program type inference is a far more challenging problem to solve vs the more local type inference PEP 484 type-checkers perform.


            2. Using Monkeytype or pyannotate -- these programs hook into your code at runtime and will try and infer types based on the runtime behavior of your code.



            Both of these approaches should generate draft-quality type hints you can iterate on.



            The mypy docs have more info about strategies for adopting mypy to larger codebases: https://mypy.readthedocs.io/en/latest/existing_code.html






            share|improve this answer

























              up vote
              0
              down vote













              Mypy does not attempt to infer function signatures. Instead, mypy (and all PEP-484 compliant type checkers) treat the function signatures themselves as the "source of truth" and conduct all type-checking based on the available signatures.



              Specifically, once a function has been (manually) assigned type hints, mypy will use that information to a) perform type checks within the function and b) make sure any other typed functions are calling that function in a type-safe way.



              If you omit type signatures from a method, mypy skip checking that function entirely. You can override this behavior by calling mypy with either the --strict or --check-untyped-defs flag. Once you do so, mypy will assume that the function's parameters and return are all of type Any, the dynamic type.





              If you are working on a sufficiently large codebase, it may be onerous to add type hints to all of your existing functions by hand. In that case, you can try:




              1. Performing whole-program type inference to try and infer type hints for your functions, try using pytype instead. That said, keep in mind that pytype is still very much a work-in-progress. Whole-program type inference is a far more challenging problem to solve vs the more local type inference PEP 484 type-checkers perform.


              2. Using Monkeytype or pyannotate -- these programs hook into your code at runtime and will try and infer types based on the runtime behavior of your code.



              Both of these approaches should generate draft-quality type hints you can iterate on.



              The mypy docs have more info about strategies for adopting mypy to larger codebases: https://mypy.readthedocs.io/en/latest/existing_code.html






              share|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote









                Mypy does not attempt to infer function signatures. Instead, mypy (and all PEP-484 compliant type checkers) treat the function signatures themselves as the "source of truth" and conduct all type-checking based on the available signatures.



                Specifically, once a function has been (manually) assigned type hints, mypy will use that information to a) perform type checks within the function and b) make sure any other typed functions are calling that function in a type-safe way.



                If you omit type signatures from a method, mypy skip checking that function entirely. You can override this behavior by calling mypy with either the --strict or --check-untyped-defs flag. Once you do so, mypy will assume that the function's parameters and return are all of type Any, the dynamic type.





                If you are working on a sufficiently large codebase, it may be onerous to add type hints to all of your existing functions by hand. In that case, you can try:




                1. Performing whole-program type inference to try and infer type hints for your functions, try using pytype instead. That said, keep in mind that pytype is still very much a work-in-progress. Whole-program type inference is a far more challenging problem to solve vs the more local type inference PEP 484 type-checkers perform.


                2. Using Monkeytype or pyannotate -- these programs hook into your code at runtime and will try and infer types based on the runtime behavior of your code.



                Both of these approaches should generate draft-quality type hints you can iterate on.



                The mypy docs have more info about strategies for adopting mypy to larger codebases: https://mypy.readthedocs.io/en/latest/existing_code.html






                share|improve this answer












                Mypy does not attempt to infer function signatures. Instead, mypy (and all PEP-484 compliant type checkers) treat the function signatures themselves as the "source of truth" and conduct all type-checking based on the available signatures.



                Specifically, once a function has been (manually) assigned type hints, mypy will use that information to a) perform type checks within the function and b) make sure any other typed functions are calling that function in a type-safe way.



                If you omit type signatures from a method, mypy skip checking that function entirely. You can override this behavior by calling mypy with either the --strict or --check-untyped-defs flag. Once you do so, mypy will assume that the function's parameters and return are all of type Any, the dynamic type.





                If you are working on a sufficiently large codebase, it may be onerous to add type hints to all of your existing functions by hand. In that case, you can try:




                1. Performing whole-program type inference to try and infer type hints for your functions, try using pytype instead. That said, keep in mind that pytype is still very much a work-in-progress. Whole-program type inference is a far more challenging problem to solve vs the more local type inference PEP 484 type-checkers perform.


                2. Using Monkeytype or pyannotate -- these programs hook into your code at runtime and will try and infer types based on the runtime behavior of your code.



                Both of these approaches should generate draft-quality type hints you can iterate on.



                The mypy docs have more info about strategies for adopting mypy to larger codebases: https://mypy.readthedocs.io/en/latest/existing_code.html







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 1 hour ago









                Michael0x2a

                21.3k1671124




                21.3k1671124






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53238088%2fhow-can-i-export-function-signatures-with-mypy%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest




















































































                    Popular posts from this blog

                    Florida Star v. B. J. F.

                    Danny Elfman

                    Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues