From 0308f4425ce1a16449560bac1e51cab076b4c831 Mon Sep 17 00:00:00 2001 From: wayu15244 Date: Wed, 7 Oct 2026 04:29:45 +0700 Subject: [PATCH] Make Dict inherit from Generic[K, V] to fix get_type_hints (#904) --- tests/config/test_application.py | 8 ++++++++ traitlets/traitlets.py | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/config/test_application.py b/tests/config/test_application.py index fc0ec291..bbac2743 100644 --- a/tests/config/test_application.py +++ b/tests/config/test_application.py @@ -986,6 +986,14 @@ def test_get_logger_after_application(): assert traitlets.log.get_logger() is fallback +def test_application_get_type_hints(): + import typing + + hints = typing.get_type_hints(Application) + assert "subcommands" in hints + assert "argv" in hints + + if __name__ == "__main__": # for test_help_output: MyApp.launch_instance() diff --git a/traitlets/traitlets.py b/traitlets/traitlets.py index 2cc239c1..26831773 100644 --- a/traitlets/traitlets.py +++ b/traitlets/traitlets.py @@ -3880,7 +3880,7 @@ def subclass_init(self, cls: type[t.Any]) -> None: # to opt out of instance_init -class Dict(Instance["dict[K, V]"]): +class Dict(Instance["dict[K, V]"], t.Generic[K, V]): """An instance of a Python dict. One or more traits can be passed to the constructor