Skip to content

Commit

Permalink
Fix: Don't use newer Python type feature
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuatz committed Sep 15, 2024
1 parent fb29cbf commit ce8f2ac
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions django_utils_lib/logger.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import logging
from os import get_terminal_size
from typing import List
from typing import List, Union

from django_utils_lib.constants import PACKAGE_NAME

pkg_logger = logging.getLogger(PACKAGE_NAME)
pkg_logger.setLevel(logging.INFO)


def build_heading_block(heading: str | List[str], border_width=2) -> str:
def build_heading_block(heading: Union[str, List[str]], border_width=2) -> str:
"""
Generate a heading, like:
```
Expand All @@ -26,15 +26,9 @@ def build_heading_block(heading: str | List[str], border_width=2) -> str:
border_width_total = border_width + 1

for line in heading if isinstance(heading, list) else heading.splitlines():
left_inner_padding = int(
(terminal_width - len(line) - (border_width_total * 2)) / 2
)
right_inner_padding = int(
terminal_width - left_inner_padding - len(line) - (border_width_total * 2)
)
heading_lines.append(
f"{border} {' ' * left_inner_padding}{line}{' ' * right_inner_padding} {border}"
)
left_inner_padding = int((terminal_width - len(line) - (border_width_total * 2)) / 2)
right_inner_padding = int(terminal_width - left_inner_padding - len(line) - (border_width_total * 2))
heading_lines.append(f"{border} {' ' * left_inner_padding}{line}{' ' * right_inner_padding} {border}")
heading_lines.append(heading_delim)

return "\n".join(heading_lines)

0 comments on commit ce8f2ac

Please sign in to comment.