76
76
from django .core .management import get_commands
77
77
from django .core .management .base import BaseCommand , CommandError
78
78
from django .core .management .base import OutputWrapper as BaseOutputWrapper
79
+ from django .core .management .color import Style as ColorStyle
79
80
from django .db .models import Model
80
81
from django .utils .translation import gettext as _
81
82
94
95
95
96
from .completers import ModelObjectCompleter
96
97
from .parsers import ModelObjectParser
97
- from .types import ForceColor , NoColor , PythonPath , Settings , SkipChecks
98
- from .types import Style as ColorStyle
99
- from .types import Traceback , Verbosity , Version
98
+ from .types import (
99
+ ForceColor ,
100
+ NoColor ,
101
+ PythonPath ,
102
+ Settings ,
103
+ SkipChecks ,
104
+ Traceback ,
105
+ Verbosity ,
106
+ Version ,
107
+ )
100
108
from .utils import _command_context , traceback_config , with_typehint
101
109
102
110
VERSION = (1 , 0 , 1 )
@@ -1671,19 +1679,20 @@ def command2(self, option: t.Optional[str] = None):
1671
1679
style : ColorStyle
1672
1680
stdout : BaseOutputWrapper
1673
1681
stderr : BaseOutputWrapper
1674
- requires_system_checks : t .Union [t .Sequence [str ], str ]
1682
+ # requires_system_checks: t.Union[t.List [str], t.Tuple[ str, ...], t.Literal['__all__'] ]
1675
1683
1676
1684
# we do not use verbosity because the base command does not do anything with it
1677
1685
# if users want to use a verbosity flag like the base django command adds
1678
1686
# they can use the type from django_typer.types.Verbosity
1679
- suppressed_base_arguments : t . Optional [ t . Iterable [ str ]] = {"verbosity" }
1687
+ suppressed_base_arguments = {"verbosity" }
1680
1688
1681
1689
typer_app : Typer
1682
1690
no_color : bool = False
1683
1691
force_color : bool = False
1684
1692
_num_commands : int = 0
1685
1693
_has_callback : bool = False
1686
1694
_root_groups : int = 0
1695
+ _handle : t .Callable [..., t .Any ]
1687
1696
1688
1697
command_tree : CommandNode
1689
1698
@@ -1701,8 +1710,8 @@ def __exit__(self, exc_type, exc_val, exc_tb):
1701
1710
1702
1711
def __init__ (
1703
1712
self ,
1704
- stdout : t .Optional [t .IO [ str ] ] = None ,
1705
- stderr : t .Optional [t .IO [ str ] ] = None ,
1713
+ stdout : t .Optional [t .TextIO ] = None ,
1714
+ stderr : t .Optional [t .TextIO ] = None ,
1706
1715
no_color : bool = no_color ,
1707
1716
force_color : bool = force_color ,
1708
1717
** kwargs ,
@@ -1795,7 +1804,9 @@ def __init_subclass__(cls, **_):
1795
1804
"""Avoid passing typer arguments up the subclass init chain"""
1796
1805
return super ().__init_subclass__ ()
1797
1806
1798
- def create_parser (self , prog_name : str , subcommand : str , ** _ ):
1807
+ def create_parser ( # pyright: ignore[reportIncompatibleMethodOverride]
1808
+ self , prog_name : str , subcommand : str , ** _
1809
+ ):
1799
1810
"""
1800
1811
Create a parser for this command. This also sets the command
1801
1812
context, so any functions below this call on the stack may
@@ -1862,7 +1873,7 @@ def handle(self, option1: bool, option2: bool):
1862
1873
:param kwargs: the options to directly pass to handle()
1863
1874
"""
1864
1875
with self :
1865
- if getattr (self , "_handle" , None ):
1876
+ if getattr (self , "_handle" , None ) and callable ( self . _handle ) :
1866
1877
return self ._handle (* args , ** kwargs )
1867
1878
raise NotImplementedError (
1868
1879
_ (
0 commit comments