77import textwrap
88import traceback
99import warnings
10- from typing import ClassVar
10+ from collections .abc import Callable
11+ from typing import Any , ClassVar
1112
1213import click
1314
2930log = logging .getLogger (__name__ )
3031
3132
32- def _showwarning (message , category , filename , lineno , file = None , line = None ):
33+ def _showwarning (
34+ message : Warning | str ,
35+ category : type [Warning ],
36+ filename : str ,
37+ lineno : int ,
38+ file : Any = None ,
39+ line : str | None = None ,
40+ ) -> None :
3341 try :
3442 # Last stack frames:
3543 # * ...
@@ -49,7 +57,7 @@ def _showwarning(message, category, filename, lineno, file=None, line=None):
4957 log .info (f'{ category .__name__ } : { message } \n { tb } ' )
5058
5159
52- def _enable_warnings ():
60+ def _enable_warnings () -> None :
5361 # When `python -W...` or `PYTHONWARNINGS` are used, `sys.warnoptions` is set.
5462 # In that case, we skip warnings configuration since
5563 # we don't want to overwrite the user configuration.
@@ -79,7 +87,7 @@ class ColorFormatter(logging.Formatter):
7987 subsequent_indent = ' ' * 11 ,
8088 )
8189
82- def format (self , record ) :
90+ def format (self , record : logging . LogRecord ) -> str :
8391 message = super ().format (record )
8492 prefix = f'{ record .levelname :<8} - '
8593 if record .levelname in self .colors :
@@ -95,7 +103,7 @@ def format(self, record):
95103class State :
96104 """Maintain logging level."""
97105
98- def __init__ (self ):
106+ def __init__ (self ) -> None :
99107 self .logger = logging .getLogger ('properdocs' )
100108 self .logger .setLevel (logging .INFO )
101109 self .logger .propagate = False
@@ -111,7 +119,7 @@ def __init__(self):
111119 self .stream .name = 'ProperDocsStreamHandler'
112120 self .logger .addHandler (self .stream )
113121
114- def __del__ (self ):
122+ def __del__ (self ) -> None :
115123 self .logger .removeHandler (self .stream )
116124
117125
@@ -158,17 +166,17 @@ def __del__(self):
158166)
159167
160168
161- def add_options (* opts ) :
162- def inner (f ) :
169+ def add_options (* opts : Callable [..., Any ]) -> Callable [..., Any ] :
170+ def inner (f : Callable [..., Any ]) -> Callable [..., Any ] :
163171 for i in reversed (opts ):
164172 f = i (f )
165173 return f
166174
167175 return inner
168176
169177
170- def verbose_option (f ) :
171- def callback (ctx , param , value ) :
178+ def verbose_option (f : Callable [..., Any ]) -> Callable [..., Any ] :
179+ def callback (ctx : click . Context , param : click . Parameter , value : Any ) -> None :
172180 state = ctx .ensure_object (State )
173181 if value :
174182 state .logger .setLevel (logging .DEBUG )
@@ -183,8 +191,8 @@ def callback(ctx, param, value):
183191 )(f )
184192
185193
186- def quiet_option (f ) :
187- def callback (ctx , param , value ) :
194+ def quiet_option (f : Callable [..., Any ]) -> Callable [..., Any ] :
195+ def callback (ctx : click . Context , param : click . Parameter , value : Any ) -> None :
188196 state = ctx .ensure_object (State )
189197 if value :
190198 state .logger .setLevel (logging .ERROR )
@@ -199,8 +207,8 @@ def callback(ctx, param, value):
199207 )(f )
200208
201209
202- def color_option (f ) :
203- def callback (ctx , param , value ) :
210+ def color_option (f : Callable [..., Any ]) -> Callable [..., Any ] :
211+ def callback (ctx : click . Context , param : click . Parameter , value : Any ) -> None :
204212 state = ctx .ensure_object (State )
205213 if value is False or (
206214 value is None
@@ -253,7 +261,7 @@ def callback(ctx, param, value):
253261)
254262@common_options
255263@color_option
256- def cli ():
264+ def cli () -> None :
257265 """ProperDocs - Project documentation with Markdown."""
258266
259267
@@ -271,7 +279,7 @@ def cli():
271279)
272280@common_config_options
273281@common_options
274- def serve_command (** kwargs ) :
282+ def serve_command (** kwargs : Any ) -> None :
275283 """Run the builtin development server."""
276284 from properdocs .commands import serve
277285
@@ -289,7 +297,7 @@ def serve_command(**kwargs):
289297@common_config_options
290298@click .option ('-d' , '--site-dir' , type = click .Path (), help = site_dir_help )
291299@common_options
292- def build_command (clean , ** kwargs ) :
300+ def build_command (clean : bool , ** kwargs : Any ) -> None :
293301 """Build the ProperDocs documentation."""
294302 from properdocs .commands import build
295303
@@ -315,8 +323,8 @@ def build_command(clean, **kwargs):
315323@click .option ('-d' , '--site-dir' , type = click .Path (), help = site_dir_help )
316324@common_options
317325def gh_deploy_command (
318- clean , message , remote_branch , remote_name , force , no_history , ignore_version , shell , ** kwargs
319- ):
326+ clean : bool , message : str | None , remote_branch : str | None , remote_name : str | None , force : bool , no_history : bool , ignore_version : bool , shell : bool , ** kwargs : Any
327+ ) -> None :
320328 """Deploy your documentation to GitHub Pages."""
321329 from properdocs .commands import build , gh_deploy
322330
@@ -347,7 +355,7 @@ def gh_deploy_command(
347355 help = projects_file_help ,
348356 show_default = True ,
349357)
350- def get_deps_command (config_file , projects_file ) :
358+ def get_deps_command (config_file : Any , projects_file : str | None ) -> None :
351359 """Show required PyPI packages inferred from plugins in properdocs.yml."""
352360 from properdocs .commands .get_deps import get_deps , get_projects_file
353361 from properdocs .config .base import _open_config_file
@@ -370,7 +378,7 @@ def get_deps_command(config_file, projects_file):
370378@cli .command (name = "new" )
371379@click .argument ("project_directory" )
372380@common_options
373- def new_command (project_directory ) :
381+ def new_command (project_directory : str ) -> None :
374382 """Create a new ProperDocs project."""
375383 from properdocs .commands import new
376384
0 commit comments