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

Prevent duplicated rule exception when importing rules and filters #87

Merged
merged 5 commits into from
Dec 19, 2024

Conversation

npeshkov
Copy link
Contributor

@npeshkov npeshkov commented Dec 13, 2024

Fixes #85.

Implementation

  • Skip adding imported rules and rule filters to rule registry.
  • Split tests/rules/example.py into tests/rules/rules.py and tests/rules/rule_filters.py.
  • Test Duplicated exception is not raised by adding an imported skip_schemaX rule filter.

Note

Both rules and rule filters can be imported now, but the existing tests cover only rule filters.

Copy link
Contributor

@jochemvandooren jochemvandooren left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only two lines to fix it, that's nice! 🙌

@@ -62,6 +62,9 @@ def _load(self, namespace_name: str) -> None:
module = importlib.import_module(module_name)
for obj_name in dir(module):
obj = module.__dict__[obj_name]
# skip adding objects imported from other modules
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# skip adding objects imported from other modules
# Skip adding objects imported from other modules

🤓

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, should be fixed now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't fully understand why we need a full rules/imported section for this, as we are just fixing a bug. Wouldn't it be simpler to split the existing examples into rules.py and rule_filters.py, add a filter in rule_filters.py that is imported in rules.py? Then it's also a practical use-case that we expect users to have

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I have split rules/example.py into rules.py and rule_filters.py, and added a rule filter which is now imported into rules.py. The structure should look better now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ordering of objects has changed, because files were renamed:

  • example used to be before nested,
  • now rules and rule_filters come after nested.

Copy link
Contributor

@jochemvandooren jochemvandooren left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! 🤩

@jochemvandooren
Copy link
Contributor

I will give @matthieucan the final say as he worked on the rule registry

Copy link
Contributor

@matthieucan matthieucan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tiny comment, but approving. Thanks!

CHANGELOG.md Outdated Show resolved Hide resolved
@npeshkov npeshkov enabled auto-merge (squash) December 19, 2024 07:19
@npeshkov npeshkov merged commit 2c47aa9 into master Dec 19, 2024
4 checks passed
@npeshkov npeshkov deleted the npeshkov/85/allow_imports branch December 19, 2024 07:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Bug: Importing a definition is counted by rule registry
3 participants