Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
9e56d5be
Kaydet (Commit)
9e56d5be
authored
Nis 03, 2007
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
SF #1382213: Tutorial section 9.5.1 ignores MRO for new-style classes
üst
7352cf59
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
11 deletions
+20
-11
tut.tex
Doc/tut/tut.tex
+20
-11
No files found.
Doc/tut/tut.tex
Dosyayı görüntüle @
9e56d5be
...
@@ -4329,8 +4329,7 @@ class DerivedClassName(Base1, Base2, Base3):
...
@@ -4329,8 +4329,7 @@ class DerivedClassName(Base1, Base2, Base3):
<statement
-
N>
<statement
-
N>
\end
{
verbatim
}
\end
{
verbatim
}
The only rule necessary to explain the semantics is the resolution
For old
-
style classes, the only rule is depth
-
first,
rule used for class attribute references. This is depth
-
first,
left
-
to
-
right. Thus, if an attribute is not found in
left
-
to
-
right. Thus, if an attribute is not found in
\class
{
DerivedClassName
}
, it is searched in
\class
{
Base
1
}
, then
\class
{
DerivedClassName
}
, it is searched in
\class
{
Base
1
}
, then
(
recursively
)
in the base classes of
\class
{
Base
1
}
, and only if it is
(
recursively
)
in the base classes of
\class
{
Base
1
}
, and only if it is
...
@@ -4345,16 +4344,26 @@ a name conflict with an attribute of \class{Base2}. The depth-first
...
@@ -4345,16 +4344,26 @@ a name conflict with an attribute of \class{Base2}. The depth-first
rule makes no differences between direct and inherited attributes of
rule makes no differences between direct and inherited attributes of
\class
{
Base
1
}
.
)
\class
{
Base
1
}
.
)
It is clear that indiscriminate use of multiple inheritance is a
For new
-
style classes, the method resolution order changes dynamically
maintenance nightmare, given the reliance in Python on conventions to
to support cooperative calls to
\function
{
super
()
}
. This approach
avoid accidental name conflicts. A well
-
known problem with multiple
is known in some other multiple
-
inheritance languages as call
-
next
-
method
inheritance is a class derived from two classes that happen to have a
and is more powerful than the super call found in single
-
inheritance languages.
common base class. While it is easy enough to figure out what happens
in this case
(
the instance will have a single copy of ``instance
With new
-
style classes, dynamic ordering is necessary because all
variables'' or data attributes used by the common base class
)
, it is
cases of multiple inheritance exhibit one or more diamond relationships
not clear that these semantics are in any way useful.
(
where one at least one of the parent classes can be accessed through
multiple paths from the bottommost class
)
. For example, all new
-
style
classes inherit from
\class
{
object
}
, so any case of multiple inheritance
provides more than one path to reach
\class
{
object
}
. To keep the
base classes from being accessed more than once, the dynamic algorithm
linearizes the search order in a way that preserves the left
-
to
-
right
ordering specified in each class, that calls each parent only once, and
that is monotonic
(
meaning that a class can be subclassed without affecting
the precedence order of its parents
)
. Taken together, these properties
make it possible to design reliable and extensible classes with
multiple inheritance. For more detail, see
\url
{
http:
//
www.python.org
/
download
/
releases
/
2
.
3
/
mro
/
}
.
%% XXX Add rules for new-style MRO?
\section
{
Private Variables
\label
{
private
}}
\section
{
Private Variables
\label
{
private
}}
...
...
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