Skip to content

Narrow _typeshed.ProfileFunction and _typeshed.TraceFunction by the event names they are documented to take#15802

Merged
srittau merged 3 commits into
python:mainfrom
jonathandung:patch-4
May 18, 2026
Merged

Narrow _typeshed.ProfileFunction and _typeshed.TraceFunction by the event names they are documented to take#15802
srittau merged 3 commits into
python:mainfrom
jonathandung:patch-4

Conversation

@jonathandung
Copy link
Copy Markdown
Contributor

@jonathandung jonathandung commented May 17, 2026

Changes the above definitions to the following:

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

# Objects suitable to be passed to sys.settrace, threading.settrace, and similar
TraceFunction: TypeAlias = Callable[
    [FrameType, Literal["call", "line", "return", "exception", "opcode"], Any], TraceFunction | None
]

where the Literal's were originally typed as plain strings. This is from these python docs snippets for sys.settrace and sys.setprofile.

@github-actions

This comment has been minimized.

@jonathandung jonathandung marked this pull request as ready for review May 17, 2026 03:24
@github-actions
Copy link
Copy Markdown
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@srittau srittau merged commit 09ee44b into python:main May 18, 2026
58 checks passed
@jonathandung jonathandung deleted the patch-4 branch May 19, 2026 01:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants