Skip to content

Commit

Permalink
refactor: Replace Union with pipe as py v3.10 introduced that syntact…
Browse files Browse the repository at this point in the history
…ic sugar - PR comment
  • Loading branch information
ronaldmaj committed Aug 20, 2024
1 parent f412f1b commit 35d49d6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
11 changes: 5 additions & 6 deletions gnssanalysis/gn_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import ftplib as _ftplib
from ftplib import FTP_TLS as _FTP_TLS
from pathlib import Path as _Path
from typing import Optional as _Optional, Union as _Union, Tuple as _Tuple, List as _List
from typing import Optional as _Optional, Tuple as _Tuple, List as _List
from urllib import request as _request
from urllib.error import HTTPError as _HTTPError

Expand Down Expand Up @@ -147,7 +147,7 @@ def request_metadata(url: str, max_retries: int = 5, metadata_header: str = "x-a
return None


def download_url(url: str, destfile: _Union[str, _os.PathLike], max_retries: int = 5) -> _Optional[_Path]:
def download_url(url: str, destfile: str | _os.PathLike, max_retries: int = 5) -> _Optional[_Path]:
logging.info(f'requesting "{url}"')
for retry in range(1, max_retries + 1):
try:
Expand Down Expand Up @@ -369,16 +369,14 @@ def generate_product_filename(
return product_filename, gps_date, reference_start


def check_whether_to_download(
filename: str, download_dir: _Path, if_file_present: str = "prompt_user"
) -> _Union[_Path, None]:
def check_whether_to_download(filename: str, download_dir: _Path, if_file_present: str = "prompt_user") -> _Path | None:
"""Determine whether to download given file (filename) to the desired location (download_dir) based on whether it is
already present and what action to take if it is (if_file_present)
:param str filename: Filename of the downloaded file
:param _Path download_dir: Where to download files (local directory)
:param str if_file_present: What to do if file already present: "replace", "dont_replace", defaults to "prompt_user"
:return _Union[_Path, None]: Path obj to the downloaded file if file should be downloaded, otherwise returns None
:return _Path | None: Path obj to the downloaded file if file should be downloaded, otherwise returns None
"""
# Flag to determine whether to download:
download = None
Expand Down Expand Up @@ -840,6 +838,7 @@ def download_atx(download_dir: _Path, reference_frame: str = "IGS20", if_file_pr
:param _Path download_dir: Where to download files (local directory)
:param str reference_frame: Coordinate reference frame file to download, defaults to "IGS20"
:param str if_file_present: What to do if file already present: "replace", "dont_replace", defaults to "prompt_user"
:raises ValueError: If an invalid option is given for reference_frame variable
:return _Path: The pathlib.Path of the downloaded file
"""
match reference_frame:
Expand Down
6 changes: 3 additions & 3 deletions gnssanalysis/gn_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import click as _click

from typing import List as _List, Union as _Union
from typing import List as _List


def diffutil_verify_input(input):
Expand Down Expand Up @@ -52,12 +52,12 @@ def get_filetype(path):
return suffix


def configure_logging(verbose: bool, output_logger: bool = False) -> _Union[_logging.Logger, None]:
def configure_logging(verbose: bool, output_logger: bool = False) -> _logging.Logger | None:
"""Configure the logger object with the level of verbosity requested and output if desired
:param bool verbose: Verbosity of logger object to use for encoding logging strings, True: DEBUG, False: INFO
:param bool output_logger: Flag to indicate whether to output the Logger object, defaults to False
:return _Union[_logging.Logger, None]: Return the logger object or None (based on output_logger)
:return _logging.Logger | None: Return the logger object or None (based on output_logger)
"""
if verbose:
logging_level = _logging.DEBUG
Expand Down

0 comments on commit 35d49d6

Please sign in to comment.