Skip to content

Commit 4d34edd

Browse files
authored
Merge pull request #786 from blink1073/cleanup-types
2 parents 8795302 + ea40cb6 commit 4d34edd

2 files changed

Lines changed: 25 additions & 19 deletions

File tree

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ check_untyped_defs = true
3636
disallow_any_generics = true
3737
disallow_incomplete_defs = true
3838
disallow_untyped_decorators = true
39+
explicit_package_bases = true
40+
namespace_packages = true
3941
no_implicit_optional = true
4042
no_implicit_reexport = true
4143
pretty = true

traitlets/config/application.py

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -146,21 +146,21 @@ class Application(SingletonConfigurable):
146146

147147
# The name of the application, will usually match the name of the command
148148
# line application
149-
name = Unicode("application")
149+
name: t.Union[str, Unicode] = Unicode("application")
150150

151151
# The description of the application that is printed at the beginning
152152
# of the help.
153-
description = Unicode("This is an application.")
153+
description: t.Union[str, Unicode] = Unicode("This is an application.")
154154
# default section descriptions
155-
option_description = Unicode(option_description)
156-
keyvalue_description = Unicode(keyvalue_description)
157-
subcommand_description = Unicode(subcommand_description)
155+
option_description: t.Union[str, Unicode] = Unicode(option_description)
156+
keyvalue_description: t.Union[str, Unicode] = Unicode(keyvalue_description)
157+
subcommand_description: t.Union[str, Unicode] = Unicode(subcommand_description)
158158

159159
python_config_loader_class = PyFileConfigLoader
160160
json_config_loader_class = JSONFileConfigLoader
161161

162162
# The usage and example string that goes at the end of the help string.
163-
examples = Unicode()
163+
examples: t.Union[str, Unicode] = Unicode()
164164

165165
# A sequence of Configurable subclasses whose config=True attributes will
166166
# be exposed at the command line.
@@ -187,28 +187,30 @@ def _classes_inc_parents(self, classes=None):
187187
yield parent
188188

189189
# The version string of this application.
190-
version = Unicode("0.0")
190+
version: t.Union[str, Unicode] = Unicode("0.0")
191191

192192
# the argv used to initialize the application
193-
argv = List()
193+
argv: t.Union[t.List[str], List] = List()
194194

195195
# Whether failing to load config files should prevent startup
196-
raise_config_file_errors = Bool(TRAITLETS_APPLICATION_RAISE_CONFIG_FILE_ERROR)
196+
raise_config_file_errors: t.Union[bool, Bool] = Bool(
197+
TRAITLETS_APPLICATION_RAISE_CONFIG_FILE_ERROR
198+
)
197199

198200
# The log level for the application
199-
log_level = Enum(
201+
log_level: t.Union[str, int, Enum] = Enum(
200202
(0, 10, 20, 30, 40, 50, "DEBUG", "INFO", "WARN", "ERROR", "CRITICAL"),
201203
default_value=logging.WARN,
202204
help="Set the log level by value or name.",
203205
).tag(config=True)
204206

205207
_log_formatter_cls = LevelFormatter
206208

207-
log_datefmt = Unicode(
209+
log_datefmt: t.Union[str, Unicode] = Unicode(
208210
"%Y-%m-%d %H:%M:%S", help="The date format used by logging formatters for %(asctime)s"
209211
).tag(config=True)
210212

211-
log_format = Unicode(
213+
log_format: t.Union[str, Unicode] = Unicode(
212214
"[%(name)s]%(highlevel)s %(message)s",
213215
help="The Logging format template",
214216
).tag(config=True)
@@ -351,7 +353,7 @@ def _log_default(self):
351353
#: the alias map for configurables
352354
#: Keys might strings or tuples for additional options; single-letter alias accessed like `-v`.
353355
#: Values might be like "Class.trait" strings of two-tuples: (Class.trait, help-text).
354-
aliases: t.Dict[str, str] = {"log-level": "Application.log_level"}
356+
aliases: t.Dict[str, t.Any] = {"log-level": "Application.log_level"}
355357

356358
# flags for loading Configurables or store_const style flags
357359
# flags are loaded from this dict by '--key' flags
@@ -389,12 +391,12 @@ def _log_default(self):
389391
# this must be a dict of two-tuples,
390392
# the first element being the application class/import string
391393
# and the second being the help string for the subcommand
392-
subcommands = Dict()
394+
subcommands: t.Union[t.Dict[str, t.Tuple[str, str]], Dict] = Dict()
393395
# parse_command_line will initialize a subapp, if requested
394396
subapp = Instance("traitlets.config.application.Application", allow_none=True)
395397

396398
# extra command-line arguments that don't set config values
397-
extra_args = List(Unicode())
399+
extra_args: t.Union[t.List[str], List] = List(Unicode())
398400

399401
cli_config = Instance(
400402
Config,
@@ -409,11 +411,11 @@ def _log_default(self):
409411

410412
_loaded_config_files = List()
411413

412-
show_config = Bool(
414+
show_config: t.Union[bool, Bool] = Bool(
413415
help="Instead of starting the Application, dump configuration to stdout"
414416
).tag(config=True)
415417

416-
show_config_json = Bool(
418+
show_config_json: t.Union[bool, Bool] = Bool(
417419
help="Instead of starting the Application, dump configuration to stdout (as JSON)"
418420
).tag(config=True)
419421

@@ -690,7 +692,9 @@ def print_version(self):
690692
@catch_config_error
691693
def initialize_subcommand(self, subc, argv=None):
692694
"""Initialize a subcommand with argv."""
693-
subapp, _ = self.subcommands.get(subc)
695+
val = self.subcommands.get(subc)
696+
assert val is not None
697+
subapp, _ = val
694698

695699
if isinstance(subapp, str):
696700
subapp = import_item(subapp)
@@ -737,7 +741,7 @@ def flatten_flags(self):
737741
for alias, longname in self.aliases.items():
738742
if isinstance(longname, tuple):
739743
longname, _ = longname
740-
cls, trait = longname.split(".", 1) # type:ignore[assignment]
744+
cls, trait = longname.split(".", 1)
741745
children = mro_tree[cls] # type:ignore[index]
742746
if len(children) == 1:
743747
# exactly one descendent, promote alias

0 commit comments

Comments
 (0)