Skip to content

Commit 09ee44b

Browse files
authored
[_typeshed] Narrow ProfileFunction and TraceFunction to accept only literal event names (#15802)
1 parent b6a3d5f commit 09ee44b

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

stdlib/_typeshed/__init__.pyi

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,10 +351,12 @@ AnyOrLiteralStr = TypeVar("AnyOrLiteralStr", str, bytes, LiteralString) # noqa:
351351
StrOrLiteralStr = TypeVar("StrOrLiteralStr", LiteralString, str) # noqa: Y001
352352

353353
# Objects suitable to be passed to sys.setprofile, threading.setprofile, and similar
354-
ProfileFunction: TypeAlias = Callable[[FrameType, str, Any], object]
354+
ProfileFunction: TypeAlias = Callable[[FrameType, Literal["call", "return", "c_call", "c_return", "c_exception"], Any], object]
355355

356356
# Objects suitable to be passed to sys.settrace, threading.settrace, and similar
357-
TraceFunction: TypeAlias = Callable[[FrameType, str, Any], TraceFunction | None]
357+
TraceFunction: TypeAlias = Callable[
358+
[FrameType, Literal["call", "line", "return", "exception", "opcode"], Any], TraceFunction | None
359+
]
358360

359361
# experimental
360362
# Might not work as expected for pyright, see

0 commit comments

Comments
 (0)