Skip to content

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

Open
jonathandung wants to merge 3 commits into
python:mainfrom
jonathandung:patch-4
Open

Narrow _typeshed.ProfileFunction and _typeshed.TraceFunction by the event names they are documented to take#15802
jonathandung wants to merge 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. 🤖🎉

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.

1 participant