Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
68728874
Commit
68728874
authored
May 14, 2002
by
Fred Drake
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Minor wording changes, plus correct a typo.
parent
4e36b03b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
7 deletions
+7
-7
Doc/ext/newtypes.tex
Doc/ext/newtypes.tex
+7
-7
No files found.
Doc/ext/newtypes.tex
View file @
68728874
...
@@ -20,9 +20,9 @@ object - it just contains the refcount and a pointer to the object's
...
@@ -20,9 +20,9 @@ object - it just contains the refcount and a pointer to the object's
``type object''. This is where the action is; the type object
``type object''. This is where the action is; the type object
determines which (C) functions get called when, for instance, an
determines which (C) functions get called when, for instance, an
attribute gets looked up on an object or it is multiplied by another
attribute gets looked up on an object or it is multiplied by another
object.
I call these C functions ``type methods'' to distinguish them
object.
These C functions are called ``type methods'' to distinguish
from things like
\code
{
[].append
}
(which I will
call ``object
them from things like
\code
{
[].append
}
(which we
call ``object
methods''
when I get around to them
).
methods'').
So, if you want to define a new object type, you need to create a new
So, if you want to define a new object type, you need to create a new
type object.
type object.
...
@@ -184,7 +184,7 @@ definition above. The remaining fields will be filled with zeros by
...
@@ -184,7 +184,7 @@ definition above. The remaining fields will be filled with zeros by
the C compiler, and it's common practice to not specify them
the C compiler, and it's common practice to not specify them
explicitly unless you need them.
explicitly unless you need them.
This is so important that
I'm
going to pick the top of it apart still
This is so important that
we're
going to pick the top of it apart still
further:
further:
\begin{verbatim}
\begin{verbatim}
...
@@ -237,7 +237,7 @@ This is so that Python knows how much memory to allocate when you call
...
@@ -237,7 +237,7 @@ This is so that Python knows how much memory to allocate when you call
\end{verbatim}
\end{verbatim}
This has to do with variable length objects like lists and strings.
This has to do with variable length objects like lists and strings.
Ignore
for now..
.
Ignore
this for now
.
Now we get into the type methods, the things that make your objects
Now we get into the type methods, the things that make your objects
different from the others. Of course, the Noddy object doesn't
different from the others. Of course, the Noddy object doesn't
...
@@ -248,7 +248,7 @@ the deallocation function.
...
@@ -248,7 +248,7 @@ the deallocation function.
noddy
_
noddy
_
dealloc, /* tp
_
dealloc */
noddy
_
noddy
_
dealloc, /* tp
_
dealloc */
\end{verbatim}
\end{verbatim}
From here, all the type methods are
\NULL
, so
I won't go over them yet
From here, all the type methods are
\NULL
, so
we'll go over them later
--- that's for the next section!
--- that's for the next section!
Everything else in the file should be familiar, except for this line
Everything else in the file should be familiar, except for this line
...
@@ -452,7 +452,7 @@ The \member{tp_str} handler is to \function{str()} what the
...
@@ -452,7 +452,7 @@ The \member{tp_str} handler is to \function{str()} what the
is, it is called when Python code calls
\function
{
str
()
}
on an
is, it is called when Python code calls
\function
{
str
()
}
on an
instance of your object. It's implementation is very similar to the
instance of your object. It's implementation is very similar to the
\member
{
tp
_
repr
}
function, but the resulting string is intended for
\member
{
tp
_
repr
}
function, but the resulting string is intended for
human consumption. I
t
\member
{
tp
_
str
}
is not specified, the
human consumption. I
f
\member
{
tp
_
str
}
is not specified, the
\member
{
tp
_
repr
}
handler is used instead.
\member
{
tp
_
repr
}
handler is used instead.
Here is a simple example:
Here is a simple example:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment