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
3134f14b
Kaydet (Commit)
3134f14b
authored
Eyl 19, 2008
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Improve docs for super().
üst
5aaa3e57
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
1 deletion
+18
-1
functions.rst
Doc/library/functions.rst
+18
-1
No files found.
Doc/library/functions.rst
Dosyayı görüntüle @
3134f14b
...
...
@@ -1216,13 +1216,28 @@ available. They are listed here in alphabetical order.
.. function:: super(type[, object-or-type])
Return a "
super
" object that acts like the superclass of *type*.
If the second argument is omitted the super
object returned is unbound. If the second argument is an object,
``isinstance(obj, type)`` must be true. If the second argument is a type,
``issubclass(type2, type)`` must be true. :func:`super` only works for
:term:`new-style class`\es.
A typical use for calling a cooperative superclass method is::
There are two typical use cases for "
super
". In a class hierarchy with
single inheritance, "
super
" can be used to refer to parent classes without
naming them explicitly, thus making the code more maintainable. This use
closely parallels the use of "
super
" in other programming languages.
The second use case is to support cooperative multiple inheritence in a
dynamic execution environment. This use case is unique to Python and is
not found in statically compiled languages or languages that only support
single inheritance. This makes in possible to implement "
diamond
diagrams
"
where multiple base classes implement the same method. Good design dictates
that this method have the same calling signature in every case (because the
order of parent calls is determined at runtime and because that order adapts
to changes in the class hierarchy).
For both use cases, a typical superclass call looks like this::
class C(B):
def meth(self, arg):
...
...
@@ -1230,6 +1245,8 @@ available. They are listed here in alphabetical order.
Note that :func:`super` is implemented as part of the binding process for
explicit dotted attribute lookups such as ``super(C, self).__getitem__(name)``.
It does so by implementing its own :meth:`__getattribute__` method for searching
parent classes in a predictable order that supports cooperative multiple inheritance.
Accordingly, :func:`super` is undefined for implicit lookups using statements or
operators such as ``super(C, self)[name]``.
...
...
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