| 
									
										
										
										
											2019-05-17 11:55:34 +02:00
										 |  |  | .. highlight:: c
 | 
					
						
							| 
									
										
										
										
											2008-01-20 09:30:57 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | .. _reflection:
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Reflection
 | 
					
						
							|  |  |  | ==========
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-20 15:51:45 +01:00
										 |  |  | .. c:function:: PyObject* PyEval_GetBuiltins(void)
 | 
					
						
							| 
									
										
										
										
											2008-01-20 09:30:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-01 13:59:35 +10:00
										 |  |  |    .. deprecated:: 3.13
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       Use :c:func:`PyEval_GetFrameBuiltins` instead.
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-01-20 09:30:57 +00:00
										 |  |  |    Return a dictionary of the builtins in the current execution frame,
 | 
					
						
							|  |  |  |    or the interpreter of the thread state if no frame is currently executing.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-20 15:51:45 +01:00
										 |  |  | .. c:function:: PyObject* PyEval_GetLocals(void)
 | 
					
						
							| 
									
										
										
										
											2008-01-20 09:30:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-01 13:59:35 +10:00
										 |  |  |    .. deprecated:: 3.13
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-02 14:44:29 +10:00
										 |  |  |       Use either :c:func:`PyEval_GetFrameLocals` to obtain the same behaviour as calling
 | 
					
						
							| 
									
										
										
										
											2024-06-01 16:21:48 +10:00
										 |  |  |       :func:`locals` in Python code, or else call :c:func:`PyFrame_GetLocals` on the result
 | 
					
						
							| 
									
										
										
										
											2024-06-02 14:44:29 +10:00
										 |  |  |       of :c:func:`PyEval_GetFrame` to access the :attr:`~frame.f_locals` attribute of the
 | 
					
						
							|  |  |  |       currently executing frame.
 | 
					
						
							| 
									
										
										
										
											2024-06-01 13:59:35 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-02 14:44:29 +10:00
										 |  |  |    Return a mapping providing access to the local variables in the current execution frame,
 | 
					
						
							| 
									
										
										
										
											2019-10-30 12:03:20 +02:00
										 |  |  |    or ``NULL`` if no frame is currently executing.
 | 
					
						
							| 
									
										
										
										
											2009-01-03 21:18:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-02 14:44:29 +10:00
										 |  |  |    Refer to :func:`locals` for details of the mapping returned at different scopes.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |    As this function returns a :term:`borrowed reference`, the dictionary returned for
 | 
					
						
							|  |  |  |    :term:`optimized scopes <optimized scope>` is cached on the frame object and will remain
 | 
					
						
							|  |  |  |    alive as long as the frame object does. Unlike :c:func:`PyEval_GetFrameLocals` and
 | 
					
						
							|  |  |  |    :func:`locals`, subsequent calls to this function in the same frame will update the
 | 
					
						
							|  |  |  |    contents of the cached dictionary to reflect changes in the state of the local variables
 | 
					
						
							|  |  |  |    rather than returning a new snapshot.
 | 
					
						
							| 
									
										
										
										
											2024-06-01 16:21:48 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  |    .. versionchanged:: 3.13
 | 
					
						
							| 
									
										
										
										
											2024-06-02 14:44:29 +10:00
										 |  |  |       As part of :pep:`667`, :c:func:`PyFrame_GetLocals`, :func:`locals`, and
 | 
					
						
							|  |  |  |       :attr:`FrameType.f_locals <frame.f_locals>` no longer make use of the shared cache
 | 
					
						
							|  |  |  |       dictionary. Refer to the :ref:`What's New entry <whatsnew313-locals-semantics>` for
 | 
					
						
							|  |  |  |       additional details.
 | 
					
						
							| 
									
										
										
										
											2024-06-01 16:21:48 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-01-20 09:30:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-20 15:51:45 +01:00
										 |  |  | .. c:function:: PyObject* PyEval_GetGlobals(void)
 | 
					
						
							| 
									
										
										
										
											2008-01-20 09:30:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-01 13:59:35 +10:00
										 |  |  |    .. deprecated:: 3.13
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       Use :c:func:`PyEval_GetFrameGlobals` instead.
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-01-20 09:30:57 +00:00
										 |  |  |    Return a dictionary of the global variables in the current execution frame,
 | 
					
						
							| 
									
										
										
										
											2019-10-30 12:03:20 +02:00
										 |  |  |    or ``NULL`` if no frame is currently executing.
 | 
					
						
							| 
									
										
										
										
											2008-01-20 09:30:57 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-20 15:51:45 +01:00
										 |  |  | .. c:function:: PyFrameObject* PyEval_GetFrame(void)
 | 
					
						
							| 
									
										
										
										
											2008-01-20 09:30:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-30 12:03:20 +02:00
										 |  |  |    Return the current thread state's frame, which is ``NULL`` if no frame is
 | 
					
						
							| 
									
										
										
										
											2008-01-20 09:30:57 +00:00
										 |  |  |    currently executing.
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-20 15:51:45 +01:00
										 |  |  |    See also :c:func:`PyThreadState_GetFrame`.
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-01-20 09:30:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-01 13:59:35 +10:00
										 |  |  | .. c:function:: PyObject* PyEval_GetFrameBuiltins(void)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |    Return a dictionary of the builtins in the current execution frame,
 | 
					
						
							|  |  |  |    or the interpreter of the thread state if no frame is currently executing.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |    .. versionadded:: 3.13
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | .. c:function:: PyObject* PyEval_GetFrameLocals(void)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |    Return a dictionary of the local variables in the current execution frame,
 | 
					
						
							|  |  |  |    or ``NULL`` if no frame is currently executing. Equivalent to calling
 | 
					
						
							|  |  |  |    :func:`locals` in Python code.
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-01 16:21:48 +10:00
										 |  |  |    To access :attr:`~frame.f_locals` on the current frame without making an independent
 | 
					
						
							|  |  |  |    snapshot in :term:`optimized scopes <optimized scope>`, call :c:func:`PyFrame_GetLocals`
 | 
					
						
							|  |  |  |    on the result of :c:func:`PyEval_GetFrame`.
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-01 13:59:35 +10:00
										 |  |  |    .. versionadded:: 3.13
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | .. c:function:: PyObject* PyEval_GetFrameGlobals(void)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |    Return a dictionary of the global variables in the current execution frame,
 | 
					
						
							|  |  |  |    or ``NULL`` if no frame is currently executing. Equivalent to calling
 | 
					
						
							|  |  |  |    :func:`globals` in Python code.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |    .. versionadded:: 3.13
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-06 10:11:56 +00:00
										 |  |  | .. c:function:: const char* PyEval_GetFuncName(PyObject *func)
 | 
					
						
							| 
									
										
										
										
											2008-01-20 09:30:57 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |    Return the name of *func* if it is a function, class or instance object, else the
 | 
					
						
							|  |  |  |    name of *func*\s type.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-06 10:11:56 +00:00
										 |  |  | .. c:function:: const char* PyEval_GetFuncDesc(PyObject *func)
 | 
					
						
							| 
									
										
										
										
											2008-01-20 09:30:57 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |    Return a description string, depending on the type of *func*.
 | 
					
						
							|  |  |  |    Return values include "()" for functions and methods, " constructor",
 | 
					
						
							|  |  |  |    " instance", and " object".  Concatenated with the result of
 | 
					
						
							| 
									
										
										
										
											2010-10-06 10:11:56 +00:00
										 |  |  |    :c:func:`PyEval_GetFuncName`, the result will be a description of
 | 
					
						
							| 
									
										
										
										
											2008-01-20 09:30:57 +00:00
										 |  |  |    *func*.
 |