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

Make a mixin class for simple explanations #33

Open
LivInTheLookingGlass opened this issue Nov 3, 2022 · 2 comments
Open

Make a mixin class for simple explanations #33

LivInTheLookingGlass opened this issue Nov 3, 2022 · 2 comments

Comments

@LivInTheLookingGlass
Copy link
Owner

LivInTheLookingGlass commented Nov 3, 2022

Allow a template, something like the below (untested)

class DescriptionMixin:
    _abstract_template: ClassVar[str] = None  # type: ignore[assignment]
    _specific_template: ClassVar[str | None] = None

    def explain_abstract(self, *args):
        return self._abstract_template.format(self=self)

    def explain_specific(self, market, *args):
        if self._specific_template is not None:
            value = self.value(market)
            return self._specific_specific.format(self=self, market=market, value=value)
        return super().explain_specific(market, *args)
@devbazregari
Copy link

devbazregari commented Nov 4, 2022

@LivInTheLookingGlass
hi buddy. I hope you're doing great, would you please explain a bit more about the task?

@LivInTheLookingGlass
Copy link
Owner Author

There are a whole bunch of Rule subclasses where they have a little stub method to return an explanation. If this mixin class is used, then that can get translated to a class variable instead, which would eliminate a bunch of CodeClimate complaints about duplicated code

Probably the easiest place to start would be with the manifold user rules?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

2 participants