Skip to content

Commit e063e8d

Browse files
committed
chore: configure bandit
1 parent 3a6e7c6 commit e063e8d

File tree

13 files changed

+34
-25
lines changed

13 files changed

+34
-25
lines changed

bandit.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
assert_used:
3+
skips: ['**/test_*.py', './tests/*.py']
4+
...

check_all_python_scripts.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22

33
set -euo pipefail
44

5+
poetry run bandit -c bandit.yml -r .
6+
57
find . -name "*.py" -not -path "./tests/example_data/python3/*" -exec ./check_python_file.sh {} +

examples/example_general.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
EXAMPLE_STR = "Hello, World!"
99
TARGET_LANGUAGE = "ada"
1010

11-
assert TARGET_LANGUAGE in string_to_code.get_target_languages()
11+
assert TARGET_LANGUAGE in string_to_code.get_target_languages() # nosec B101
1212

1313
CODE = string_to_code.proc(TARGET_LANGUAGE, EXAMPLE_STR)
1414

examples/setup_examples.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
import sys
55

66
_PROJ_PATH_STR = str(pathlib.Path(__file__).parents[1])
7-
assert str(_PROJ_PATH_STR).endswith("string_to_code_proj")
7+
assert str(_PROJ_PATH_STR).endswith("string_to_code_proj") # nosec B101
88
sys.path.insert(0, _PROJ_PATH_STR)

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ ruff = "0.8.4"
2525
coverage = "7.6.10"
2626
black = "24.10.0"
2727
mypy = "1.14.0"
28+
bandit = "1.8.0"
2829

2930
[build-system]
3031
requires = ["poetry-core"]

string_to_code/core.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ class SimpleFunction(typing.NamedTuple):
3333

3434
def str_pieces(in_str: str, in_pieces_len: list[int]) -> Strings:
3535
"""returns in_str split into pieces of lengths as in in_pieces_len"""
36-
assert all(_ > 0 for _ in in_pieces_len)
37-
assert sum(in_pieces_len) == len(in_str)
36+
assert all(_ > 0 for _ in in_pieces_len) # nosec B101
37+
assert sum(in_pieces_len) == len(in_str) # nosec B101
3838
cur_str = in_str
3939
res = []
4040
for _ in in_pieces_len:
4141
res.append(cur_str[:_])
4242
cur_str = cur_str[_:]
43-
assert "".join(res) == in_str
43+
assert "".join(res) == in_str # nosec B101
4444
return res
4545

4646

@@ -49,11 +49,11 @@ def random_pieces_len(in_total_len: int) -> list[int]:
4949
cur_num = in_total_len
5050
res = []
5151
while cur_num > 0:
52-
tmp_len = random.randint(1, max(cur_num, 1))
52+
tmp_len = random.randint(1, max(cur_num, 1)) # nosec B311
5353
res.append(tmp_len)
5454
cur_num -= tmp_len
5555
random.shuffle(res)
56-
assert sum(res) == in_total_len
56+
assert sum(res) == in_total_len # nosec B101
5757
return res
5858

5959

@@ -63,7 +63,7 @@ def random_split(in_str: str) -> Strings:
6363

6464

6565
def _interesting_random_split(in_str: str) -> Strings:
66-
assert len(in_str) > 1
66+
assert len(in_str) > 1 # nosec B101
6767
res = random_split(in_str)
6868
while len(res) == 1:
6969
res = random_split(in_str)
@@ -114,12 +114,14 @@ def __init__(self, initial_call: InitialCall, needed_functions: SimpleFunctions)
114114

115115
def _check_data(self) -> None:
116116
if self.initial_call is not None and not isinstance(self.initial_call, Atom):
117-
assert self.needed_functions
117+
assert self.needed_functions # nosec B101
118118
if self.needed_functions:
119-
assert isinstance(self.initial_call, int)
120-
assert self.initial_call + 1 == len(self.needed_functions)
119+
assert isinstance(self.initial_call, int) # nosec B101
120+
assert self.initial_call + 1 == len(self.needed_functions) # nosec B101
121121
for fun_id, fun in enumerate(self.needed_functions):
122-
assert all(_ < fun_id for _ in fun.called_list if not isinstance(_, Atom))
122+
assert all(
123+
_ < fun_id for _ in fun.called_list if not isinstance(_, Atom)
124+
) # nosec B101
123125

124126
def needed_function_definitions_str_list(
125127
self, in_function_to_str, **kwargs

string_to_code/string_to_code.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111
def _remove_prefix(in_str: str, in_prefix: str) -> str:
12-
assert in_str.startswith(in_prefix)
12+
assert in_str.startswith(in_prefix) # nosec B101
1313
return in_str[len(in_prefix) :]
1414

1515

string_to_code/to_ada.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def _join_to_final(main_call: str, function_definitions: list[str], **kwargs) ->
7979
]
8080
)
8181
if function_definitions or main_call != _MAIN_NULL_CALL:
82-
assert "Ada.Text_IO." in res
82+
assert "Ada.Text_IO." in res # nosec B101
8383
res = "with Ada.Text_IO;\n\n" + res
8484
return res
8585

string_to_code/to_algol68.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def atom_to_code(in_atom: core.Atom) -> str:
3232
def _merge_to_full_function(in_function_name: str, in_function_body: str) -> str:
3333
body_str = ""
3434
if in_function_body:
35-
assert in_function_body[-1] == ";"
35+
assert in_function_body[-1] == ";" # nosec B101
3636
body_str = "\n" + in_function_body[:-1] + "\n"
3737
return f"PROC {in_function_name} = VOID :({body_str});\n"
3838

@@ -46,12 +46,12 @@ def _main_call_to_code(in_initial_call: core.InitialCall, **kwargs) -> str:
4646
if in_initial_call is None:
4747
return 'print("")'
4848
res = _call_function_or_atom(in_initial_call, **kwargs)
49-
assert res[-1] == ";"
49+
assert res[-1] == ";" # nosec B101
5050
return res[:-1]
5151

5252

5353
def _join_to_final(main_call: str, function_definitions: list[str], **_kwargs) -> str:
54-
assert main_call[-1] != "\n"
54+
assert main_call[-1] != "\n" # nosec B101
5555
return "\n\n".join(function_definitions + [main_call + "\n"])
5656

5757

string_to_code/to_haskell.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ def _join_to_final(main_call, function_definitions, **_kwargs):
5959

6060
import_list = ["IO", "putStr"]
6161
if function_definitions:
62-
assert "String" in res
62+
assert "String" in res # nosec B101
6363
import_list.append("String")
64-
assert "++" in res
64+
assert "++" in res # nosec B101
6565
import_list.append("(++)")
6666
res = f'import Prelude ({", ".join(import_list)})\n' + res
6767

0 commit comments

Comments
 (0)