Method: pylint.lint.pylinter.PyLinter.get_ast
Calls: 1336, Exceptions: 12, Paths: 6Back
Path 1: 1320 calls (0.99)
'/Users/andrehora/Documents/git/projects-pathspotter/pylint/tests/input/similar1' (114) '/Users/andrehora/Documents/git/projects-pathspotter/pylint/te...
'file_to_lint' (50) '--test-file_data-name-0--' (29) '--test-file_data-name-1--' (24) 'fail_under_plus7_5' (20) 'empty' (19) '--test-file_data-name-2-...
None (1320)
Module (1320)
1def get_ast(
2 self, filepath: str, modname: str, data: str | None = None
3 ) -> nodes.Module | None:
4 """Return an ast(roid) representation of a module or a string.
5
6 :param filepath: path to checked file.
7 :param str modname: The name of the module to be checked.
8 :param str data: optional contents of the checked file.
9 :returns: the AST
10 :rtype: astroid.nodes.Module
11 :raises AstroidBuildingError: Whenever we encounter an unexpected exception
12 """
13 try:
14 if data is None:
15 return MANAGER.ast_from_file(filepath, modname, source=True)
16 return astroid.builder.AstroidBuilder(MANAGER).string_build(
17 data, modname, filepath
18 )
19 except astroid.AstroidSyntaxError as ex:
20 line = getattr(ex.error, "lineno", None)
21 if line is None:
22 line = 0
23 self.add_message(
24 "syntax-error",
25 line=line,
26 col_offset=getattr(ex.error, "offset", None),
27 args=f"Parsing failed: '{ex.error}'",
28 confidence=HIGH,
29 )
30 except astroid.AstroidBuildingError as ex:
31 self.add_message("parse-error", args=ex)
32 except Exception as ex:
33 traceback.print_exc()
34 # We raise BuildingError here as this is essentially an astroid issue
35 # Creating an issue template and adding the 'astroid-error' message is handled
36 # by caller: _check_files
37 raise astroid.AstroidBuildingError(
38 "Building error when trying to create ast representation of module '{modname}'",
39 modname=modname,
40 ) from ex
41 return None
Path 2: 8 calls (0.01)
'/Users/andrehora/Documents/git/projects-pathspotter/pylint/tests/regrtest_data/syntax_error.py' (3) '/Users/andrehora/Documents/git/projects-pathspot...
'syntax_error' (4) 'bad_package' (2) 'input.func_w0122_py_30' (1) 'descriptor_crash' (1)
None (8)
None (8)
AstroidSyntaxError (8)
1def get_ast(
2 self, filepath: str, modname: str, data: str | None = None
3 ) -> nodes.Module | None:
4 """Return an ast(roid) representation of a module or a string.
5
6 :param filepath: path to checked file.
7 :param str modname: The name of the module to be checked.
8 :param str data: optional contents of the checked file.
9 :returns: the AST
10 :rtype: astroid.nodes.Module
11 :raises AstroidBuildingError: Whenever we encounter an unexpected exception
12 """
13 try:
14 if data is None:
15 return MANAGER.ast_from_file(filepath, modname, source=True)
16 return astroid.builder.AstroidBuilder(MANAGER).string_build(
17 data, modname, filepath
18 )
19 except astroid.AstroidSyntaxError as ex:
20 line = getattr(ex.error, "lineno", None)
21 if line is None:
22 line = 0
23 self.add_message(
24 "syntax-error",
25 line=line,
26 col_offset=getattr(ex.error, "offset", None),
27 args=f"Parsing failed: '{ex.error}'",
28 confidence=HIGH,
29 )
30 except astroid.AstroidBuildingError as ex:
31 self.add_message("parse-error", args=ex)
32 except Exception as ex:
33 traceback.print_exc()
34 # We raise BuildingError here as this is essentially an astroid issue
35 # Creating an issue template and adding the 'astroid-error' message is handled
36 # by caller: _check_files
37 raise astroid.AstroidBuildingError(
38 "Building error when trying to create ast representation of module '{modname}'",
39 modname=modname,
40 ) from ex
41 return None
Path 3: 4 calls (0.0)
'a/b.py' (2) '/Users/andrehora/Documents/git/projects-pathspotter/pylint/tests/mymodule.py' (1) 'mymodule.py' (1)
'mymodule' (2) 'a.b' (2)
'import os\n' (2) "\nfrom .c import foobar\nfrom .d import bla # module does not exist\n\nfoobar('hello')\nbla()\n" (2)
Module (4)
1def get_ast(
2 self, filepath: str, modname: str, data: str | None = None
3 ) -> nodes.Module | None:
4 """Return an ast(roid) representation of a module or a string.
5
6 :param filepath: path to checked file.
7 :param str modname: The name of the module to be checked.
8 :param str data: optional contents of the checked file.
9 :returns: the AST
10 :rtype: astroid.nodes.Module
11 :raises AstroidBuildingError: Whenever we encounter an unexpected exception
12 """
13 try:
14 if data is None:
15 return MANAGER.ast_from_file(filepath, modname, source=True)
16 return astroid.builder.AstroidBuilder(MANAGER).string_build(
17 data, modname, filepath
18 )
19 except astroid.AstroidSyntaxError as ex:
20 line = getattr(ex.error, "lineno", None)
21 if line is None:
22 line = 0
23 self.add_message(
24 "syntax-error",
25 line=line,
26 col_offset=getattr(ex.error, "offset", None),
27 args=f"Parsing failed: '{ex.error}'",
28 confidence=HIGH,
29 )
30 except astroid.AstroidBuildingError as ex:
31 self.add_message("parse-error", args=ex)
32 except Exception as ex:
33 traceback.print_exc()
34 # We raise BuildingError here as this is essentially an astroid issue
35 # Creating an issue template and adding the 'astroid-error' message is handled
36 # by caller: _check_files
37 raise astroid.AstroidBuildingError(
38 "Building error when trying to create ast representation of module '{modname}'",
39 modname=modname,
40 ) from ex
41 return None
Path 4: 2 calls (0.0)
'/Users/andrehora/Documents/git/projects-pathspotter/pylint/tests/regrtest_data/invalid_encoding.py' (1) '/Users/andrehora/Documents/git/projects-path...
'invalid_encoding' (1) 'bad_wrong_num' (1)
None (2)
None (2)
AstroidSyntaxError (2)
1def get_ast(
2 self, filepath: str, modname: str, data: str | None = None
3 ) -> nodes.Module | None:
4 """Return an ast(roid) representation of a module or a string.
5
6 :param filepath: path to checked file.
7 :param str modname: The name of the module to be checked.
8 :param str data: optional contents of the checked file.
9 :returns: the AST
10 :rtype: astroid.nodes.Module
11 :raises AstroidBuildingError: Whenever we encounter an unexpected exception
12 """
13 try:
14 if data is None:
15 return MANAGER.ast_from_file(filepath, modname, source=True)
16 return astroid.builder.AstroidBuilder(MANAGER).string_build(
17 data, modname, filepath
18 )
19 except astroid.AstroidSyntaxError as ex:
20 line = getattr(ex.error, "lineno", None)
21 if line is None:
22 line = 0
23 self.add_message(
24 "syntax-error",
25 line=line,
26 col_offset=getattr(ex.error, "offset", None),
27 args=f"Parsing failed: '{ex.error}'",
28 confidence=HIGH,
29 )
30 except astroid.AstroidBuildingError as ex:
31 self.add_message("parse-error", args=ex)
32 except Exception as ex:
33 traceback.print_exc()
34 # We raise BuildingError here as this is essentially an astroid issue
35 # Creating an issue template and adding the 'astroid-error' message is handled
36 # by caller: _check_files
37 raise astroid.AstroidBuildingError(
38 "Building error when trying to create ast representation of module '{modname}'",
39 modname=modname,
40 ) from ex
41 return None
Path 5: 1 calls (0.0)
'a.py' (1)
'a' (1)
'for\n' (1)
None (1)
AstroidSyntaxError (1)
1def get_ast(
2 self, filepath: str, modname: str, data: str | None = None
3 ) -> nodes.Module | None:
4 """Return an ast(roid) representation of a module or a string.
5
6 :param filepath: path to checked file.
7 :param str modname: The name of the module to be checked.
8 :param str data: optional contents of the checked file.
9 :returns: the AST
10 :rtype: astroid.nodes.Module
11 :raises AstroidBuildingError: Whenever we encounter an unexpected exception
12 """
13 try:
14 if data is None:
15 return MANAGER.ast_from_file(filepath, modname, source=True)
16 return astroid.builder.AstroidBuilder(MANAGER).string_build(
17 data, modname, filepath
18 )
19 except astroid.AstroidSyntaxError as ex:
20 line = getattr(ex.error, "lineno", None)
21 if line is None:
22 line = 0
23 self.add_message(
24 "syntax-error",
25 line=line,
26 col_offset=getattr(ex.error, "offset", None),
27 args=f"Parsing failed: '{ex.error}'",
28 confidence=HIGH,
29 )
30 except astroid.AstroidBuildingError as ex:
31 self.add_message("parse-error", args=ex)
32 except Exception as ex:
33 traceback.print_exc()
34 # We raise BuildingError here as this is essentially an astroid issue
35 # Creating an issue template and adding the 'astroid-error' message is handled
36 # by caller: _check_files
37 raise astroid.AstroidBuildingError(
38 "Building error when trying to create ast representation of module '{modname}'",
39 modname=modname,
40 ) from ex
41 return None
Path 6: 1 calls (0.0)
'/Users/andrehora/Documents/git/projects-pathspotter/pylint/tests/lint/test_utils.py' (1)
'lint.test_utils' (1)
None (1)
AstroidBuildingError (1)
1def get_ast(
2 self, filepath: str, modname: str, data: str | None = None
3 ) -> nodes.Module | None:
4 """Return an ast(roid) representation of a module or a string.
5
6 :param filepath: path to checked file.
7 :param str modname: The name of the module to be checked.
8 :param str data: optional contents of the checked file.
9 :returns: the AST
10 :rtype: astroid.nodes.Module
11 :raises AstroidBuildingError: Whenever we encounter an unexpected exception
12 """
13 try:
14 if data is None:
15 return MANAGER.ast_from_file(filepath, modname, source=True)
16 return astroid.builder.AstroidBuilder(MANAGER).string_build(
17 data, modname, filepath
18 )
19 except astroid.AstroidSyntaxError as ex:
20 line = getattr(ex.error, "lineno", None)
21 if line is None:
22 line = 0
23 self.add_message(
24 "syntax-error",
25 line=line,
26 col_offset=getattr(ex.error, "offset", None),
27 args=f"Parsing failed: '{ex.error}'",
28 confidence=HIGH,
29 )
30 except astroid.AstroidBuildingError as ex:
31 self.add_message("parse-error", args=ex)
32 except Exception as ex:
33 traceback.print_exc()
34 # We raise BuildingError here as this is essentially an astroid issue
35 # Creating an issue template and adding the 'astroid-error' message is handled
36 # by caller: _check_files
37 raise astroid.AstroidBuildingError(
38 "Building error when trying to create ast representation of module '{modname}'",
39 modname=modname,
40 ) from ex
41 return None