Skip to content

Commit

Permalink
More typing cleanup (#877)
Browse files Browse the repository at this point in the history
  • Loading branch information
blink1073 committed Oct 3, 2023
1 parent c360e43 commit e238765
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
12 changes: 7 additions & 5 deletions traitlets/config/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ def _log_default(self) -> AnyLogger:
# this must be a dict of two-tuples,
# the first element being the application class/import string
# and the second being the help string for the subcommand
subcommands = Dict()
subcommands: dict[str, t.Any] | Dict = Dict()
# parse_command_line will initialize a subapp, if requested
subapp = Instance("traitlets.config.application.Application", allow_none=True)

Expand Down Expand Up @@ -891,15 +891,15 @@ def parse_command_line(self, argv: ArgvType = None) -> None:
def _load_config_files(
cls,
basefilename: str,
path: list[str | None] | None = None,
path: str | t.Sequence[str | None] | None,
log: AnyLogger | None = None,
raise_config_file_errors: bool = False,
) -> t.Generator[t.Any, None, None]:
"""Load config files (py,json) by filename and path.
yield each config object in turn.
"""
if not isinstance(path, list):
if isinstance(path, str) or path is None:
path = [path]
for current in reversed(path):
# path list is in descending priority order, so load files backwards:
Expand Down Expand Up @@ -949,7 +949,9 @@ def loaded_config_files(self) -> list[str]:
return self._loaded_config_files[:]

@catch_config_error
def load_config_file(self, filename: str, path: list[str | None] | None = None) -> None:
def load_config_file(
self, filename: str, path: str | t.Sequence[str | None] | None = None
) -> None:
"""Load config files by filename and path."""
filename, ext = os.path.splitext(filename)
new_config = Config()
Expand Down Expand Up @@ -1032,7 +1034,7 @@ def close_handlers(self) -> None:
handler.close()
self._logging_configured = False

def exit(self, exit_status: int = 0) -> None:
def exit(self, exit_status: int | str | None = 0) -> None:
self.log.debug("Exiting application: %s" % self.name)
self.close_handlers()
sys.exit(exit_status)
Expand Down
8 changes: 4 additions & 4 deletions traitlets/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import sys
from subprocess import PIPE, Popen
from typing import Any
from typing import Any, Sequence


def get_output_error_code(cmd: str | list[str]) -> tuple[str, str, Any]:
def get_output_error_code(cmd: str | Sequence[str]) -> tuple[str, str, Any]:
"""Get stdout, stderr, and exit code from running a command"""
p = Popen(cmd, stdout=PIPE, stderr=PIPE) # noqa
out, err = p.communicate()
Expand All @@ -14,7 +14,7 @@ def get_output_error_code(cmd: str | list[str]) -> tuple[str, str, Any]:
return out_str, err_str, p.returncode


def check_help_output(pkg: str, subcommand: list[str] | None = None) -> tuple[str, str]:
def check_help_output(pkg: str, subcommand: Sequence[str] | None = None) -> tuple[str, str]:
"""test that `python -m PKG [subcommand] -h` works"""
cmd = [sys.executable, "-m", pkg]
if subcommand:
Expand All @@ -28,7 +28,7 @@ def check_help_output(pkg: str, subcommand: list[str] | None = None) -> tuple[st
return out, err


def check_help_all_output(pkg: str, subcommand: list[str] | None = None) -> tuple[str, str]:
def check_help_all_output(pkg: str, subcommand: Sequence[str] | None = None) -> tuple[str, str]:
"""test that `python -m PKG --help-all` works"""
cmd = [sys.executable, "-m", pkg]
if subcommand:
Expand Down

0 comments on commit e238765

Please sign in to comment.