mirror of
				https://github.com/python/cpython.git
				synced 2025-11-03 19:34:08 +00:00 
			
		
		
		
	improve Enum docs
This commit is contained in:
		
							parent
							
								
									97be87a5c8
								
							
						
					
					
						commit
						54924df2b1
					
				
					 1 changed files with 12 additions and 11 deletions
				
			
		| 
						 | 
					@ -542,9 +542,9 @@ The next variation of :class:`Enum` provided, :class:`IntFlag`, is also based
 | 
				
			||||||
on :class:`int`.  The difference being :class:`IntFlag` members can be combined
 | 
					on :class:`int`.  The difference being :class:`IntFlag` members can be combined
 | 
				
			||||||
using the bitwise operators (&, \|, ^, ~) and the result is still an
 | 
					using the bitwise operators (&, \|, ^, ~) and the result is still an
 | 
				
			||||||
:class:`IntFlag` member.  However, as the name implies, :class:`IntFlag`
 | 
					:class:`IntFlag` member.  However, as the name implies, :class:`IntFlag`
 | 
				
			||||||
members also subclass :class:`int` and can be used wherever an :class:`int` is.
 | 
					members also subclass :class:`int` and can be used wherever an :class:`int` is
 | 
				
			||||||
Any operation on an :class:`IntFlag` member besides the bit-wise operations
 | 
					used.  Any operation on an :class:`IntFlag` member besides the bit-wise
 | 
				
			||||||
will lose the :class:`IntFlag` membership.
 | 
					operations will lose the :class:`IntFlag` membership.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.. versionadded:: 3.6
 | 
					.. versionadded:: 3.6
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -955,10 +955,11 @@ and raise an error if the two do not match::
 | 
				
			||||||
``Enum`` member type
 | 
					``Enum`` member type
 | 
				
			||||||
""""""""""""""""""""
 | 
					""""""""""""""""""""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
:class:`Enum` members are instances of an :class:`Enum` class, and even
 | 
					:class:`Enum` members are instances of their :class:`Enum` class, and are
 | 
				
			||||||
though they are accessible as `EnumClass.member`, they should not be accessed
 | 
					normally accessed as ``EnumClass.member``.  Under certain circumstances they
 | 
				
			||||||
directly from the member as that lookup may fail or, worse, return something
 | 
					can also be accessed as ``EnumClass.member.member``, but you should never do
 | 
				
			||||||
besides the ``Enum`` member you looking for::
 | 
					this as that lookup may fail or, worse, return something besides the
 | 
				
			||||||
 | 
					:class:`Enum` member you are looking for::
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    >>> class FieldTypes(Enum):
 | 
					    >>> class FieldTypes(Enum):
 | 
				
			||||||
    ...     name = 0
 | 
					    ...     name = 0
 | 
				
			||||||
| 
						 | 
					@ -976,16 +977,16 @@ besides the ``Enum`` member you looking for::
 | 
				
			||||||
Boolean value of ``Enum`` classes and members
 | 
					Boolean value of ``Enum`` classes and members
 | 
				
			||||||
"""""""""""""""""""""""""""""""""""""""""""""
 | 
					"""""""""""""""""""""""""""""""""""""""""""""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
``Enum`` members that are mixed with non-Enum types (such as
 | 
					:class:`Enum` members that are mixed with non-:class:`Enum` types (such as
 | 
				
			||||||
:class:`int`, :class:`str`, etc.) are evaluated according to the mixed-in
 | 
					:class:`int`, :class:`str`, etc.) are evaluated according to the mixed-in
 | 
				
			||||||
type's rules; otherwise, all members evaluate as :data:`True`.  To make your own
 | 
					type's rules; otherwise, all members evaluate as :data:`True`.  To make your
 | 
				
			||||||
Enum's boolean evaluation depend on the member's value add the following to
 | 
					own Enum's boolean evaluation depend on the member's value add the following to
 | 
				
			||||||
your class::
 | 
					your class::
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def __bool__(self):
 | 
					    def __bool__(self):
 | 
				
			||||||
        return bool(self.value)
 | 
					        return bool(self.value)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
``Enum`` classes always evaluate as :data:`True`.
 | 
					:class:`Enum` classes always evaluate as :data:`True`.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
``Enum`` classes with methods
 | 
					``Enum`` classes with methods
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue