summaryrefslogtreecommitdiffstats
path: root/Include/cpython/context.h
Commit message (Collapse)AuthorAgeFilesLines
* gh-124872: Replace enter/exit events with "switched" (#125532)Kirill Podoprigora2024-10-161-13/+4
| | | | | | | | | | | | | | | | | | | | | | | | | Users want to know when the current context switches to a different context object. Right now this happens when and only when a context is entered or exited, so the enter and exit events are synonymous with "switched". However, if the changes proposed for gh-99633 are implemented, the current context will also switch for reasons other than context enter or exit. Since users actually care about context switches and not enter or exit, replace the enter and exit events with a single switched event. The former exit event was emitted just before exiting the context. The new switched event is emitted after the context is exited to match the semantics users expect of an event with a past-tense name. If users need the ability to clean up before the switch takes effect, another event type can be added in the future. It is not added here because YAGNI. I skipped 0 in the enum as a matter of practice. Skipping 0 makes it easier to troubleshoot when code forgets to set zeroed memory, and it aligns with best practices for other tools (e.g., https://protobuf.dev/programming-guides/dos-donts/#unspecified-enum). Co-authored-by: Richard Hansen <rhansen@rhansen.org> Co-authored-by: Victor Stinner <vstinner@python.org>
* gh-125512: Revert "gh-124872: Replace enter/exit events with "switched" ↵Kirill Podoprigora2024-10-151-4/+13
| | | | (#124776)" (#125513)
* gh-124872: Replace enter/exit events with "switched" (#124776)Richard Hansen2024-10-141-13/+4
| | | | | | | | | | | | | | | | | | | | | | Users want to know when the current context switches to a different context object. Right now this happens when and only when a context is entered or exited, so the enter and exit events are synonymous with "switched". However, if the changes proposed for gh-99633 are implemented, the current context will also switch for reasons other than context enter or exit. Since users actually care about context switches and not enter or exit, replace the enter and exit events with a single switched event. The former exit event was emitted just before exiting the context. The new switched event is emitted after the context is exited to match the semantics users expect of an event with a past-tense name. If users need the ability to clean up before the switch takes effect, another event type can be added in the future. It is not added here because YAGNI. I skipped 0 in the enum as a matter of practice. Skipping 0 makes it easier to troubleshoot when code forgets to set zeroed memory, and it aligns with best practices for other tools (e.g., https://protobuf.dev/programming-guides/dos-donts/#unspecified-enum).
* gh-124872: Change PyContext_WatchCallback to take PyObject (#124737)Richard Hansen2024-10-121-1/+1
| | | | | The PyContext struct is not intended to be public, and users of the API don't need anything more specific than PyObject. Also see gh-78943.
* gh-124872: Refine contextvars documentation (#124773)Richard Hansen2024-10-091-6/+17
| | | | | | | | | | | | | * Add definitions for "context", "current context", and "context management protocol". * Update related definitions to be consistent with the new definitions. * Restructure the documentation for the `contextvars.Context` class to prepare for adding context manager support, and for consistency with the definitions. * Use `testcode` and `testoutput` to test the `Context.run` example. * Expand the documentation for the `Py_CONTEXT_EVENT_ENTER` and `Py_CONTEXT_EVENT_EXIT` events to clarify and to prepare for planned changes.
* gh-119333: get interp from tstate for PyContext watchers(#124444)Jason Fried2024-09-261-3/+2
| | | Co-authored-by: Kumar Aditya <kumaraditya@python.org>
* gh-119333: Add C api to have contextvar enter/exit callbacks (#119335)Jason Fried2024-09-241-0/+32
| | | Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
* gh-106320: Remove private _PyContext_NewHamtForTests() (#108434)Victor Stinner2023-08-241-4/+0
| | | Move the function to the internal C API.
* gh-87347: Add parenthesis around PyXXX_Check() arguments (#92815)Victor Stinner2022-06-161-3/+3
|
* bpo-35134: Move classobject.h to Include/cpython/ (GH-28968)Victor Stinner2021-10-151-0/+78
Move classobject.h, context.h, genobject.h and longintrepr.h header files from Include/ to Include/cpython/. Remove redundant "#ifndef Py_LIMITED_API" in context.h. Remove explicit #include "longintrepr.h" in C files. It's not needed, Python.h already includes it.