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
ccf44b04
Kaydet (Commit)
ccf44b04
authored
Ock 15, 2016
tarafından
Ethan Furman
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
branch merge
üst
63b85052
60255b67
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
5 deletions
+26
-5
enum.rst
Doc/library/enum.rst
+10
-1
enum.py
Lib/enum.py
+0
-3
test_enum.py
Lib/test/test_enum.py
+16
-1
No files found.
Doc/library/enum.rst
Dosyayı görüntüle @
ccf44b04
...
...
@@ -257,7 +257,7 @@ members are not integers (but see `IntEnum`_ below)::
>>> Color.red < Color.blue
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError:
'<' not supported between instances of 'Color' and 'Color'
TypeError:
unorderable types: Color() < Color()
Equality comparisons are defined though::
...
...
@@ -747,6 +747,15 @@ besides the :class:`Enum` member you looking for::
.. versionchanged:: 3.5
Boolean evaluation: Enum classes that are mixed with non-Enum types (such as
:class:`int`, :class:`str`, etc.) are evaluated according to the mixed-in
type's rules; otherwise, all members evaluate as ``True``. To make your own
Enum's boolean evaluation depend on the member's value add the following to
your class::
def __bool__(self):
return bool(self._value_)
The :attr:`__members__` attribute is only available on the class.
If you give your :class:`Enum` subclass extra methods, like the `Planet`_
...
...
Lib/enum.py
Dosyayı görüntüle @
ccf44b04
...
...
@@ -482,9 +482,6 @@ class Enum(metaclass=EnumMeta):
def
__str__
(
self
):
return
"
%
s.
%
s"
%
(
self
.
__class__
.
__name__
,
self
.
_name_
)
def
__bool__
(
self
):
return
bool
(
self
.
_value_
)
def
__dir__
(
self
):
added_behavior
=
[
m
...
...
Lib/test/test_enum.py
Dosyayı görüntüle @
ccf44b04
...
...
@@ -272,11 +272,26 @@ class TestEnum(unittest.TestCase):
_any_name_
=
9
def
test_bool
(
self
):
# plain Enum members are always True
class
Logic
(
Enum
):
true
=
True
false
=
False
self
.
assertTrue
(
Logic
.
true
)
self
.
assertFalse
(
Logic
.
false
)
self
.
assertTrue
(
Logic
.
false
)
# unless overridden
class
RealLogic
(
Enum
):
true
=
True
false
=
False
def
__bool__
(
self
):
return
bool
(
self
.
_value_
)
self
.
assertTrue
(
RealLogic
.
true
)
self
.
assertFalse
(
RealLogic
.
false
)
# mixed Enums depend on mixed-in type
class
IntLogic
(
int
,
Enum
):
true
=
1
false
=
0
self
.
assertTrue
(
IntLogic
.
true
)
self
.
assertFalse
(
IntLogic
.
false
)
def
test_contains
(
self
):
Season
=
self
.
Season
...
...
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