本文整理汇总了Python中mypy.options.Options.fast_parser方法的典型用法代码示例。如果您正苦于以下问题:Python Options.fast_parser方法的具体用法?Python Options.fast_parser怎么用?Python Options.fast_parser使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mypy.options.Options
的用法示例。
在下文中一共展示了Options.fast_parser方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: generate_stub
# 需要导入模块: from mypy.options import Options [as 别名]
# 或者: from mypy.options.Options import fast_parser [as 别名]
def generate_stub(path: str, output_dir: str, _all_: Optional[List[str]] = None,
target: str = None, add_header: bool = False, module: str = None,
pyversion: Tuple[int, int] = defaults.PYTHON3_VERSION,
fast_parser: bool = False) -> None:
with open(path, 'rb') as f:
source = f.read()
options = MypyOptions()
options.python_version = pyversion
options.fast_parser = fast_parser
try:
ast = mypy.parse.parse(source, fnam=path, errors=None, options=options)
except mypy.errors.CompileError as e:
# Syntax error!
for m in e.messages:
sys.stderr.write('%s\n' % m)
sys.exit(1)
gen = StubGenerator(_all_, pyversion=pyversion)
ast.accept(gen)
if not target:
target = os.path.join(output_dir, os.path.basename(path))
subdir = os.path.dirname(target)
if subdir and not os.path.isdir(subdir):
os.makedirs(subdir)
with open(target, 'w') as file:
if add_header:
write_header(file, module, pyversion=pyversion)
file.write(''.join(gen.output()))