1616#-----------------------------------------------------------------------------
1717# Imports
1818#-----------------------------------------------------------------------------
19- from collections .abc import Sequence
19+ from __future__ import annotations
20+
21+ from collections .abc import Callable , Sequence
22+ from typing import Any , TypeVar
2023
2124from IPython .utils .docs import GENERATING_DOCUMENTATION
2225
26+ F = TypeVar ("F" , bound = Callable [..., Any ])
2327
2428#-----------------------------------------------------------------------------
2529# Code
2630#-----------------------------------------------------------------------------
2731
28- def flag_calls (func ) :
32+ def flag_calls (func : Callable [..., Any ]) -> Callable [..., Any ] :
2933 """Wrap a function to detect and flag when it gets called.
3034
3135 This is a decorator which takes a function and wraps it in a function with
@@ -37,23 +41,23 @@ def flag_calls(func):
3741
3842 Testing for truth in wrapper.called allows you to determine if a call to
3943 func() was attempted and succeeded."""
40-
44+
4145 # don't wrap twice
4246 if hasattr (func , 'called' ):
4347 return func
4448
45- def wrapper (* args , ** kw ) :
46- wrapper .called = False
47- out = func (* args ,** kw )
48- wrapper .called = True
49+ def wrapper (* args : Any , ** kw : Any ) -> Any :
50+ wrapper .called = False # type: ignore[attr-defined]
51+ out = func (* args , ** kw )
52+ wrapper .called = True # type: ignore[attr-defined]
4953 return out
5054
51- wrapper .called = False
55+ wrapper .called = False # type: ignore[attr-defined]
5256 wrapper .__doc__ = func .__doc__
5357 return wrapper
5458
5559
56- def undoc (func ) :
60+ def undoc (func : F ) -> F :
5761 """Mark a function or class as undocumented.
5862
5963 This is found by inspecting the AST, so for now it must be used directly
@@ -66,14 +70,14 @@ def sphinx_options(
6670 show_inheritance : bool = True ,
6771 show_inherited_members : bool = False ,
6872 exclude_inherited_from : Sequence [str ] = tuple (),
69- ):
73+ ) -> Callable [[ F ], F ] :
7074 """Set sphinx options"""
7175
72- def wrapper (func ) :
76+ def wrapper (func : F ) -> F :
7377 if not GENERATING_DOCUMENTATION :
7478 return func
7579
76- func ._sphinx_options = dict (
80+ func ._sphinx_options = dict ( # type: ignore[attr-defined]
7781 show_inheritance = show_inheritance ,
7882 show_inherited_members = show_inherited_members ,
7983 exclude_inherited_from = exclude_inherited_from ,
0 commit comments