Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Register new operators #16

Open
Tiago-Lira opened this issue Jul 5, 2019 · 1 comment
Open

Feature request: Register new operators #16

Tiago-Lira opened this issue Jul 5, 2019 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@Tiago-Lira
Copy link

Tiago-Lira commented Jul 5, 2019

Flipper's latest version supports these kind of operators:

  • __gt Greater than
  • __gte Greater than or equal to
  • __lt Less than
  • __lte Less than or equal to
  • __ne Not equals
  • __in Set membership
  • __not_in Set non-membership

However, a complex program may require extra or custom operators. The only way to add new operators are opening a pull-request or doing a hack:

from typing import Iterable

from flipper.conditions.operators.interface import AbstractOperator
from flipper.conditions.operators import Operator


class OverlapOperator(AbstractOperator):
    SYMBOL = "overlap"

    def compare(
        self,
        expected: Iterable,
        actual: Iterable,
    ) -> bool:
        return bool(set(expected) - set(actual)) is False


Operator.OPERATOR_MAP[OverlapOperator.SYMBOL] = OverlapOperator

I'll open a pull-request adding OverlapOperator. But I'd love to hear thoughts about being able to add custom operators for specific projects.

@Tiago-Lira Tiago-Lira added the enhancement New feature or request label Jul 5, 2019
@adambom
Copy link
Contributor

adambom commented Jul 8, 2019

I don't think we'll add OverlapOperator to the main repo. I don't totally understand the use case and I don't think it will be used all that often.

My preference would be to add a register method to the operator factory: flipper.conditions.operators.Operator. Then you could have a public interface for registering any new operators you want. I'll review that PR if you want to put it together.

class Operator:
    @classmethod
    def register(cls, operator: AbstractOperator):
        cls.OPERATOR_MAP[operator.SYMBOL] = operator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants