Skip to content

Commit

Permalink
Merge pull request #153 from vil02/simplify_list_typehints
Browse files Browse the repository at this point in the history
style: use `list` in type hints
  • Loading branch information
vil02 authored Nov 30, 2024
2 parents 2ace3ee + 204055c commit b1fe832
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 23 deletions.
4 changes: 1 addition & 3 deletions puzzle_generator/configurators/simple/simple.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import typing

from ...encryption_algorithms.simple import simple as se
from . import common as csc
from ..check_kwargs import check_kwargs
Expand All @@ -11,7 +9,7 @@ def __init__(self, **kwargs):
self._scrypt_params = csc.scrypt_params(**kwargs)
self._signature_params = csc.signature_params(**kwargs)

def get_modules(self) -> typing.List[str]:
def get_modules(self) -> list[str]:
return csc.MODULES

def get_encrypt(self):
Expand Down
7 changes: 3 additions & 4 deletions puzzle_generator/configurators/simple/spiced.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import secrets
import typing

from ... import bytestr_utils as bu
from ...encryption_algorithms.simple import spiced as sse
Expand All @@ -11,11 +10,11 @@ def _get_some_spices():
return [secrets.token_bytes(3) for _ in range(20)]


def _list_of_bytes_to_str(in_list: typing.List[bytes]) -> str:
def _list_of_bytes_to_str(in_list: list[bytes]) -> str:
return str([bu.bytes_to_bytestr(_) for _ in in_list])


def _list_of_bytes_to_codestr(in_list: typing.List[bytes]) -> str:
def _list_of_bytes_to_codestr(in_list: list[bytes]) -> str:
raw: str = _list_of_bytes_to_str(in_list)
return f"[bytestr_to_bytes(_) for _ in {raw}]"

Expand All @@ -31,7 +30,7 @@ def __init__(self, **kwargs):
self._proc_spices = kwargs.get("proc_spices", _get_some_spices())
self._signature_spices = kwargs.get("signature_spices", _get_some_spices())

def get_modules(self) -> typing.List[str]:
def get_modules(self) -> list[str]:
return csc.MODULES

def get_encrypt(self):
Expand Down
3 changes: 1 addition & 2 deletions puzzle_generator/create_puzzle.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import inspect
import typing
import textwrap
import importlib.metadata

Expand Down Expand Up @@ -61,7 +60,7 @@ def _create_str(in_encrypted_puzzle, configurator) -> str:
)


def create(qa_list: typing.List[str], **kwargs) -> str:
def create(qa_list: list[str], **kwargs) -> str:
puzzle = question_answer_list_to_dict(qa_list)
configurator = configurators.get_configurator(**kwargs)
encrypted_puzzle = encrypt_data(puzzle, configurator.get_encrypt())
Expand Down
10 changes: 5 additions & 5 deletions puzzle_generator/encryption_algorithms/simple/spiced.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
)


def must_be_nonempty(in_list: typing.List[bytes]) -> None:
def must_be_nonempty(in_list: list[bytes]) -> None:
if not in_list:
raise ValueError("in_list must be nonempty")


def get_encrypt(
proc_spices: typing.List[bytes],
signature_spices: typing.List[bytes],
proc_spices: list[bytes],
signature_spices: list[bytes],
scrypt_params,
signature_params,
) -> typing.Callable[[bytes, bytes], bytes]:
Expand All @@ -39,8 +39,8 @@ def _encrypt(in_bytes: bytes, in_pass: bytes) -> bytes:


def get_decrypt(
proc_spices: typing.List[bytes],
signature_spices: typing.List[bytes],
proc_spices: list[bytes],
signature_spices: list[bytes],
scrypt_params,
signature_params,
) -> typing.Callable[[bytes, bytes], bytes | None]:
Expand Down
5 changes: 1 addition & 4 deletions puzzle_generator/puzzle_data_creators.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import typing


def question_answer_list_to_dict(qa_list: typing.List[str]):
def question_answer_list_to_dict(qa_list: list[str]):
if len(qa_list) % 2 == 0:
raise ValueError("The question/answer list must have odd length.")
if len(qa_list) == 1:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "puzzle-generator"
version = "0.14.2"
version = "0.14.3"
description = "Generates python code representing a puzzle"
authors = ["piotr.idzik <[email protected]>"]
readme = "./puzzle_generator/README.md"
Expand Down
8 changes: 4 additions & 4 deletions tests/test_create_puzzle.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
)


def _get_input(qa_list: typing.List[str]) -> typing.List[str]:
def _get_input(qa_list: list[str]) -> list[str]:
return [_ for num, _ in enumerate(qa_list) if num % 2 == 1]


def _get_positive_output(qa_list: typing.List[str]) -> str:
def _get_positive_output(qa_list: list[str]) -> str:
return "\n".join(_ for num, _ in enumerate(qa_list) if num % 2 == 0) + "\n"


def _positive_puzzle_tc(qa_list: typing.List[str]) -> _PuzzleTestCase:
def _positive_puzzle_tc(qa_list: list[str]) -> _PuzzleTestCase:
return _PuzzleTestCase(
qa_list=qa_list, input=_get_input(qa_list), output=_get_positive_output(qa_list)
)
Expand Down Expand Up @@ -175,7 +175,7 @@ def test_wrong_answers(
assert not res.stderr


def _get_input_simulator(answers: typing.List[str]) -> typing.Callable[[], str]:
def _get_input_simulator(answers: list[str]) -> typing.Callable[[], str]:
cur_input = 0

def _input_simulator() -> str:
Expand Down

0 comments on commit b1fe832

Please sign in to comment.