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
ff564d33
Commit
ff564d33
authored
Mar 08, 2005
by
Greg Ward
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SF #1156412: document the __new__() static method
(merge from release24-maint branch).
parent
50682d0f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
0 deletions
+29
-0
Doc/ref/ref3.tex
Doc/ref/ref3.tex
+29
-0
No files found.
Doc/ref/ref3.tex
View file @
ff564d33
...
...
@@ -1052,6 +1052,35 @@ extracting a slice may not make sense. (One example of this is the
\subsection
{
Basic customization
\label
{
customization
}}
\begin{methoddesc}
[object]
{__
new
__}{
cls
\optional
{
,
\moreargs
}}
Called to create a new instance of class
\var
{
cls
}
.
\method
{__
new
__
()
}
is a static method (special-cased so you need not declare it as such)
that takes the class of which an instance was requested as its first
argument. The remaining arguments are those passed to the object
constructor expression (the call to the class). The return value of
\method
{__
new
__
()
}
should be the new object instance (usually an
instance of
\var
{
cls
}
).
Typical implementations create a new instance of the class by invoking
the superclass's
\method
{__
new
__
()
}
method using
\samp
{
super(
\var
{
currentclass
}
,
\var
{
cls
}
).
__
new
__
(
\var
{
cls
}
[, ...])
}
with appropriate arguments and then modifying the newly-created instance
as necessary before returning it.
If
\method
{__
new
__
()
}
returns an instance of
\var
{
cls
}
, then the new
instance's
\method
{__
init
__
()
}
method will be invoked like
\samp
{__
init
__
(
\var
{
self
}
[, ...])
}
, where
\var
{
self
}
is the new instance
and the remaining arguments are the same as were passed to
\method
{__
new
__
()
}
.
If
\method
{__
new
__
()
}
does not return an instance of
\var
{
cls
}
, then the
new instance's
\method
{__
init
__
()
}
method will not be invoked.
\method
{__
new
__
()
}
is intended mainly to allow subclasses of
immutable types (like int, str, or tuple) to customize instance
creation.
\end{methoddesc}
\begin{methoddesc}
[object]
{__
init
__}{
self
\optional
{
,
\moreargs
}}
Called
\indexii
{
class
}{
constructor
}
when the instance is created. The
arguments are those passed to the class constructor expression. If a
...
...
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