pyre-check
pyre-check copied to clipboard
Filtered infer
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
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.
@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):