dropbox / pyannotate

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

Wrong/Strange paths in type_info.json #16

Closed jabdoa2 closed 6 years ago

jabdoa2 commented 6 years ago

In the Mission Pinball Project we check out two repositories: src/mpf/ (https://github.com/missionpinball/mpf/) src/mpf-mc/ (https://github.com/missionpinball/mpf-mc/)

I ran type annotations from within src/mpf/. Most annotations look fine in type_info.json (there is actually an mpf folder below the other src/mpf):

    {
        "func_name": "Show._add_token",
        "path": "mpf/assets/show.py",
        "type_comments": [
            "(str, List[Union[int, str]], str) -> None"
        ],
        "line": 249,
        "samples": 250
    },

However, some annotations look strange:

    {   
        "func_name": "BcpProcessor",
        "path": "mc/mpfmc/core/bcp_processor.py",
        "type_comments": [
            "() -> None"
        ],
        "line": 15,
        "samples": 1
    },

There is no mc folder below src/mpf/. It refers to file in src/mpf-mc/ (there is a mpfmc folder in src/mpf-mc). However, I have no idea why this is "mc/mpfmc/" instead of "../mpf-mc/mpfmc/".

gvanrossum commented 6 years ago

Hm, there's probably something wrong with the logic that removes "TOP_DIR" from the filename here: https://github.com/dropbox/pyannotate/blob/master/pyannotate_runtime/collect_types.py#L710

Can you experiment with a fix that does what you want and submit it as a PR?

jabdoa2 commented 6 years ago

Will do

gvanrossum commented 6 years ago

With pyannotate 1.0.2, you should now be able to pass a filter function to init_types_collection() that can select and normalize filenames. Let me know if this is useful.