Skip to content

Commit

Permalink
fix: typing
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey committed Aug 8, 2024
1 parent 3cc1a0f commit 1b798cd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
13 changes: 7 additions & 6 deletions src/ape/cli/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def abort(msg: str, base_error: Optional[Exception] = None) -> NoReturn:


def verbosity_option(
cli_logger: Optional[ApeLogger] = None, default: str = DEFAULT_LOG_LEVEL
cli_logger: Optional[ApeLogger] = None, default: Union[str, LogLevel] = DEFAULT_LOG_LEVEL
) -> Callable:
"""A decorator that adds a `--verbosity, -v` option to the decorated
command.
Expand All @@ -67,12 +67,12 @@ def verbosity_option(


def _create_verbosity_kwargs(
_logger: Optional[ApeLogger] = None, default: str = DEFAULT_LOG_LEVEL
_logger: Optional[ApeLogger] = None, default: Union[str, LogLevel] = DEFAULT_LOG_LEVEL
) -> dict:
cli_logger = _logger or logger

def set_level(ctx, param, value):
cli_logger._load_from_sys_argv(default=value.upper())
cli_logger._load_from_sys_argv(default=value.upper() if isinstance(value, str) else value)

level_names = [lvl.name for lvl in LogLevel]
names_str = f"{', '.join(level_names[:-1])}, or {level_names[-1]}"
Expand All @@ -87,16 +87,17 @@ def set_level(ctx, param, value):


def ape_cli_context(
default_log_level: str = DEFAULT_LOG_LEVEL, obj_type: type = ApeCliContextObject
default_log_level: Union[str, LogLevel] = DEFAULT_LOG_LEVEL,
obj_type: type = ApeCliContextObject,
) -> Callable:
"""
A ``click`` context object with helpful utilities.
Use in your commands to get access to common utility features,
such as logging or accessing managers.
Args:
default_log_level (str): The log-level value to pass to
:meth:`~ape.cli.options.verbosity_option`.
default_log_level (Union[str, :class:`~ape.logging.LogLevel`]): The log-level
value to pass to :meth:`~ape.cli.options.verbosity_option`.
obj_type (Type): The context object type. Defaults to
:class:`~ape.cli.options.ApeCliContextObject`. Sub-class
the context to extend its functionality in your CLIs,
Expand Down
2 changes: 1 addition & 1 deletion src/ape/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def format(self, fmt: Optional[str] = None):
fmt = fmt or DEFAULT_LOG_FORMAT
_format_logger(self._logger, fmt)

def _load_from_sys_argv(self, default: Optional[Union[str, int]] = None):
def _load_from_sys_argv(self, default: Optional[Union[str, int, LogLevel]] = None):
"""
Load from sys.argv to beat race condition with `click`.
"""
Expand Down

0 comments on commit 1b798cd

Please sign in to comment.