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

RuleCollection Class? #81

Open
MementoRC opened this issue Jan 8, 2023 · 0 comments
Open

RuleCollection Class? #81

MementoRC opened this issue Jan 8, 2023 · 0 comments

Comments

@MementoRC
Copy link
Contributor

MementoRC commented Jan 8, 2023

I found it practical to group Rules into collections in order to resolve some of the MaybeOverlap that I was getting by having too many chained actions.

For background, I think I use the chained actions a bit too much and I am reluctant to have lots of Rules (I get lost as to naming them and knowing which is faulty), but then, I end-up with some MaybeOverlap because I don't want to break a Rule into many rules.

So, I thought, it would be great if I could still target the changes, say for a ClassDef, but instead of doing the yield, or creating many rules, I would have a Collection of Rules, each one completing (instead of piling up the chain) but within the same Session (pretty sure this is not very clear)

For example:
My session would be simple

Session(rules=[InitializeProcessing, ModuleProcessing, ClassProcessing, FunctionProcessing])

and for example, my ClassProcessing would be:

class ClassProcessing(RuleCollection):
   rules: list[type[Rule] = [ChangeClassName, AddFundctionB, MoveFuncAtoB, ChangeFuncA, etc...]

class ChangeClassName(Rule):
   ...

The way I am currently clunky-ing it is by:

class _ChangeClassName(Rule):
    ...
class ClassProcessing(Rule):
   def match(self, node: ast.AST) -> Iterator[BaseAction]:
      if isinstance(statement, ast.AsyncFunctionDef):
                for remove in _ChangeClassName(self.context).match(statement):
                    yield remove

But then if I push this too far ... BAAAM MaybeOverlap

I prepared a PR for it, but any feedback on better ways (or surely I could overlooking something!) would be welcome

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

No branches or pull requests

1 participant