Skip to content

Commit b7b20d0

Browse files
Merge pull request #2031 from VWS-Python/enable-S311
Enable S311 checks and resolve errors
2 parents e0f3729 + 0e0d846 commit b7b20d0

File tree

3 files changed

+6
-8
lines changed

3 files changed

+6
-8
lines changed

pyproject.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,6 @@ ignore = [
224224
# narrowing - see
225225
# https://mypy.readthedocs.io/en/stable/type_narrowing.html#type-narrowing-expressions.
226226
"S101",
227-
# Allow `random` as we are not implementing something which needs cryptographic safety.
228-
"S311",
229227
]
230228

231229
# Do not automatically remove commented out code.

src/mock_vws/target_raters.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import functools
44
import io
55
import math
6-
import random
6+
import secrets
77
from typing import Protocol, runtime_checkable
88

99
import piq # type: ignore[import-untyped]
@@ -62,7 +62,7 @@ def __call__(self, image_content: bytes) -> int:
6262
image_content: A target's image's content.
6363
"""
6464
assert image_content
65-
return random.randint(0, 5)
65+
return secrets.randbelow(exclusive_upper_bound=6)
6666

6767

6868
class HardcodedTargetTrackingRater:

tests/mock_vws/utils/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"""
44

55
import io
6-
import random
6+
import secrets
77
from typing import Literal
88

99
import requests
@@ -89,9 +89,9 @@ def make_image_file(
8989
image = Image.new(color_space, (width, height))
9090
for row_index in range(height):
9191
for column_index in range(width):
92-
red = random.choice(seq=range(255))
93-
green = random.choice(seq=range(255))
94-
blue = random.choice(seq=range(255))
92+
red = secrets.choice(seq=range(255))
93+
green = secrets.choice(seq=range(255))
94+
blue = secrets.choice(seq=range(255))
9595
image.putpixel(
9696
xy=(column_index, row_index),
9797
value=(red, green, blue),

0 commit comments

Comments
 (0)