dropbox / pyannotate

Auto-generate PEP-484 annotations
Apache License 2.0
1.42k stars 59 forks source link

Support for overloads #102

Open chadrik opened 4 years ago

chadrik commented 4 years ago

I've written a tool that extracts signature data for a C extension from doxygen xml files, and I have stubs that I created using mypy's stubgen, and I'd like to use pyannotate to combine the two. In order to do that I need pyannotate to support @overloads.

I'm happy to make the PR for this.

I was thinking that we can add support for a "overloads" key that contains a list of signature data. The behavior will be slightly different depending on whether the target file is a .py or .pyi

Here's an example json file:

[
  {
    "func_name": "my_command",
    "line": 16,
    "path": "/Users/chad/dev/mymodule.py",
    "samples": 0,
    "overloads": [
      {
        "arg_types": [
          "str"
        ],
        "return_type": "str"
      },
      {
        "arg_types": [
          "int"
        ],
        "return_type": "None"
      }
    ],
    "signature": {
      "arg_types": [
        "Union[str, int]"
      ],
      "return_type": "Optional[str]"
    }
  }
]