Method: pylint.checkers.stdlib.StdlibChecker._check_open_call
Calls: 135, Exceptions: 84, Paths: 23Back
Path 1: 47 calls (0.35)
Call (47)
'_io' (47)
'open' (47)
NoSuchArgumentError (47)
1def _check_open_call(
2 self, node: nodes.Call, open_module: str, func_name: str
3 ) -> None:
4 """Various checks for an open call."""
5 mode_arg = None
6 try:
7 if open_module == "_io":
8 mode_arg = utils.get_argument_from_call(
9 node, position=1, keyword="mode"
10 )
11 elif open_module == "pathlib":
12 mode_arg = utils.get_argument_from_call(
13 node, position=0, keyword="mode"
14 )
15 except utils.NoSuchArgumentError:
16 pass
17
18 if mode_arg:
19 mode_arg = utils.safe_infer(mode_arg)
20
21 if (
22 func_name in OPEN_FILES_MODE
23 and isinstance(mode_arg, nodes.Const)
24 and not _check_mode_str(mode_arg.value)
25 ):
26 self.add_message(
27 "bad-open-mode",
28 node=node,
29 args=mode_arg.value or str(mode_arg.value),
30 )
31
32 if (
33 not mode_arg
34 or isinstance(mode_arg, nodes.Const)
35 and (not mode_arg.value or "b" not in str(mode_arg.value))
36 ):
37 encoding_arg = None
38 try:
39 if open_module == "pathlib":
40 if node.func.attrname == "read_text":
41 encoding_arg = utils.get_argument_from_call(
42 node, position=0, keyword="encoding"
43 )
44 elif node.func.attrname == "write_text":
45 encoding_arg = utils.get_argument_from_call(
46 node, position=1, keyword="encoding"
47 )
48 else:
49 encoding_arg = utils.get_argument_from_call(
50 node, position=2, keyword="encoding"
51 )
52 else:
53 encoding_arg = utils.get_argument_from_call(
54 node, position=3, keyword="encoding"
55 )
56 except utils.NoSuchArgumentError:
57 self.add_message("unspecified-encoding", node=node)
58
59 if encoding_arg:
60 encoding_arg = utils.safe_infer(encoding_arg)
61
62 if isinstance(encoding_arg, nodes.Const) and encoding_arg.value is None:
63 self.add_message("unspecified-encoding", node=node)
Path 2: 20 calls (0.15)
Call (20)
'_io' (20)
'open' (20)
1def _check_open_call(
2 self, node: nodes.Call, open_module: str, func_name: str
3 ) -> None:
4 """Various checks for an open call."""
5 mode_arg = None
6 try:
7 if open_module == "_io":
8 mode_arg = utils.get_argument_from_call(
9 node, position=1, keyword="mode"
10 )
11 elif open_module == "pathlib":
12 mode_arg = utils.get_argument_from_call(
13 node, position=0, keyword="mode"
14 )
15 except utils.NoSuchArgumentError:
16 pass
17
18 if mode_arg:
19 mode_arg = utils.safe_infer(mode_arg)
20
21 if (
22 func_name in OPEN_FILES_MODE
23 and isinstance(mode_arg, nodes.Const)
24 and not _check_mode_str(mode_arg.value)
25 ):
26 self.add_message(
27 "bad-open-mode",
28 node=node,
29 args=mode_arg.value or str(mode_arg.value),
30 )
31
32 if (
33 not mode_arg
34 or isinstance(mode_arg, nodes.Const)
35 and (not mode_arg.value or "b" not in str(mode_arg.value))
36 ):
37 encoding_arg = None
38 try:
39 if open_module == "pathlib":
40 if node.func.attrname == "read_text":
41 encoding_arg = utils.get_argument_from_call(
42 node, position=0, keyword="encoding"
43 )
44 elif node.func.attrname == "write_text":
45 encoding_arg = utils.get_argument_from_call(
46 node, position=1, keyword="encoding"
47 )
48 else:
49 encoding_arg = utils.get_argument_from_call(
50 node, position=2, keyword="encoding"
51 )
52 else:
53 encoding_arg = utils.get_argument_from_call(
54 node, position=3, keyword="encoding"
55 )
56 except utils.NoSuchArgumentError:
57 self.add_message("unspecified-encoding", node=node)
58
59 if encoding_arg:
60 encoding_arg = utils.safe_infer(encoding_arg)
61
62 if isinstance(encoding_arg, nodes.Const) and encoding_arg.value is None:
63 self.add_message("unspecified-encoding", node=node)
Path 3: 10 calls (0.07)
Call (10)
'_io' (10)
'open' (10)
1def _check_open_call(
2 self, node: nodes.Call, open_module: str, func_name: str
3 ) -> None:
4 """Various checks for an open call."""
5 mode_arg = None
6 try:
7 if open_module == "_io":
8 mode_arg = utils.get_argument_from_call(
9 node, position=1, keyword="mode"
10 )
11 elif open_module == "pathlib":
12 mode_arg = utils.get_argument_from_call(
13 node, position=0, keyword="mode"
14 )
15 except utils.NoSuchArgumentError:
16 pass
17
18 if mode_arg:
19 mode_arg = utils.safe_infer(mode_arg)
20
21 if (
22 func_name in OPEN_FILES_MODE
23 and isinstance(mode_arg, nodes.Const)
24 and not _check_mode_str(mode_arg.value)
25 ):
26 self.add_message(
27 "bad-open-mode",
28 node=node,
29 args=mode_arg.value or str(mode_arg.value),
30 )
31
32 if (
33 not mode_arg
34 or isinstance(mode_arg, nodes.Const)
35 and (not mode_arg.value or "b" not in str(mode_arg.value))
36 ):
37 encoding_arg = None
38 try:
39 if open_module == "pathlib":
40 if node.func.attrname == "read_text":
41 encoding_arg = utils.get_argument_from_call(
42 node, position=0, keyword="encoding"
43 )
44 elif node.func.attrname == "write_text":
45 encoding_arg = utils.get_argument_from_call(
46 node, position=1, keyword="encoding"
47 )
48 else:
49 encoding_arg = utils.get_argument_from_call(
50 node, position=2, keyword="encoding"
51 )
52 else:
53 encoding_arg = utils.get_argument_from_call(
54 node, position=3, keyword="encoding"
55 )
56 except utils.NoSuchArgumentError:
57 self.add_message("unspecified-encoding", node=node)
58
59 if encoding_arg:
60 encoding_arg = utils.safe_infer(encoding_arg)
61
62 if isinstance(encoding_arg, nodes.Const) and encoding_arg.value is None:
63 self.add_message("unspecified-encoding", node=node)
Path 4: 9 calls (0.07)
Call (9)
'_io' (9)
'open' (9)
NoSuchArgumentError (9)
1def _check_open_call(
2 self, node: nodes.Call, open_module: str, func_name: str
3 ) -> None:
4 """Various checks for an open call."""
5 mode_arg = None
6 try:
7 if open_module == "_io":
8 mode_arg = utils.get_argument_from_call(
9 node, position=1, keyword="mode"
10 )
11 elif open_module == "pathlib":
12 mode_arg = utils.get_argument_from_call(
13 node, position=0, keyword="mode"
14 )
15 except utils.NoSuchArgumentError:
16 pass
17
18 if mode_arg:
19 mode_arg = utils.safe_infer(mode_arg)
20
21 if (
22 func_name in OPEN_FILES_MODE
23 and isinstance(mode_arg, nodes.Const)
24 and not _check_mode_str(mode_arg.value)
25 ):
26 self.add_message(
27 "bad-open-mode",
28 node=node,
29 args=mode_arg.value or str(mode_arg.value),
30 )
31
32 if (
33 not mode_arg
34 or isinstance(mode_arg, nodes.Const)
35 and (not mode_arg.value or "b" not in str(mode_arg.value))
36 ):
37 encoding_arg = None
38 try:
39 if open_module == "pathlib":
40 if node.func.attrname == "read_text":
41 encoding_arg = utils.get_argument_from_call(
42 node, position=0, keyword="encoding"
43 )
44 elif node.func.attrname == "write_text":
45 encoding_arg = utils.get_argument_from_call(
46 node, position=1, keyword="encoding"
47 )
48 else:
49 encoding_arg = utils.get_argument_from_call(
50 node, position=2, keyword="encoding"
51 )
52 else:
53 encoding_arg = utils.get_argument_from_call(
54 node, position=3, keyword="encoding"
55 )
56 except utils.NoSuchArgumentError:
57 self.add_message("unspecified-encoding", node=node)
58
59 if encoding_arg:
60 encoding_arg = utils.safe_infer(encoding_arg)
61
62 if isinstance(encoding_arg, nodes.Const) and encoding_arg.value is None:
63 self.add_message("unspecified-encoding", node=node)
Path 5: 6 calls (0.04)
Call (6)
'_io' (6)
'open' (6)
1def _check_open_call(
2 self, node: nodes.Call, open_module: str, func_name: str
3 ) -> None:
4 """Various checks for an open call."""
5 mode_arg = None
6 try:
7 if open_module == "_io":
8 mode_arg = utils.get_argument_from_call(
9 node, position=1, keyword="mode"
10 )
11 elif open_module == "pathlib":
12 mode_arg = utils.get_argument_from_call(
13 node, position=0, keyword="mode"
14 )
15 except utils.NoSuchArgumentError:
16 pass
17
18 if mode_arg:
19 mode_arg = utils.safe_infer(mode_arg)
20
21 if (
22 func_name in OPEN_FILES_MODE
23 and isinstance(mode_arg, nodes.Const)
24 and not _check_mode_str(mode_arg.value)
25 ):
26 self.add_message(
27 "bad-open-mode",
28 node=node,
29 args=mode_arg.value or str(mode_arg.value),
30 )
31
32 if (
33 not mode_arg
34 or isinstance(mode_arg, nodes.Const)
35 and (not mode_arg.value or "b" not in str(mode_arg.value))
36 ):
37 encoding_arg = None
38 try:
39 if open_module == "pathlib":
40 if node.func.attrname == "read_text":
41 encoding_arg = utils.get_argument_from_call(
42 node, position=0, keyword="encoding"
43 )
44 elif node.func.attrname == "write_text":
45 encoding_arg = utils.get_argument_from_call(
46 node, position=1, keyword="encoding"
47 )
48 else:
49 encoding_arg = utils.get_argument_from_call(
50 node, position=2, keyword="encoding"
51 )
52 else:
53 encoding_arg = utils.get_argument_from_call(
54 node, position=3, keyword="encoding"
55 )
56 except utils.NoSuchArgumentError:
57 self.add_message("unspecified-encoding", node=node)
58
59 if encoding_arg:
60 encoding_arg = utils.safe_infer(encoding_arg)
61
62 if isinstance(encoding_arg, nodes.Const) and encoding_arg.value is None:
63 self.add_message("unspecified-encoding", node=node)
Path 6: 6 calls (0.04)
Call (6)
'_io' (6)
'open' (6)
NoSuchArgumentError (6)
1def _check_open_call(
2 self, node: nodes.Call, open_module: str, func_name: str
3 ) -> None:
4 """Various checks for an open call."""
5 mode_arg = None
6 try:
7 if open_module == "_io":
8 mode_arg = utils.get_argument_from_call(
9 node, position=1, keyword="mode"
10 )
11 elif open_module == "pathlib":
12 mode_arg = utils.get_argument_from_call(
13 node, position=0, keyword="mode"
14 )
15 except utils.NoSuchArgumentError:
16 pass
17
18 if mode_arg:
19 mode_arg = utils.safe_infer(mode_arg)
20
21 if (
22 func_name in OPEN_FILES_MODE
23 and isinstance(mode_arg, nodes.Const)
24 and not _check_mode_str(mode_arg.value)
25 ):
26 self.add_message(
27 "bad-open-mode",
28 node=node,
29 args=mode_arg.value or str(mode_arg.value),
30 )
31
32 if (
33 not mode_arg
34 or isinstance(mode_arg, nodes.Const)
35 and (not mode_arg.value or "b" not in str(mode_arg.value))
36 ):
37 encoding_arg = None
38 try:
39 if open_module == "pathlib":
40 if node.func.attrname == "read_text":
41 encoding_arg = utils.get_argument_from_call(
42 node, position=0, keyword="encoding"
43 )
44 elif node.func.attrname == "write_text":
45 encoding_arg = utils.get_argument_from_call(
46 node, position=1, keyword="encoding"
47 )
48 else:
49 encoding_arg = utils.get_argument_from_call(
50 node, position=2, keyword="encoding"
51 )
52 else:
53 encoding_arg = utils.get_argument_from_call(
54 node, position=3, keyword="encoding"
55 )
56 except utils.NoSuchArgumentError:
57 self.add_message("unspecified-encoding", node=node)
58
59 if encoding_arg:
60 encoding_arg = utils.safe_infer(encoding_arg)
61
62 if isinstance(encoding_arg, nodes.Const) and encoding_arg.value is None:
63 self.add_message("unspecified-encoding", node=node)
Path 7: 4 calls (0.03)
Call (4)
'pathlib' (4)
'open' (4)
NoSuchArgumentError (4)
1def _check_open_call(
2 self, node: nodes.Call, open_module: str, func_name: str
3 ) -> None:
4 """Various checks for an open call."""
5 mode_arg = None
6 try:
7 if open_module == "_io":
8 mode_arg = utils.get_argument_from_call(
9 node, position=1, keyword="mode"
10 )
11 elif open_module == "pathlib":
12 mode_arg = utils.get_argument_from_call(
13 node, position=0, keyword="mode"
14 )
15 except utils.NoSuchArgumentError:
16 pass
17
18 if mode_arg:
19 mode_arg = utils.safe_infer(mode_arg)
20
21 if (
22 func_name in OPEN_FILES_MODE
23 and isinstance(mode_arg, nodes.Const)
24 and not _check_mode_str(mode_arg.value)
25 ):
26 self.add_message(
27 "bad-open-mode",
28 node=node,
29 args=mode_arg.value or str(mode_arg.value),
30 )
31
32 if (
33 not mode_arg
34 or isinstance(mode_arg, nodes.Const)
35 and (not mode_arg.value or "b" not in str(mode_arg.value))
36 ):
37 encoding_arg = None
38 try:
39 if open_module == "pathlib":
40 if node.func.attrname == "read_text":
41 encoding_arg = utils.get_argument_from_call(
42 node, position=0, keyword="encoding"
43 )
44 elif node.func.attrname == "write_text":
45 encoding_arg = utils.get_argument_from_call(
46 node, position=1, keyword="encoding"
47 )
48 else:
49 encoding_arg = utils.get_argument_from_call(
50 node, position=2, keyword="encoding"
51 )
52 else:
53 encoding_arg = utils.get_argument_from_call(
54 node, position=3, keyword="encoding"
55 )
56 except utils.NoSuchArgumentError:
57 self.add_message("unspecified-encoding", node=node)
58
59 if encoding_arg:
60 encoding_arg = utils.safe_infer(encoding_arg)
61
62 if isinstance(encoding_arg, nodes.Const) and encoding_arg.value is None:
63 self.add_message("unspecified-encoding", node=node)
Path 8: 4 calls (0.03)
Call (4)
'_io' (4)
'open' (4)
NoSuchArgumentError (4)
1def _check_open_call(
2 self, node: nodes.Call, open_module: str, func_name: str
3 ) -> None:
4 """Various checks for an open call."""
5 mode_arg = None
6 try:
7 if open_module == "_io":
8 mode_arg = utils.get_argument_from_call(
9 node, position=1, keyword="mode"
10 )
11 elif open_module == "pathlib":
12 mode_arg = utils.get_argument_from_call(
13 node, position=0, keyword="mode"
14 )
15 except utils.NoSuchArgumentError:
16 pass
17
18 if mode_arg:
19 mode_arg = utils.safe_infer(mode_arg)
20
21 if (
22 func_name in OPEN_FILES_MODE
23 and isinstance(mode_arg, nodes.Const)
24 and not _check_mode_str(mode_arg.value)
25 ):
26 self.add_message(
27 "bad-open-mode",
28 node=node,
29 args=mode_arg.value or str(mode_arg.value),
30 )
31
32 if (
33 not mode_arg
34 or isinstance(mode_arg, nodes.Const)
35 and (not mode_arg.value or "b" not in str(mode_arg.value))
36 ):
37 encoding_arg = None
38 try:
39 if open_module == "pathlib":
40 if node.func.attrname == "read_text":
41 encoding_arg = utils.get_argument_from_call(
42 node, position=0, keyword="encoding"
43 )
44 elif node.func.attrname == "write_text":
45 encoding_arg = utils.get_argument_from_call(
46 node, position=1, keyword="encoding"
47 )
48 else:
49 encoding_arg = utils.get_argument_from_call(
50 node, position=2, keyword="encoding"
51 )
52 else:
53 encoding_arg = utils.get_argument_from_call(
54 node, position=3, keyword="encoding"
55 )
56 except utils.NoSuchArgumentError:
57 self.add_message("unspecified-encoding", node=node)
58
59 if encoding_arg:
60 encoding_arg = utils.safe_infer(encoding_arg)
61
62 if isinstance(encoding_arg, nodes.Const) and encoding_arg.value is None:
63 self.add_message("unspecified-encoding", node=node)
Path 9: 3 calls (0.02)
Call (3)
'pathlib' (3)
'write_text' (3)
1def _check_open_call(
2 self, node: nodes.Call, open_module: str, func_name: str
3 ) -> None:
4 """Various checks for an open call."""
5 mode_arg = None
6 try:
7 if open_module == "_io":
8 mode_arg = utils.get_argument_from_call(
9 node, position=1, keyword="mode"
10 )
11 elif open_module == "pathlib":
12 mode_arg = utils.get_argument_from_call(
13 node, position=0, keyword="mode"
14 )
15 except utils.NoSuchArgumentError:
16 pass
17
18 if mode_arg:
19 mode_arg = utils.safe_infer(mode_arg)
20
21 if (
22 func_name in OPEN_FILES_MODE
23 and isinstance(mode_arg, nodes.Const)
24 and not _check_mode_str(mode_arg.value)
25 ):
26 self.add_message(
27 "bad-open-mode",
28 node=node,
29 args=mode_arg.value or str(mode_arg.value),
30 )
31
32 if (
33 not mode_arg
34 or isinstance(mode_arg, nodes.Const)
35 and (not mode_arg.value or "b" not in str(mode_arg.value))
36 ):
37 encoding_arg = None
38 try:
39 if open_module == "pathlib":
40 if node.func.attrname == "read_text":
41 encoding_arg = utils.get_argument_from_call(
42 node, position=0, keyword="encoding"
43 )
44 elif node.func.attrname == "write_text":
45 encoding_arg = utils.get_argument_from_call(
46 node, position=1, keyword="encoding"
47 )
48 else:
49 encoding_arg = utils.get_argument_from_call(
50 node, position=2, keyword="encoding"
51 )
52 else:
53 encoding_arg = utils.get_argument_from_call(
54 node, position=3, keyword="encoding"
55 )
56 except utils.NoSuchArgumentError:
57 self.add_message("unspecified-encoding", node=node)
58
59 if encoding_arg:
60 encoding_arg = utils.safe_infer(encoding_arg)
61
62 if isinstance(encoding_arg, nodes.Const) and encoding_arg.value is None:
63 self.add_message("unspecified-encoding", node=node)
Path 10: 3 calls (0.02)
Call (3)
'pathlib' (3)
'open' (3)
NoSuchArgumentError (3)
1def _check_open_call(
2 self, node: nodes.Call, open_module: str, func_name: str
3 ) -> None:
4 """Various checks for an open call."""
5 mode_arg = None
6 try:
7 if open_module == "_io":
8 mode_arg = utils.get_argument_from_call(
9 node, position=1, keyword="mode"
10 )
11 elif open_module == "pathlib":
12 mode_arg = utils.get_argument_from_call(
13 node, position=0, keyword="mode"
14 )
15 except utils.NoSuchArgumentError:
16 pass
17
18 if mode_arg:
19 mode_arg = utils.safe_infer(mode_arg)
20
21 if (
22 func_name in OPEN_FILES_MODE
23 and isinstance(mode_arg, nodes.Const)
24 and not _check_mode_str(mode_arg.value)
25 ):
26 self.add_message(
27 "bad-open-mode",
28 node=node,
29 args=mode_arg.value or str(mode_arg.value),
30 )
31
32 if (
33 not mode_arg
34 or isinstance(mode_arg, nodes.Const)
35 and (not mode_arg.value or "b" not in str(mode_arg.value))
36 ):
37 encoding_arg = None
38 try:
39 if open_module == "pathlib":
40 if node.func.attrname == "read_text":
41 encoding_arg = utils.get_argument_from_call(
42 node, position=0, keyword="encoding"
43 )
44 elif node.func.attrname == "write_text":
45 encoding_arg = utils.get_argument_from_call(
46 node, position=1, keyword="encoding"
47 )
48 else:
49 encoding_arg = utils.get_argument_from_call(
50 node, position=2, keyword="encoding"
51 )
52 else:
53 encoding_arg = utils.get_argument_from_call(
54 node, position=3, keyword="encoding"
55 )
56 except utils.NoSuchArgumentError:
57 self.add_message("unspecified-encoding", node=node)
58
59 if encoding_arg:
60 encoding_arg = utils.safe_infer(encoding_arg)
61
62 if isinstance(encoding_arg, nodes.Const) and encoding_arg.value is None:
63 self.add_message("unspecified-encoding", node=node)
Path 11: 2 calls (0.01)
Call (2)
'_io' (2)
'open' (2)
1def _check_open_call(
2 self, node: nodes.Call, open_module: str, func_name: str
3 ) -> None:
4 """Various checks for an open call."""
5 mode_arg = None
6 try:
7 if open_module == "_io":
8 mode_arg = utils.get_argument_from_call(
9 node, position=1, keyword="mode"
10 )
11 elif open_module == "pathlib":
12 mode_arg = utils.get_argument_from_call(
13 node, position=0, keyword="mode"
14 )
15 except utils.NoSuchArgumentError:
16 pass
17
18 if mode_arg:
19 mode_arg = utils.safe_infer(mode_arg)
20
21 if (
22 func_name in OPEN_FILES_MODE
23 and isinstance(mode_arg, nodes.Const)
24 and not _check_mode_str(mode_arg.value)
25 ):
26 self.add_message(
27 "bad-open-mode",
28 node=node,
29 args=mode_arg.value or str(mode_arg.value),
30 )
31
32 if (
33 not mode_arg
34 or isinstance(mode_arg, nodes.Const)
35 and (not mode_arg.value or "b" not in str(mode_arg.value))
36 ):
37 encoding_arg = None
38 try:
39 if open_module == "pathlib":
40 if node.func.attrname == "read_text":
41 encoding_arg = utils.get_argument_from_call(
42 node, position=0, keyword="encoding"
43 )
44 elif node.func.attrname == "write_text":
45 encoding_arg = utils.get_argument_from_call(
46 node, position=1, keyword="encoding"
47 )
48 else:
49 encoding_arg = utils.get_argument_from_call(
50 node, position=2, keyword="encoding"
51 )
52 else:
53 encoding_arg = utils.get_argument_from_call(
54 node, position=3, keyword="encoding"
55 )
56 except utils.NoSuchArgumentError:
57 self.add_message("unspecified-encoding", node=node)
58
59 if encoding_arg:
60 encoding_arg = utils.safe_infer(encoding_arg)
61
62 if isinstance(encoding_arg, nodes.Const) and encoding_arg.value is None:
63 self.add_message("unspecified-encoding", node=node)
Path 12: 2 calls (0.01)
Call (2)
'pathlib' (2)
'read_text' (2)
NoSuchArgumentError (2)
1def _check_open_call(
2 self, node: nodes.Call, open_module: str, func_name: str
3 ) -> None:
4 """Various checks for an open call."""
5 mode_arg = None
6 try:
7 if open_module == "_io":
8 mode_arg = utils.get_argument_from_call(
9 node, position=1, keyword="mode"
10 )
11 elif open_module == "pathlib":
12 mode_arg = utils.get_argument_from_call(
13 node, position=0, keyword="mode"
14 )
15 except utils.NoSuchArgumentError:
16 pass
17
18 if mode_arg:
19 mode_arg = utils.safe_infer(mode_arg)
20
21 if (
22 func_name in OPEN_FILES_MODE
23 and isinstance(mode_arg, nodes.Const)
24 and not _check_mode_str(mode_arg.value)
25 ):
26 self.add_message(
27 "bad-open-mode",
28 node=node,
29 args=mode_arg.value or str(mode_arg.value),
30 )
31
32 if (
33 not mode_arg
34 or isinstance(mode_arg, nodes.Const)
35 and (not mode_arg.value or "b" not in str(mode_arg.value))
36 ):
37 encoding_arg = None
38 try:
39 if open_module == "pathlib":
40 if node.func.attrname == "read_text":
41 encoding_arg = utils.get_argument_from_call(
42 node, position=0, keyword="encoding"
43 )
44 elif node.func.attrname == "write_text":
45 encoding_arg = utils.get_argument_from_call(
46 node, position=1, keyword="encoding"
47 )
48 else:
49 encoding_arg = utils.get_argument_from_call(
50 node, position=2, keyword="encoding"
51 )
52 else:
53 encoding_arg = utils.get_argument_from_call(
54 node, position=3, keyword="encoding"
55 )
56 except utils.NoSuchArgumentError:
57 self.add_message("unspecified-encoding", node=node)
58
59 if encoding_arg:
60 encoding_arg = utils.safe_infer(encoding_arg)
61
62 if isinstance(encoding_arg, nodes.Const) and encoding_arg.value is None:
63 self.add_message("unspecified-encoding", node=node)
Path 13: 2 calls (0.01)
Call (2)
'pathlib' (2)
'read_text' (2)
1def _check_open_call(
2 self, node: nodes.Call, open_module: str, func_name: str
3 ) -> None:
4 """Various checks for an open call."""
5 mode_arg = None
6 try:
7 if open_module == "_io":
8 mode_arg = utils.get_argument_from_call(
9 node, position=1, keyword="mode"
10 )
11 elif open_module == "pathlib":
12 mode_arg = utils.get_argument_from_call(
13 node, position=0, keyword="mode"
14 )
15 except utils.NoSuchArgumentError:
16 pass
17
18 if mode_arg:
19 mode_arg = utils.safe_infer(mode_arg)
20
21 if (
22 func_name in OPEN_FILES_MODE
23 and isinstance(mode_arg, nodes.Const)
24 and not _check_mode_str(mode_arg.value)
25 ):
26 self.add_message(
27 "bad-open-mode",
28 node=node,
29 args=mode_arg.value or str(mode_arg.value),
30 )
31
32 if (
33 not mode_arg
34 or isinstance(mode_arg, nodes.Const)
35 and (not mode_arg.value or "b" not in str(mode_arg.value))
36 ):
37 encoding_arg = None
38 try:
39 if open_module == "pathlib":
40 if node.func.attrname == "read_text":
41 encoding_arg = utils.get_argument_from_call(
42 node, position=0, keyword="encoding"
43 )
44 elif node.func.attrname == "write_text":
45 encoding_arg = utils.get_argument_from_call(
46 node, position=1, keyword="encoding"
47 )
48 else:
49 encoding_arg = utils.get_argument_from_call(
50 node, position=2, keyword="encoding"
51 )
52 else:
53 encoding_arg = utils.get_argument_from_call(
54 node, position=3, keyword="encoding"
55 )
56 except utils.NoSuchArgumentError:
57 self.add_message("unspecified-encoding", node=node)
58
59 if encoding_arg:
60 encoding_arg = utils.safe_infer(encoding_arg)
61
62 if isinstance(encoding_arg, nodes.Const) and encoding_arg.value is None:
63 self.add_message("unspecified-encoding", node=node)
Path 14: 2 calls (0.01)
Call (2)
'pathlib' (2)
'read_text' (2)
NoSuchArgumentError (2)
1def _check_open_call(
2 self, node: nodes.Call, open_module: str, func_name: str
3 ) -> None:
4 """Various checks for an open call."""
5 mode_arg = None
6 try:
7 if open_module == "_io":
8 mode_arg = utils.get_argument_from_call(
9 node, position=1, keyword="mode"
10 )
11 elif open_module == "pathlib":
12 mode_arg = utils.get_argument_from_call(
13 node, position=0, keyword="mode"
14 )
15 except utils.NoSuchArgumentError:
16 pass
17
18 if mode_arg:
19 mode_arg = utils.safe_infer(mode_arg)
20
21 if (
22 func_name in OPEN_FILES_MODE
23 and isinstance(mode_arg, nodes.Const)
24 and not _check_mode_str(mode_arg.value)
25 ):
26 self.add_message(
27 "bad-open-mode",
28 node=node,
29 args=mode_arg.value or str(mode_arg.value),
30 )
31
32 if (
33 not mode_arg
34 or isinstance(mode_arg, nodes.Const)
35 and (not mode_arg.value or "b" not in str(mode_arg.value))
36 ):
37 encoding_arg = None
38 try:
39 if open_module == "pathlib":
40 if node.func.attrname == "read_text":
41 encoding_arg = utils.get_argument_from_call(
42 node, position=0, keyword="encoding"
43 )
44 elif node.func.attrname == "write_text":
45 encoding_arg = utils.get_argument_from_call(
46 node, position=1, keyword="encoding"
47 )
48 else:
49 encoding_arg = utils.get_argument_from_call(
50 node, position=2, keyword="encoding"
51 )
52 else:
53 encoding_arg = utils.get_argument_from_call(
54 node, position=3, keyword="encoding"
55 )
56 except utils.NoSuchArgumentError:
57 self.add_message("unspecified-encoding", node=node)
58
59 if encoding_arg:
60 encoding_arg = utils.safe_infer(encoding_arg)
61
62 if isinstance(encoding_arg, nodes.Const) and encoding_arg.value is None:
63 self.add_message("unspecified-encoding", node=node)
Path 15: 2 calls (0.01)
Call (2)
'pathlib' (2)
'read_text' (2)
NoSuchArgumentError (2)
1def _check_open_call(
2 self, node: nodes.Call, open_module: str, func_name: str
3 ) -> None:
4 """Various checks for an open call."""
5 mode_arg = None
6 try:
7 if open_module == "_io":
8 mode_arg = utils.get_argument_from_call(
9 node, position=1, keyword="mode"
10 )
11 elif open_module == "pathlib":
12 mode_arg = utils.get_argument_from_call(
13 node, position=0, keyword="mode"
14 )
15 except utils.NoSuchArgumentError:
16 pass
17
18 if mode_arg:
19 mode_arg = utils.safe_infer(mode_arg)
20
21 if (
22 func_name in OPEN_FILES_MODE
23 and isinstance(mode_arg, nodes.Const)
24 and not _check_mode_str(mode_arg.value)
25 ):
26 self.add_message(
27 "bad-open-mode",
28 node=node,
29 args=mode_arg.value or str(mode_arg.value),
30 )
31
32 if (
33 not mode_arg
34 or isinstance(mode_arg, nodes.Const)
35 and (not mode_arg.value or "b" not in str(mode_arg.value))
36 ):
37 encoding_arg = None
38 try:
39 if open_module == "pathlib":
40 if node.func.attrname == "read_text":
41 encoding_arg = utils.get_argument_from_call(
42 node, position=0, keyword="encoding"
43 )
44 elif node.func.attrname == "write_text":
45 encoding_arg = utils.get_argument_from_call(
46 node, position=1, keyword="encoding"
47 )
48 else:
49 encoding_arg = utils.get_argument_from_call(
50 node, position=2, keyword="encoding"
51 )
52 else:
53 encoding_arg = utils.get_argument_from_call(
54 node, position=3, keyword="encoding"
55 )
56 except utils.NoSuchArgumentError:
57 self.add_message("unspecified-encoding", node=node)
58
59 if encoding_arg:
60 encoding_arg = utils.safe_infer(encoding_arg)
61
62 if isinstance(encoding_arg, nodes.Const) and encoding_arg.value is None:
63 self.add_message("unspecified-encoding", node=node)
Path 16: 2 calls (0.01)
Call (2)
'pathlib' (2)
'write_text' (2)
NoSuchArgumentError (2)
1def _check_open_call(
2 self, node: nodes.Call, open_module: str, func_name: str
3 ) -> None:
4 """Various checks for an open call."""
5 mode_arg = None
6 try:
7 if open_module == "_io":
8 mode_arg = utils.get_argument_from_call(
9 node, position=1, keyword="mode"
10 )
11 elif open_module == "pathlib":
12 mode_arg = utils.get_argument_from_call(
13 node, position=0, keyword="mode"
14 )
15 except utils.NoSuchArgumentError:
16 pass
17
18 if mode_arg:
19 mode_arg = utils.safe_infer(mode_arg)
20
21 if (
22 func_name in OPEN_FILES_MODE
23 and isinstance(mode_arg, nodes.Const)
24 and not _check_mode_str(mode_arg.value)
25 ):
26 self.add_message(
27 "bad-open-mode",
28 node=node,
29 args=mode_arg.value or str(mode_arg.value),
30 )
31
32 if (
33 not mode_arg
34 or isinstance(mode_arg, nodes.Const)
35 and (not mode_arg.value or "b" not in str(mode_arg.value))
36 ):
37 encoding_arg = None
38 try:
39 if open_module == "pathlib":
40 if node.func.attrname == "read_text":
41 encoding_arg = utils.get_argument_from_call(
42 node, position=0, keyword="encoding"
43 )
44 elif node.func.attrname == "write_text":
45 encoding_arg = utils.get_argument_from_call(
46 node, position=1, keyword="encoding"
47 )
48 else:
49 encoding_arg = utils.get_argument_from_call(
50 node, position=2, keyword="encoding"
51 )
52 else:
53 encoding_arg = utils.get_argument_from_call(
54 node, position=3, keyword="encoding"
55 )
56 except utils.NoSuchArgumentError:
57 self.add_message("unspecified-encoding", node=node)
58
59 if encoding_arg:
60 encoding_arg = utils.safe_infer(encoding_arg)
61
62 if isinstance(encoding_arg, nodes.Const) and encoding_arg.value is None:
63 self.add_message("unspecified-encoding", node=node)
Path 17: 2 calls (0.01)
Call (2)
'pathlib' (2)
'write_text' (2)
1def _check_open_call(
2 self, node: nodes.Call, open_module: str, func_name: str
3 ) -> None:
4 """Various checks for an open call."""
5 mode_arg = None
6 try:
7 if open_module == "_io":
8 mode_arg = utils.get_argument_from_call(
9 node, position=1, keyword="mode"
10 )
11 elif open_module == "pathlib":
12 mode_arg = utils.get_argument_from_call(
13 node, position=0, keyword="mode"
14 )
15 except utils.NoSuchArgumentError:
16 pass
17
18 if mode_arg:
19 mode_arg = utils.safe_infer(mode_arg)
20
21 if (
22 func_name in OPEN_FILES_MODE
23 and isinstance(mode_arg, nodes.Const)
24 and not _check_mode_str(mode_arg.value)
25 ):
26 self.add_message(
27 "bad-open-mode",
28 node=node,
29 args=mode_arg.value or str(mode_arg.value),
30 )
31
32 if (
33 not mode_arg
34 or isinstance(mode_arg, nodes.Const)
35 and (not mode_arg.value or "b" not in str(mode_arg.value))
36 ):
37 encoding_arg = None
38 try:
39 if open_module == "pathlib":
40 if node.func.attrname == "read_text":
41 encoding_arg = utils.get_argument_from_call(
42 node, position=0, keyword="encoding"
43 )
44 elif node.func.attrname == "write_text":
45 encoding_arg = utils.get_argument_from_call(
46 node, position=1, keyword="encoding"
47 )
48 else:
49 encoding_arg = utils.get_argument_from_call(
50 node, position=2, keyword="encoding"
51 )
52 else:
53 encoding_arg = utils.get_argument_from_call(
54 node, position=3, keyword="encoding"
55 )
56 except utils.NoSuchArgumentError:
57 self.add_message("unspecified-encoding", node=node)
58
59 if encoding_arg:
60 encoding_arg = utils.safe_infer(encoding_arg)
61
62 if isinstance(encoding_arg, nodes.Const) and encoding_arg.value is None:
63 self.add_message("unspecified-encoding", node=node)
Path 18: 2 calls (0.01)
Call (2)
'pathlib' (2)
'open' (2)
1def _check_open_call(
2 self, node: nodes.Call, open_module: str, func_name: str
3 ) -> None:
4 """Various checks for an open call."""
5 mode_arg = None
6 try:
7 if open_module == "_io":
8 mode_arg = utils.get_argument_from_call(
9 node, position=1, keyword="mode"
10 )
11 elif open_module == "pathlib":
12 mode_arg = utils.get_argument_from_call(
13 node, position=0, keyword="mode"
14 )
15 except utils.NoSuchArgumentError:
16 pass
17
18 if mode_arg:
19 mode_arg = utils.safe_infer(mode_arg)
20
21 if (
22 func_name in OPEN_FILES_MODE
23 and isinstance(mode_arg, nodes.Const)
24 and not _check_mode_str(mode_arg.value)
25 ):
26 self.add_message(
27 "bad-open-mode",
28 node=node,
29 args=mode_arg.value or str(mode_arg.value),
30 )
31
32 if (
33 not mode_arg
34 or isinstance(mode_arg, nodes.Const)
35 and (not mode_arg.value or "b" not in str(mode_arg.value))
36 ):
37 encoding_arg = None
38 try:
39 if open_module == "pathlib":
40 if node.func.attrname == "read_text":
41 encoding_arg = utils.get_argument_from_call(
42 node, position=0, keyword="encoding"
43 )
44 elif node.func.attrname == "write_text":
45 encoding_arg = utils.get_argument_from_call(
46 node, position=1, keyword="encoding"
47 )
48 else:
49 encoding_arg = utils.get_argument_from_call(
50 node, position=2, keyword="encoding"
51 )
52 else:
53 encoding_arg = utils.get_argument_from_call(
54 node, position=3, keyword="encoding"
55 )
56 except utils.NoSuchArgumentError:
57 self.add_message("unspecified-encoding", node=node)
58
59 if encoding_arg:
60 encoding_arg = utils.safe_infer(encoding_arg)
61
62 if isinstance(encoding_arg, nodes.Const) and encoding_arg.value is None:
63 self.add_message("unspecified-encoding", node=node)
Path 19: 2 calls (0.01)
Call (2)
'_io' (2)
'open' (2)
1def _check_open_call(
2 self, node: nodes.Call, open_module: str, func_name: str
3 ) -> None:
4 """Various checks for an open call."""
5 mode_arg = None
6 try:
7 if open_module == "_io":
8 mode_arg = utils.get_argument_from_call(
9 node, position=1, keyword="mode"
10 )
11 elif open_module == "pathlib":
12 mode_arg = utils.get_argument_from_call(
13 node, position=0, keyword="mode"
14 )
15 except utils.NoSuchArgumentError:
16 pass
17
18 if mode_arg:
19 mode_arg = utils.safe_infer(mode_arg)
20
21 if (
22 func_name in OPEN_FILES_MODE
23 and isinstance(mode_arg, nodes.Const)
24 and not _check_mode_str(mode_arg.value)
25 ):
26 self.add_message(
27 "bad-open-mode",
28 node=node,
29 args=mode_arg.value or str(mode_arg.value),
30 )
31
32 if (
33 not mode_arg
34 or isinstance(mode_arg, nodes.Const)
35 and (not mode_arg.value or "b" not in str(mode_arg.value))
36 ):
37 encoding_arg = None
38 try:
39 if open_module == "pathlib":
40 if node.func.attrname == "read_text":
41 encoding_arg = utils.get_argument_from_call(
42 node, position=0, keyword="encoding"
43 )
44 elif node.func.attrname == "write_text":
45 encoding_arg = utils.get_argument_from_call(
46 node, position=1, keyword="encoding"
47 )
48 else:
49 encoding_arg = utils.get_argument_from_call(
50 node, position=2, keyword="encoding"
51 )
52 else:
53 encoding_arg = utils.get_argument_from_call(
54 node, position=3, keyword="encoding"
55 )
56 except utils.NoSuchArgumentError:
57 self.add_message("unspecified-encoding", node=node)
58
59 if encoding_arg:
60 encoding_arg = utils.safe_infer(encoding_arg)
61
62 if isinstance(encoding_arg, nodes.Const) and encoding_arg.value is None:
63 self.add_message("unspecified-encoding", node=node)
Path 20: 2 calls (0.01)
Call (2)
'_io' (2)
'open' (2)
NoSuchArgumentError (2)
1def _check_open_call(
2 self, node: nodes.Call, open_module: str, func_name: str
3 ) -> None:
4 """Various checks for an open call."""
5 mode_arg = None
6 try:
7 if open_module == "_io":
8 mode_arg = utils.get_argument_from_call(
9 node, position=1, keyword="mode"
10 )
11 elif open_module == "pathlib":
12 mode_arg = utils.get_argument_from_call(
13 node, position=0, keyword="mode"
14 )
15 except utils.NoSuchArgumentError:
16 pass
17
18 if mode_arg:
19 mode_arg = utils.safe_infer(mode_arg)
20
21 if (
22 func_name in OPEN_FILES_MODE
23 and isinstance(mode_arg, nodes.Const)
24 and not _check_mode_str(mode_arg.value)
25 ):
26 self.add_message(
27 "bad-open-mode",
28 node=node,
29 args=mode_arg.value or str(mode_arg.value),
30 )
31
32 if (
33 not mode_arg
34 or isinstance(mode_arg, nodes.Const)
35 and (not mode_arg.value or "b" not in str(mode_arg.value))
36 ):
37 encoding_arg = None
38 try:
39 if open_module == "pathlib":
40 if node.func.attrname == "read_text":
41 encoding_arg = utils.get_argument_from_call(
42 node, position=0, keyword="encoding"
43 )
44 elif node.func.attrname == "write_text":
45 encoding_arg = utils.get_argument_from_call(
46 node, position=1, keyword="encoding"
47 )
48 else:
49 encoding_arg = utils.get_argument_from_call(
50 node, position=2, keyword="encoding"
51 )
52 else:
53 encoding_arg = utils.get_argument_from_call(
54 node, position=3, keyword="encoding"
55 )
56 except utils.NoSuchArgumentError:
57 self.add_message("unspecified-encoding", node=node)
58
59 if encoding_arg:
60 encoding_arg = utils.safe_infer(encoding_arg)
61
62 if isinstance(encoding_arg, nodes.Const) and encoding_arg.value is None:
63 self.add_message("unspecified-encoding", node=node)
Path 21: 1 calls (0.01)
Call (1)
'pathlib' (1)
'open' (1)
1def _check_open_call(
2 self, node: nodes.Call, open_module: str, func_name: str
3 ) -> None:
4 """Various checks for an open call."""
5 mode_arg = None
6 try:
7 if open_module == "_io":
8 mode_arg = utils.get_argument_from_call(
9 node, position=1, keyword="mode"
10 )
11 elif open_module == "pathlib":
12 mode_arg = utils.get_argument_from_call(
13 node, position=0, keyword="mode"
14 )
15 except utils.NoSuchArgumentError:
16 pass
17
18 if mode_arg:
19 mode_arg = utils.safe_infer(mode_arg)
20
21 if (
22 func_name in OPEN_FILES_MODE
23 and isinstance(mode_arg, nodes.Const)
24 and not _check_mode_str(mode_arg.value)
25 ):
26 self.add_message(
27 "bad-open-mode",
28 node=node,
29 args=mode_arg.value or str(mode_arg.value),
30 )
31
32 if (
33 not mode_arg
34 or isinstance(mode_arg, nodes.Const)
35 and (not mode_arg.value or "b" not in str(mode_arg.value))
36 ):
37 encoding_arg = None
38 try:
39 if open_module == "pathlib":
40 if node.func.attrname == "read_text":
41 encoding_arg = utils.get_argument_from_call(
42 node, position=0, keyword="encoding"
43 )
44 elif node.func.attrname == "write_text":
45 encoding_arg = utils.get_argument_from_call(
46 node, position=1, keyword="encoding"
47 )
48 else:
49 encoding_arg = utils.get_argument_from_call(
50 node, position=2, keyword="encoding"
51 )
52 else:
53 encoding_arg = utils.get_argument_from_call(
54 node, position=3, keyword="encoding"
55 )
56 except utils.NoSuchArgumentError:
57 self.add_message("unspecified-encoding", node=node)
58
59 if encoding_arg:
60 encoding_arg = utils.safe_infer(encoding_arg)
61
62 if isinstance(encoding_arg, nodes.Const) and encoding_arg.value is None:
63 self.add_message("unspecified-encoding", node=node)
Path 22: 1 calls (0.01)
Call (1)
'pathlib' (1)
'open' (1)
NoSuchArgumentError (1)
1def _check_open_call(
2 self, node: nodes.Call, open_module: str, func_name: str
3 ) -> None:
4 """Various checks for an open call."""
5 mode_arg = None
6 try:
7 if open_module == "_io":
8 mode_arg = utils.get_argument_from_call(
9 node, position=1, keyword="mode"
10 )
11 elif open_module == "pathlib":
12 mode_arg = utils.get_argument_from_call(
13 node, position=0, keyword="mode"
14 )
15 except utils.NoSuchArgumentError:
16 pass
17
18 if mode_arg:
19 mode_arg = utils.safe_infer(mode_arg)
20
21 if (
22 func_name in OPEN_FILES_MODE
23 and isinstance(mode_arg, nodes.Const)
24 and not _check_mode_str(mode_arg.value)
25 ):
26 self.add_message(
27 "bad-open-mode",
28 node=node,
29 args=mode_arg.value or str(mode_arg.value),
30 )
31
32 if (
33 not mode_arg
34 or isinstance(mode_arg, nodes.Const)
35 and (not mode_arg.value or "b" not in str(mode_arg.value))
36 ):
37 encoding_arg = None
38 try:
39 if open_module == "pathlib":
40 if node.func.attrname == "read_text":
41 encoding_arg = utils.get_argument_from_call(
42 node, position=0, keyword="encoding"
43 )
44 elif node.func.attrname == "write_text":
45 encoding_arg = utils.get_argument_from_call(
46 node, position=1, keyword="encoding"
47 )
48 else:
49 encoding_arg = utils.get_argument_from_call(
50 node, position=2, keyword="encoding"
51 )
52 else:
53 encoding_arg = utils.get_argument_from_call(
54 node, position=3, keyword="encoding"
55 )
56 except utils.NoSuchArgumentError:
57 self.add_message("unspecified-encoding", node=node)
58
59 if encoding_arg:
60 encoding_arg = utils.safe_infer(encoding_arg)
61
62 if isinstance(encoding_arg, nodes.Const) and encoding_arg.value is None:
63 self.add_message("unspecified-encoding", node=node)
Path 23: 1 calls (0.01)
Call (1)
'pathlib' (1)
'open' (1)
1def _check_open_call(
2 self, node: nodes.Call, open_module: str, func_name: str
3 ) -> None:
4 """Various checks for an open call."""
5 mode_arg = None
6 try:
7 if open_module == "_io":
8 mode_arg = utils.get_argument_from_call(
9 node, position=1, keyword="mode"
10 )
11 elif open_module == "pathlib":
12 mode_arg = utils.get_argument_from_call(
13 node, position=0, keyword="mode"
14 )
15 except utils.NoSuchArgumentError:
16 pass
17
18 if mode_arg:
19 mode_arg = utils.safe_infer(mode_arg)
20
21 if (
22 func_name in OPEN_FILES_MODE
23 and isinstance(mode_arg, nodes.Const)
24 and not _check_mode_str(mode_arg.value)
25 ):
26 self.add_message(
27 "bad-open-mode",
28 node=node,
29 args=mode_arg.value or str(mode_arg.value),
30 )
31
32 if (
33 not mode_arg
34 or isinstance(mode_arg, nodes.Const)
35 and (not mode_arg.value or "b" not in str(mode_arg.value))
36 ):
37 encoding_arg = None
38 try:
39 if open_module == "pathlib":
40 if node.func.attrname == "read_text":
41 encoding_arg = utils.get_argument_from_call(
42 node, position=0, keyword="encoding"
43 )
44 elif node.func.attrname == "write_text":
45 encoding_arg = utils.get_argument_from_call(
46 node, position=1, keyword="encoding"
47 )
48 else:
49 encoding_arg = utils.get_argument_from_call(
50 node, position=2, keyword="encoding"
51 )
52 else:
53 encoding_arg = utils.get_argument_from_call(
54 node, position=3, keyword="encoding"
55 )
56 except utils.NoSuchArgumentError:
57 self.add_message("unspecified-encoding", node=node)
58
59 if encoding_arg:
60 encoding_arg = utils.safe_infer(encoding_arg)
61
62 if isinstance(encoding_arg, nodes.Const) and encoding_arg.value is None:
63 self.add_message("unspecified-encoding", node=node)