70
70
('modules' , List [str ]),
71
71
('ignore_errors' , bool ),
72
72
('recursive' , bool ),
73
+ ('fast_parser' , bool ),
73
74
])
74
75
75
76
76
77
def generate_stub_for_module (module : str , output_dir : str , quiet : bool = False ,
77
78
add_header : bool = False , sigs : Dict [str , str ] = {},
78
79
class_sigs : Dict [str , str ] = {},
79
80
pyversion : Tuple [int , int ] = defaults .PYTHON3_VERSION ,
81
+ fast_parser : bool = False ,
80
82
no_import : bool = False ,
81
83
search_path : List [str ] = [],
82
84
interpreter : str = sys .executable ) -> None :
@@ -103,7 +105,8 @@ def generate_stub_for_module(module: str, output_dir: str, quiet: bool = False,
103
105
target += '.pyi'
104
106
target = os .path .join (output_dir , target )
105
107
generate_stub (module_path , output_dir , module_all ,
106
- target = target , add_header = add_header , module = module , pyversion = pyversion )
108
+ target = target , add_header = add_header , module = module ,
109
+ pyversion = pyversion , fast_parser = fast_parser )
107
110
if not quiet :
108
111
print ('Created %s' % target )
109
112
@@ -168,10 +171,12 @@ def load_python_module_info(module: str, interpreter: str) -> Tuple[str, Optiona
168
171
169
172
def generate_stub (path : str , output_dir : str , _all_ : Optional [List [str ]] = None ,
170
173
target : str = None , add_header : bool = False , module : str = None ,
171
- pyversion : Tuple [int , int ] = defaults .PYTHON3_VERSION ) -> None :
174
+ pyversion : Tuple [int , int ] = defaults .PYTHON3_VERSION ,
175
+ fast_parser : bool = False ) -> None :
172
176
source = open (path , 'rb' ).read ()
173
177
options = MypyOptions ()
174
178
options .python_version = pyversion
179
+ options .fast_parser = fast_parser
175
180
try :
176
181
ast = mypy .parse .parse (source , fnam = path , errors = None , options = options )
177
182
except mypy .errors .CompileError as e :
@@ -612,6 +617,7 @@ def main() -> None:
612
617
sigs = sigs ,
613
618
class_sigs = class_sigs ,
614
619
pyversion = options .pyversion ,
620
+ fast_parser = options .fast_parser ,
615
621
no_import = options .no_import ,
616
622
search_path = options .search_path ,
617
623
interpreter = options .interpreter )
@@ -631,6 +637,7 @@ def parse_options() -> Options:
631
637
doc_dir = ''
632
638
search_path = [] # type: List[str]
633
639
interpreter = ''
640
+ fast_parser = False
634
641
while args and args [0 ].startswith ('-' ):
635
642
if args [0 ] == '--doc-dir' :
636
643
doc_dir = args [1 ]
@@ -645,6 +652,8 @@ def parse_options() -> Options:
645
652
args = args [1 :]
646
653
elif args [0 ] == '--recursive' :
647
654
recursive = True
655
+ elif args [0 ] == '--fast-parser' :
656
+ fast_parser = True
648
657
elif args [0 ] == '--ignore-errors' :
649
658
ignore_errors = True
650
659
elif args [0 ] == '--py2' :
@@ -667,7 +676,8 @@ def parse_options() -> Options:
667
676
interpreter = interpreter ,
668
677
modules = args ,
669
678
ignore_errors = ignore_errors ,
670
- recursive = recursive )
679
+ recursive = recursive ,
680
+ fast_parser = fast_parser )
671
681
672
682
673
683
def default_python2_interpreter () -> str :
@@ -695,6 +705,7 @@ def usage() -> None:
695
705
Options:
696
706
--py2 run in Python 2 mode (default: Python 3 mode)
697
707
--recursive traverse listed modules to generate inner package modules as well
708
+ --fast-parser enable experimental fast parser
698
709
--ignore-errors ignore errors when trying to generate stubs for modules
699
710
--no-import don't import the modules, just parse and analyze them
700
711
(doesn't work with C extension modules and doesn't
0 commit comments