Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More typing cleanup #877

Merged
merged 2 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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