Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bf88b68

Browse files
committed
Add documentation for the public API for weak reference objects.
1 parent f7f8cad commit bf88b68

1 file changed

Lines changed: 70 additions & 1 deletion

File tree

Doc/api/api.tex

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1099,13 +1099,14 @@ \section{Standard Exceptions \label{standardExceptions}}
10991099
\lineiii{PyExc_NotImplementedError}{\exception{NotImplementedError}}{}
11001100
\lineiii{PyExc_OSError}{\exception{OSError}}{}
11011101
\lineiii{PyExc_OverflowError}{\exception{OverflowError}}{}
1102+
\lineiii{PyExc_ReferenceError}{\exception{ReferenceError}}{(2)}
11021103
\lineiii{PyExc_RuntimeError}{\exception{RuntimeError}}{}
11031104
\lineiii{PyExc_SyntaxError}{\exception{SyntaxError}}{}
11041105
\lineiii{PyExc_SystemError}{\exception{SystemError}}{}
11051106
\lineiii{PyExc_SystemExit}{\exception{SystemExit}}{}
11061107
\lineiii{PyExc_TypeError}{\exception{TypeError}}{}
11071108
\lineiii{PyExc_ValueError}{\exception{ValueError}}{}
1108-
\lineiii{PyExc_WindowsError}{\exception{WindowsError}}{(2)}
1109+
\lineiii{PyExc_WindowsError}{\exception{WindowsError}}{(3)}
11091110
\lineiii{PyExc_ZeroDivisionError}{\exception{ZeroDivisionError}}{}
11101111
\end{tableiii}
11111112

@@ -1116,6 +1117,9 @@ \section{Standard Exceptions \label{standardExceptions}}
11161117
This is a base class for other standard exceptions.
11171118

11181119
\item[(2)]
1120+
This is the same as \exception{weakref.ReferenceError}.
1121+
1122+
\item[(3)]
11191123
Only defined on Windows; protect code that uses this by testing that
11201124
the preprocessor macro \code{MS_WINDOWS} is defined.
11211125
\end{description}
@@ -4502,6 +4506,71 @@ \subsection{Slice Objects \label{slice-objects}}
45024506
\end{cfuncdesc}
45034507

45044508

4509+
\subsection{Weak Reference Objects \label{weakref-objects}}
4510+
4511+
Python supports \emph{weak references} as first-class objects. There
4512+
are two specific object types which directly implement weak
4513+
references. The first is a simple reference object, and the second
4514+
acts as a proxy for the original object as much as it can.
4515+
4516+
\begin{cfuncdesc}{int}{PyWeakref_Check}{ob}
4517+
Return true if \var{ob} is either a reference or proxy object.
4518+
\versionadded{2.2}
4519+
\end{cfuncdesc}
4520+
4521+
\begin{cfuncdesc}{int}{PyWeakref_CheckRef}{ob}
4522+
Return true if \var{ob} is a reference object.
4523+
\versionadded{2.2}
4524+
\end{cfuncdesc}
4525+
4526+
\begin{cfuncdesc}{int}{PyWeakref_CheckProxy}{ob}
4527+
Return true if \var{ob} is a proxy object.
4528+
\versionadded{2.2}
4529+
\end{cfuncdesc}
4530+
4531+
\begin{cfuncdesc}{PyObject*}{PyWeakref_NewRef}{PyObject *ob,
4532+
PyObject *callback}
4533+
Return a weak reference object for the object \var{ob}. This will
4534+
always return a new reference, but is not guaranteed to create a new
4535+
object; an existing reference object may be returned. The second
4536+
parameter, \var{callback}, can be a callable object that receives
4537+
notification when \var{ob} is garbage collected; it should accept a
4538+
single paramter, which will be the weak reference object itself.
4539+
\var{callback} may also be \code{None} or \NULL. If \var{ob}
4540+
is not a weakly-referencable object, or if \var{callback} is not
4541+
callable, \code{None}, or \NULL, this will return \NULL{} and
4542+
raise \exception{TypeError}.
4543+
\versionadded{2.2}
4544+
\end{cfuncdesc}
4545+
4546+
\begin{cfuncdesc}{PyObject*}{PyWeakref_NewProxy}{PyObject *ob,
4547+
PyObject *callback}
4548+
Return a weak reference proxy object for the object \var{ob}. This
4549+
will always return a new reference, but is not guaranteed to create
4550+
a new object; an existing proxy object may be returned. The second
4551+
parameter, \var{callback}, can be a callable object that receives
4552+
notification when \var{ob} is garbage collected; it should accept a
4553+
single paramter, which will be the weak reference object itself.
4554+
\var{callback} may also be \code{None} or \NULL. If \var{ob} is not
4555+
a weakly-referencable object, or if \var{callback} is not callable,
4556+
\code{None}, or \NULL, this will return \NULL{} and raise
4557+
\exception{TypeError}.
4558+
\versionadded{2.2}
4559+
\end{cfuncdesc}
4560+
4561+
\begin{cfuncdesc}{PyObject*}{PyWeakref_GetObject}{PyObject *ref}
4562+
Returns the referenced object from a weak reference, \var{ref}. If
4563+
the referent is no longer live, returns \NULL.
4564+
\versionadded{2.2}
4565+
\end{cfuncdesc}
4566+
4567+
\begin{cfuncdesc}{PyObject*}{PyWeakref_GET_OBJECT}{PyObject *ref}
4568+
Similar to \cfunction{PyWeakref_GetObject()}, but implemented as a
4569+
macro that does no error checking.
4570+
\versionadded{2.2}
4571+
\end{cfuncdesc}
4572+
4573+
45054574
\subsection{CObjects \label{cObjects}}
45064575

45074576
\obindex{CObject}

0 commit comments

Comments
 (0)