Skip to content

Commit

Permalink
Use Optional and Union for python 3.9 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
ashariyar committed Dec 13, 2024
1 parent 30ce541 commit 7fccfc9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
6 changes: 3 additions & 3 deletions pdfalyzer/helpers/filesystem_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
import re
from pathlib import Path
from typing import Union
from typing import Optional, Union

from yaralyzer.output.rich_console import console

Expand Down Expand Up @@ -45,7 +45,7 @@ def do_all_files_exist(file_paths: list[Union[str, Path]]) -> bool:
return all_files_exist


def extract_page_number(file_path: Union[str, Path]) -> int|None:
def extract_page_number(file_path: Union[str, Path]) -> Optional[int]:
"""Extract the page number from the end of a filename if it exists."""
match = NUMBERED_PAGE_REGEX.match(str(file_path))
return int(match.group(1)) if match else None
Expand All @@ -56,7 +56,7 @@ def file_size_in_mb(file_path: Union[str, Path], decimal_places: int = 2) -> flo
return round(Path(file_path).stat().st_size / 1024.0 / 1024.0, decimal_places)


def set_max_open_files(num_filehandles: int = DEFAULT_MAX_OPEN_FILES) -> tuple[int | None, int | None]:
def set_max_open_files(num_filehandles: int = DEFAULT_MAX_OPEN_FILES) -> tuple[Optional[int], Optional[int]]:
"""
Sets the OS level max open files to at least 'num_filehandles'. Current value can be seen with 'ulimit -a'.
Required when you might be opening more than DEFAULT_MAX_OPEN_FILES file handles simultaneously
Expand Down
5 changes: 2 additions & 3 deletions pdfalyzer/helpers/rich_text_helper.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
"""
Functions for miscellaneous Rich text/string operations.
"""
from functools import partial
from typing import List
from typing import List, Union

from pypdf.generic import PdfObject
from rich.console import Console
Expand All @@ -17,7 +16,7 @@
pdfalyzer_console = Console(color_system='256')


def print_highlighted(msg: str|Text, **kwargs) -> None:
def print_highlighted(msg: Union[str, Text], **kwargs) -> None:
"""Print 'msg' with Rich highlighting."""
pdfalyzer_console.print(msg, highlight=True, **kwargs)

Expand Down
4 changes: 2 additions & 2 deletions pdfalyzer/util/argument_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from functools import partial, update_wrapper
from importlib.metadata import version
from os import getcwd, path
from typing import List
from typing import List, Optional

from rich_argparse_plus import RichHelpFormatterPlus
from rich.prompt import Confirm
Expand Down Expand Up @@ -254,7 +254,7 @@ def ask_to_proceed() -> None:
exit_with_error()


def exit_with_error(error_message: str|None = None) -> None:
def exit_with_error(error_message: Optional[str] = None) -> None:
"""Print 'error_message' and exit with status code 1."""
if error_message:
print_highlighted(Text('').append('ERROR', style='bold red').append(f': {error_message}'))
Expand Down

0 comments on commit 7fccfc9

Please sign in to comment.