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

Filtered infer #763

Open
r-barnes opened this issue Jul 24, 2023 · 2 comments
Open

Filtered infer #763

r-barnes opened this issue Jul 24, 2023 · 2 comments

Comments

@r-barnes
Copy link
Contributor

Pyre Feature Request

Is your feature request related to a problem? Please describe.
I've run pyre --output=json and written a small script to filter this:

#!/usr/bin/env python3

import json
import sys

# Open the first argument as a file and read it as a JSON object
with open(sys.argv[1], 'r') as f:
    data = json.load(f)

# `data` is a list of dictionaries and filter so that only those with "code": 3 and "description" containing Returning `None` are left
data = [d for d in data if d['code'] == 3 and 'Returning `None`' in d['description']]

# Write the data to stdout as a JSON string
json.dump(data, sys.stdout)

After the above I have 3,742 instances where I could add -> None to my codebase.

This change would be very safe and easy to review because the scope is very narrow and it is automated.

Unfortunately, there's not a way to tell Pyre to fix the code to do this. pyre infer itself will potentially add other things.

Describe the solution you'd like
I'd like a way to control pyre infer in a more fine-grained way.

Describe alternatives you've considered
I'm playing with some crazy regex expressions just now to work around this.

Additional context
N/A

@stroxler
Copy link
Contributor

Pyre infer does have a --simple-annotations flag that only adds annotations which wouldn't require an import.

Would that be enough to solve your problem? It might not, since Pyre could potentially be producing incorrect simple annotations (e.g. incorrectly guessing int or str), but it's worth a try.

We could probably support this by allowing some kind of config to filter and/or rewrite types. But I'm curious how much the off-the-shelf behavior helps.

@r-barnes
Copy link
Contributor Author

@stroxler : I think the case where --simple-annotations would be most problematic would be this:

def write_file(filename=None):

where I expect it would do:

def write_file(filename: None = None):

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

No branches or pull requests

2 participants