Skip to content

Commit

Permalink
Merge pull request #322 from vil02/add_type_hints_to_c_like_utils
Browse files Browse the repository at this point in the history
style: add some type hints to `c_like_utils` and `utils`
  • Loading branch information
vil02 authored Jul 18, 2024
2 parents 7c04289 + 21f37ac commit 45959fe
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
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 = "string-to-code"
version = "0.2.11"
version = "0.2.12"
description = "Generates a piece of messy code in a given language displaying a given string "
authors = ["piotr.idzik <[email protected]>"]
readme = "./string_to_code/README.md"
Expand Down
21 changes: 15 additions & 6 deletions string_to_code/c_like_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"""
utilities fror C-like languages
utilities for C-like languages
"""

import typing

from . import core
from . import utils

Expand All @@ -21,7 +23,10 @@ def escape_special_char(in_atom: core.Atom) -> str:
return special_chars.get(in_atom.atom_char, in_atom.atom_char)


def get_atom_to_code(in_printer_function_name, in_escape_special_char_fun):
def get_atom_to_code(
in_printer_function_name: str,
in_escape_special_char_fun: typing.Callable[[core.Atom], str],
) -> typing.Callable[[core.Atom], str]:
"""returns the atom_to_code type function"""

def _inner(in_atom: core.Atom) -> str:
Expand All @@ -36,15 +41,19 @@ def get_function_call_str_fun(get_function_name):
return utils.get_function_call_str_fun(get_function_name, "", "();")


def get_body_to_str(in_call_function_or_atom):
def get_body_to_str(
in_call_function_or_atom: typing.Callable[[core.CalledListEntry], str],
) -> typing.Callable[[core.SimpleFunction], str]:
"""returns body_to_str-like function for c-like languages"""
return utils.get_body_to_str("\n", " ", in_call_function_or_atom, "", "")


def get_merge_to_full_function(in_function_prefix):
def get_merge_to_full_function(
in_function_prefix: str,
) -> typing.Callable[[str, str], str]:
"""returns merge_to_full_function-like function for c-like languages"""

def _merge_to_full_function(in_function_name, in_function_body):
def _merge_to_full_function(in_function_name: str, in_function_body: str) -> str:
body_str = "\n" + in_function_body + "\n" if in_function_body else ""
return "\n".join(
[
Expand All @@ -59,7 +68,7 @@ def _merge_to_full_function(in_function_name, in_function_body):
def get_main_call_fun(in_call_function_or_atom):
"""returns function returning code of main C or C++ function"""

def _main_call(in_initial_call, **kwargs):
def _main_call(in_initial_call: str | None, **kwargs) -> str:
initial_call_str = (
" " + in_call_function_or_atom(in_initial_call, **kwargs) + "\n "
if in_initial_call is not None
Expand Down
8 changes: 5 additions & 3 deletions string_to_code/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ def get_all_proc_functions(main_call_to_code, function_to_code, join_to_final):
def get_body_to_str(
in_separator: str,
in_prefix: str,
in_call_function_or_atom,
in_call_function_or_atom: typing.Callable[[core.CalledListEntry], str],
in_postfix: str,
in_empty_result: str,
):
) -> typing.Callable[[core.SimpleFunction], str]:
"""returns body_to_str-like function"""

def _body_to_str(in_function: core.SimpleFunction) -> str:
Expand All @@ -100,7 +100,9 @@ def _body_to_str(in_function: core.SimpleFunction) -> str:


def get_function_to_code(
in_get_function_name, in_body_to_str, in_merge_to_full_function
in_get_function_name,
in_body_to_str: typing.Callable[[core.SimpleFunction], str],
in_merge_to_full_function: typing.Callable[[str, str], str],
):
"""return function_to_code-like function"""

Expand Down

0 comments on commit 45959fe

Please sign in to comment.