Skip to content

fix(rules): populate `all_rules` correctly again

Claudia Pellegrino requested to merge auerhuhn/namcap:fix-all-rules into master

Commit f4ef0624 from !41 (merged) changed AbstractRule so it inherits from ABC.
This inadvertently introduced a regression so the all_rules dict became empty, essentially breaking all of namcap.

The existing logic in __init__.py that populates all_rules uses a filter which tries to let only things pass that are classes:

type(v) == type

However, this really means "check that v is a class with no superclass," so this check only allows top-level classes (inheriting directly from object) to pass.

That still worked by accident because there was no inheritance at all, but letting AbstractRule inherit from ABC finally broke it.

To fix this regression, this MR changes the check to:

isinstance(v, type)

which means "check that v is a class."

There is no unit test that tests (or interacts with) all_rules, which explains why this went past CI checks.

Merge request reports