Skip to content

Commit e543edb

Browse files
authored
Add a flag to use the 'signature' format for type annotations (#88)
The motivation here is that the type comment parser can't handle Callable types and I want to be able to use pyannotate to add them.
1 parent f06705d commit e543edb

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

pyannotate_tools/annotations/__main__.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
parser = argparse.ArgumentParser()
1717
parser.add_argument('--type-info', default='type_info.json', metavar="FILE",
1818
help="JSON input file (default type_info.json)")
19+
parser.add_argument('--uses-signature', action='store_true',
20+
help="JSON input uses a signature format")
1921
parser.add_argument('-p', '--print-function', action='store_true',
2022
help="Assume print is a function")
2123
parser.add_argument('-w', '--write', action='store_true',
@@ -108,14 +110,18 @@ def main(args_override=None):
108110
else:
109111
# Produce nice error message if type_info.json not found.
110112
try:
111-
open(args.type_info).close()
113+
with open(args.type_info) as f:
114+
contents = f.read()
112115
except IOError as err:
113116
sys.exit("Can't open type info file: %s" % err)
114117

115118
# Run pass 2 with output into a variable.
116-
data = generate_annotations_json_string(
117-
args.type_info,
118-
only_simple=args.only_simple) # type: List[Any]
119+
if args.uses_signature:
120+
data = json.loads(contents) # type: List[Any]
121+
else:
122+
data = generate_annotations_json_string(
123+
args.type_info,
124+
only_simple=args.only_simple)
119125

120126
# Run pass 3 with input from that variable.
121127
FixAnnotateJson.init_stub_json_from_data(data, args.files[0])

0 commit comments

Comments
 (0)