Cmd / Cmds: Update legacy type annotation

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2026-01-20 18:56:12 +01:00
commit 9b5cd1b857
2 changed files with 4 additions and 6 deletions

View file

@ -1,7 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import annotations from __future__ import annotations
from typing import Optional, List, Type, Union, TypeVar
import inspect, sys, re, abc, argparse import inspect, sys, re, abc, argparse
from argparse import ArgumentParser, _SubParsersAction from argparse import ArgumentParser, _SubParsersAction
@ -21,9 +20,9 @@ class Cmd(abc.ABC): # export
self.name = name self.name = name
self.help = help self.help = help
self.parent = None self.parent = None
self.children: List[Cmd] = [] self.children: list[Cmd] = []
self.child_classes: List[Type[Cmd]] = [] self.child_classes: list[type[Cmd]] = []
self.app: Optional[Cmds] = None self.app: Cmds|None = None
async def _run(self, args): async def _run(self, args):
pass pass
@ -34,7 +33,7 @@ class Cmd(abc.ABC): # export
r.set_defaults(func=self.run) r.set_defaults(func=self.run)
return r return r
def add_subcommands(self, cmd: Union[str, Type[Cmd], List[Type[Cmd]]]) -> None: def add_subcommands(self, cmd: str|type[Cmd]|list[type[Cmd]]) -> None:
if isinstance(cmd, str): if isinstance(cmd, str):
sc = [] sc = []
for name, obj in inspect.getmembers(sys.modules[self.__class__.__module__]): for name, obj in inspect.getmembers(sys.modules[self.__class__.__module__]):

View file

@ -1,6 +1,5 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from typing import Optional
import os, sys, argcomplete, argparse, importlib, inspect, re, pickle, asyncio, cProfile import os, sys, argcomplete, argparse, importlib, inspect, re, pickle, asyncio, cProfile
from argparse import ArgumentParser from argparse import ArgumentParser
from pathlib import Path, PurePath from pathlib import Path, PurePath