diff --git a/python/lsst/pipe/base/cmdLineTask.py b/python/lsst/pipe/base/cmdLineTask.py index 282ceccd8..fa3916045 100644 --- a/python/lsst/pipe/base/cmdLineTask.py +++ b/python/lsst/pipe/base/cmdLineTask.py @@ -25,9 +25,14 @@ import contextlib import logging +from collections.abc import Generator +from typing import TYPE_CHECKING from deprecated.sphinx import deprecated +if TYPE_CHECKING: + import cProfile + @deprecated( reason="Replaced by lsst.utils.timer.profile(). Will be removed after v26.0", @@ -35,7 +40,7 @@ category=FutureWarning, ) @contextlib.contextmanager -def profile(filename: str, log: logging.Logger | None = None): +def profile(filename: str, log: logging.Logger | None = None) -> Generator[cProfile.Profile, None, None]: """Context manager for profiling with cProfile. Parameters @@ -71,7 +76,7 @@ def profile(filename: str, log: logging.Logger | None = None): """ if not filename: # Nothing to do - yield + yield None # type: ignore return from cProfile import Profile