Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add caller func name into type_info.json to make it clear which function is doing wrong #116

Closed
wants to merge 2 commits into from

Conversation

ghost
Copy link

@ghost ghost commented Jul 5, 2021

What this pr does

  • add caller func name into type_info.json
  • this doesn't affect to any original function

Why I do this

I think this is really necessary in a kind of big project.

Let's think if you have a code like this.

def main():
    print(gcd(15, 10))
    print(gcd(24, 10))
    print(gcd("a", "b"))

def gcd(a, b):
    return a, b

This generates type_info like below.

[
    {
        "path": "gcd.py",
        "line": 1,
        "func_name": "main",
        "type_comments": [
            "() -> None"
        ],
        "samples": 1
    },
    {
        "path": "gcd.py",
        "line": 6,
        "func_name": "gcd",
        "type_comments": [
            "(int, int) -> Tuple[int, int]",
            "(str, str) -> Tuple[str, str]"
        ],
        "samples": 3
    }
]

Then, you would come up with the idea like "this gcd function must accept only int. Which function uses in wrong way...?".

However, you can't see any information about that. So you need to dig yourself which code was wrong. I spent the most of time on this while using pyannotate.

Now, this pr will show which code screwed up. This will generate type_info like below

[
    {
        "path": "gcd.py",
        "line": 1,
        "func_name": "main",
        "type_comments": [
            "() -> None"
        ],
        "caller_name": [
            ["__main__ : 7"]
        ],
        "samples": 1
    },
    {
        "path": "gcd.py",
        "line": 6,
        "func_name": "gcd",
        "type_comments": [
            "(int, int) -> Tuple[int, int]",
            "(str, str) -> Tuple[str, str]"
        ],
        "caller_name": [
            [
                "gcd.main : 2",
                "gcd.main : 3"
            ],
            ["gcd.main : 4"]
        ],
        "samples": 3
    }
]

As you see, you can understand (str, str) is called by "gcd.main : 4" easily.

remarks

I submitted Contributor License Agreement.

@ghost
Copy link
Author

ghost commented Jul 5, 2021

Fix #115

@ghost
Copy link
Author

ghost commented Jul 19, 2021

@gvanrossum

Sorry if I shouldn't mention you since you are not in dropbox now, but I just love to hear reviews of this pr.

I really love this project but this doesn't seem to be reviewed actively.

@gvanrossum
Copy link
Contributor

You're going to have to find a new maintainer, sorry.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants