本文整理汇总了Python中mypy.errors.Errors.report方法的典型用法代码示例。如果您正苦于以下问题:Python Errors.report方法的具体用法?Python Errors.report怎么用?Python Errors.report使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mypy.errors.Errors
的用法示例。
在下文中一共展示了Errors.report方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parse
# 需要导入模块: from mypy.errors import Errors [as 别名]
# 或者: from mypy.errors.Errors import report [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())
示例2: parse
# 需要导入模块: from mypy.errors import Errors [as 别名]
# 或者: from mypy.errors.Errors import report [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())
示例3: parse
# 需要导入模块: from mypy.errors import Errors [as 别名]
# 或者: from mypy.errors.Errors import report [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
示例4: parse_type_comment
# 需要导入模块: from mypy.errors import Errors [as 别名]
# 或者: from mypy.errors.Errors import report [as 别名]
def parse_type_comment(type_comment: str, line: int, errors: Errors) -> Optional[Type]:
try:
typ = ast35.parse(type_comment, '<type_comment>', 'eval')
except SyntaxError as e:
errors.report(line, e.offset, TYPE_COMMENT_SYNTAX_ERROR)
return None
else:
assert isinstance(typ, ast35.Expression)
return TypeConverter(errors, line=line).visit(typ.body)