本文整理汇总了Python中mypy.errors.Errors.set_file方法的典型用法代码示例。如果您正苦于以下问题:Python Errors.set_file方法的具体用法?Python Errors.set_file怎么用?Python Errors.set_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mypy.errors.Errors
的用法示例。
在下文中一共展示了Errors.set_file方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parse
# 需要导入模块: from mypy.errors import Errors [as 别名]
# 或者: from mypy.errors.Errors import set_file [as 别名]
def parse(source: Union[str, bytes], fnam: str = None, errors: Errors = None,
pyversion: Tuple[int, int] = defaults.PYTHON3_VERSION,
custom_typing_module: str = None, implicit_any: bool = False) -> MypyFile:
"""Parse a source file, without doing any semantic analysis.
Return the parse tree. If errors is not provided, raise ParseError
on failure. Otherwise, use the errors object to report parse errors.
The pyversion (major, minor) argument determines the Python syntax variant.
"""
is_stub_file = bool(fnam) and fnam.endswith('.pyi')
try:
ast = typed_ast.parse(source, fnam, 'exec')
except SyntaxError as e:
if errors:
errors.set_file('<input>' if fnam is None else fnam)
errors.report(e.lineno, e.msg) # type: ignore
else:
raise
else:
tree = ASTConverter().visit(ast)
tree.path = fnam
tree.is_stub = is_stub_file
return tree
return MypyFile([],
[],
False,
set(),
weak_opts=set())
示例2: parse
# 需要导入模块: from mypy.errors import Errors [as 别名]
# 或者: from mypy.errors.Errors import set_file [as 别名]
def parse(source: Union[str, bytes], fnam: str = None, errors: Errors = None,
pyversion: Tuple[int, int] = defaults.PYTHON3_VERSION,
custom_typing_module: str = None) -> MypyFile:
"""Parse a source file, without doing any semantic analysis.
Return the parse tree. If errors is not provided, raise ParseError
on failure. Otherwise, use the errors object to report parse errors.
The pyversion (major, minor) argument determines the Python syntax variant.
"""
is_stub_file = bool(fnam) and fnam.endswith('.pyi')
try:
assert pyversion[0] < 3 and not is_stub_file
ast = ast27.parse(source, fnam, 'exec')
tree = ASTConverter(pyversion=pyversion,
is_stub=is_stub_file,
custom_typing_module=custom_typing_module,
).visit(ast)
assert isinstance(tree, MypyFile)
tree.path = fnam
tree.is_stub = is_stub_file
return tree
except (SyntaxError, TypeCommentParseError) as e:
if errors:
errors.set_file('<input>' if fnam is None else fnam)
errors.report(e.lineno, e.offset, e.msg)
else:
raise
return MypyFile([], [], False, set())
示例3: parse
# 需要导入模块: from mypy.errors import Errors [as 别名]
# 或者: from mypy.errors.Errors import set_file [as 别名]
def parse(source: Union[str, bytes], fnam: str = None, errors: Errors = None,
pyversion: Tuple[int, int] = defaults.PYTHON3_VERSION,
custom_typing_module: str = None) -> MypyFile:
"""Parse a source file, without doing any semantic analysis.
Return the parse tree. If errors is not provided, raise ParseError
on failure. Otherwise, use the errors object to report parse errors.
The pyversion (major, minor) argument determines the Python syntax variant.
"""
raise_on_error = False
if errors is None:
errors = Errors()
raise_on_error = True
errors.set_file('<input>' if fnam is None else fnam)
is_stub_file = bool(fnam) and fnam.endswith('.pyi')
try:
assert pyversion[0] >= 3 or is_stub_file
ast = ast35.parse(source, fnam, 'exec')
tree = ASTConverter(pyversion=pyversion,
is_stub=is_stub_file,
errors=errors,
custom_typing_module=custom_typing_module,
).visit(ast)
tree.path = fnam
tree.is_stub = is_stub_file
except SyntaxError as e:
errors.report(e.lineno, e.offset, e.msg)
tree = MypyFile([], [], False, set())
if raise_on_error and errors.is_errors():
errors.raise_error()
return tree