You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "Bas Harenslak (JIRA)" <ji...@apache.org> on 2019/05/18 17:27:00 UTC

[jira] [Updated] (AIRFLOW-4374) Inherit from Enum

     [ https://issues.apache.org/jira/browse/AIRFLOW-4374?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Bas Harenslak updated AIRFLOW-4374:
-----------------------------------
    Description: 
Python 3.4 introduced the Enum type, which can reduce the complexity of a few enum-style classes. E.g. the TriggerRule could become:
{code:java}
from enum import Enum


class TriggerRule(Enum):
    ALL_SUCCESS = "all_success"
    ALL_FAILED = "all_failed"
    ALL_DONE = "all_done"
    ONE_SUCCESS = "one_success"
    ONE_FAILED = "one_failed"
    NONE_FAILED = "none_failed"
    NONE_SKIPPED = "none_skipped"
    DUMMY = "dummy"

    @classmethod
    def all_triggers(cls):
        return [tr.name for tr in TriggerRule]
{code}
 A quick scan showed me enum-like class are TriggerRule, WeightRule, -State-, but there might be more, so search first.

Also, note this is optional and not required for running in Python 3.

 

Edit: not touching the State in this one, since state contains additional attributes (e.g. state_color) and in Python Enum all attributes are part of the Enum class, which we don't want in this case. Will have to rethink this one.

  was:
Python 3.4 introduced the Enum type, which can reduce the complexity of a few enum-style classes. E.g. the TriggerRule could become:
{code}
from enum import Enum


class TriggerRule(Enum):
    ALL_SUCCESS = "all_success"
    ALL_FAILED = "all_failed"
    ALL_DONE = "all_done"
    ONE_SUCCESS = "one_success"
    ONE_FAILED = "one_failed"
    NONE_FAILED = "none_failed"
    NONE_SKIPPED = "none_skipped"
    DUMMY = "dummy"

    @classmethod
    def all_triggers(cls):
        return [tr.name for tr in TriggerRule]
{code}
 A quick scan showed me enum-like class are TriggerRule, WeightRule, State, but there might be more, so search first.

Also, note this is optional and not required for running in Python 3.


> Inherit from Enum
> -----------------
>
>                 Key: AIRFLOW-4374
>                 URL: https://issues.apache.org/jira/browse/AIRFLOW-4374
>             Project: Apache Airflow
>          Issue Type: Sub-task
>            Reporter: Bas Harenslak
>            Priority: Minor
>
> Python 3.4 introduced the Enum type, which can reduce the complexity of a few enum-style classes. E.g. the TriggerRule could become:
> {code:java}
> from enum import Enum
> class TriggerRule(Enum):
>     ALL_SUCCESS = "all_success"
>     ALL_FAILED = "all_failed"
>     ALL_DONE = "all_done"
>     ONE_SUCCESS = "one_success"
>     ONE_FAILED = "one_failed"
>     NONE_FAILED = "none_failed"
>     NONE_SKIPPED = "none_skipped"
>     DUMMY = "dummy"
>     @classmethod
>     def all_triggers(cls):
>         return [tr.name for tr in TriggerRule]
> {code}
>  A quick scan showed me enum-like class are TriggerRule, WeightRule, -State-, but there might be more, so search first.
> Also, note this is optional and not required for running in Python 3.
>  
> Edit: not touching the State in this one, since state contains additional attributes (e.g. state_color) and in Python Enum all attributes are part of the Enum class, which we don't want in this case. Will have to rethink this one.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)