Skip to content

Commit e238765

Browse files
authored
More typing cleanup (#877)
1 parent c360e43 commit e238765

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

traitlets/config/application.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ def _log_default(self) -> AnyLogger:
400400
# this must be a dict of two-tuples,
401401
# the first element being the application class/import string
402402
# and the second being the help string for the subcommand
403-
subcommands = Dict()
403+
subcommands: dict[str, t.Any] | Dict = Dict()
404404
# parse_command_line will initialize a subapp, if requested
405405
subapp = Instance("traitlets.config.application.Application", allow_none=True)
406406

@@ -891,15 +891,15 @@ def parse_command_line(self, argv: ArgvType = None) -> None:
891891
def _load_config_files(
892892
cls,
893893
basefilename: str,
894-
path: list[str | None] | None = None,
894+
path: str | t.Sequence[str | None] | None,
895895
log: AnyLogger | None = None,
896896
raise_config_file_errors: bool = False,
897897
) -> t.Generator[t.Any, None, None]:
898898
"""Load config files (py,json) by filename and path.
899899
900900
yield each config object in turn.
901901
"""
902-
if not isinstance(path, list):
902+
if isinstance(path, str) or path is None:
903903
path = [path]
904904
for current in reversed(path):
905905
# path list is in descending priority order, so load files backwards:
@@ -949,7 +949,9 @@ def loaded_config_files(self) -> list[str]:
949949
return self._loaded_config_files[:]
950950

951951
@catch_config_error
952-
def load_config_file(self, filename: str, path: list[str | None] | None = None) -> None:
952+
def load_config_file(
953+
self, filename: str, path: str | t.Sequence[str | None] | None = None
954+
) -> None:
953955
"""Load config files by filename and path."""
954956
filename, ext = os.path.splitext(filename)
955957
new_config = Config()
@@ -1032,7 +1034,7 @@ def close_handlers(self) -> None:
10321034
handler.close()
10331035
self._logging_configured = False
10341036

1035-
def exit(self, exit_status: int = 0) -> None:
1037+
def exit(self, exit_status: int | str | None = 0) -> None:
10361038
self.log.debug("Exiting application: %s" % self.name)
10371039
self.close_handlers()
10381040
sys.exit(exit_status)

traitlets/tests/utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
import sys
44
from subprocess import PIPE, Popen
5-
from typing import Any
5+
from typing import Any, Sequence
66

77

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

1616

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

3030

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

0 commit comments

Comments
 (0)