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
d4614e83
Kaydet (Commit)
d4614e83
authored
Şub 27, 2001
tarafından
Barry Warsaw
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Updates to the semantics of function and method attributes.
üst
ab354bb9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
14 deletions
+18
-14
libstdtypes.tex
Doc/lib/libstdtypes.tex
+18
-14
No files found.
Doc/lib/libstdtypes.tex
Dosyayı görüntüle @
d4614e83
...
...
@@ -982,6 +982,16 @@ attributes. \emph{Note that the current implementation only supports
function attributes on functions written in Python. Function
attributes on built-ins may be supported in the future.
}
Functions have another special attribute
\code
{
\var
{
f
}
.
__
dict
__}
(a.k.a.
\code
{
\var
{
f
}
.func
_
dict
}
) which contains the namespace used to
support function attributes.
\code
{__
dict
__}
can be accessed
directly, set to a dictionary object, or
\code
{
None
}
. It can also be
deleted (but the following two lines are equivalent):
\begin{verbatim}
del func.
__
dict
__
func.
__
dict
__
= None
\end{verbatim}
\subsubsection
{
Methods
\label
{
typesmethods
}}
\obindex
{
method
}
...
...
@@ -1007,14 +1017,13 @@ object must be passed as the first argument. In this case,
\code
{
self
}
must be an instance of the unbound method's class (or a
subclass of that class), otherwise a
\code
{
TypeError
}
is raised.
Like function objects, methods objects support getting and setting
arbitrary attributes. However, the attributes are actually stored on
the underlying function object (i.e.
\code
{
meth.im
_
func
}
). To avoid
surprising behavior, a
\code
{
TypeError
}
is raised when an attempt is
made to set an attribute on a bound method. It is legal to get a
bound method's attribute (the underlying function's attribute is
returned), and it is also legal to set or get an unbound method's
attribute. For example:
Like function objects, methods objects support getting
arbitrary attributes. However, since method attributes are actually
stored on the underlying function object (i.e.
\code
{
meth.im
_
func
}
),
setting method attributes on either bound or unbound methods is
disallowed. Attempting to set a method attribute results in a
\code
{
TypeError
}
being raised. In order to set a method attribute,
you need to explicitly set it on the underlying function object:
\begin{verbatim}
class C:
...
...
@@ -1022,14 +1031,9 @@ class C:
pass
c = C()
d = C()
c.method.whoami = 'my name is c'
d.method.whoami = 'my name is d'
c.method.im
_
func.whoami = 'my name is c'
\end{verbatim}
If bound method attribute setting was allowed,
\code
{
c.method.whoami
}
would return ``my name is d''.
See the
\citetitle
[../ref/ref.html]
{
Python Reference Manual
}
for more
information.
...
...
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