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
748dad5b
Kaydet (Commit)
748dad5b
authored
Kas 20, 2015
tarafından
Ethan Furman
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Close 25594: advise against accessing Enum members from other members
üst
5444de93
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
10 deletions
+16
-10
enum.rst
Doc/library/enum.rst
+16
-10
No files found.
Doc/library/enum.rst
Dosyayı görüntüle @
748dad5b
...
...
@@ -730,18 +730,24 @@ member instances.
Finer Points
^^^^^^^^^^^^
Enum members are instances of an Enum class, and even though they are
accessible as `EnumClass.member`, they are not accessible directly from
the member::
>>> Color.red
<Color.red: 1>
>>> Color.red.blue
Traceback (most recent call last):
:class:`Enum` members are instances of an :class:`Enum` class, and even
though they are accessible as `EnumClass.member`, they should not be accessed
directly from the member as that lookup may fail or, worse, return something
besides the :class:`Enum` member you looking for::
>>> class FieldTypes(Enum):
... name = 0
... value = 1
... size = 2
...
AttributeError: 'Color' object has no attribute 'blue'
>>> FieldTypes.value.size
<FieldTypes.size: 2>
>>> FieldTypes.size.value
2
.. versionchanged:: 3.5
Likewise, the :attr:`__members__`
is only available on the class.
The :attr:`__members__` attribute
is only available on the class.
If you give your :class:`Enum` subclass extra methods, like the `Planet`_
class above, those methods will show up in a :func:`dir` of the member,
...
...
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