diff --git a/traitlets/config/application.py b/traitlets/config/application.py index b0cf36f7..5993b4c7 100644 --- a/traitlets/config/application.py +++ b/traitlets/config/application.py @@ -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) @@ -891,7 +891,7 @@ 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]: @@ -899,7 +899,7 @@ def _load_config_files( 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: @@ -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() @@ -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) diff --git a/traitlets/tests/utils.py b/traitlets/tests/utils.py index b4d0fe95..55829078 100644 --- a/traitlets/tests/utils.py +++ b/traitlets/tests/utils.py @@ -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() @@ -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: @@ -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: