You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by tv...@apache.org on 2021/02/04 07:10:41 UTC

[buildstream] 01/01: types.py: Derive enumerations from standard library classes

This is an automated email from the ASF dual-hosted git repository.

tvb pushed a commit to branch chandan/enums
in repository https://gitbox.apache.org/repos/asf/buildstream.git

commit fa6d9856c86e1fe72af02f4ef32267b66be49c75
Author: Chandan Singh <ch...@chandansingh.net>
AuthorDate: Tue Jul 16 22:08:28 2019 +0100

    types.py: Derive enumerations from standard library classes
    
    `types.py` defines a few enumerations, but only some of them are
    derived from the standard `enum.Enum` class.
    
    Among other things, this makes type checking difficult as the inferred
    type of the values is `<class 'int'>` or `<class 'str'>`, and not
    something like `<enum 'Scope'>`.
    
    Note that `Consistency` is derived from `IntEnum` and not `Enum`, since
    it is sometimes used in comparisons.
---
 src/buildstream/types.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/buildstream/types.py b/src/buildstream/types.py
index 6f6262e..d186c4f 100644
--- a/src/buildstream/types.py
+++ b/src/buildstream/types.py
@@ -25,7 +25,7 @@ Foundation types
 
 """
 
-from enum import Enum
+from enum import Enum, IntEnum
 
 
 class Scope(Enum):
@@ -56,7 +56,7 @@ class Scope(Enum):
     """
 
 
-class Consistency():
+class Consistency(IntEnum):
     """Defines the various consistency states of a :class:`.Source`.
     """
 
@@ -81,7 +81,7 @@ class Consistency():
     """
 
 
-class CoreWarnings():
+class CoreWarnings(Enum):
     """CoreWarnings()
 
     Some common warnings which are raised by core functionalities within BuildStream are found in this class.