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

Add duplicate name check for subclasses #207

Merged
merged 1 commit into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions capsula/_context/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
_subclass_registry: Final[dict[str, type[ContextBase]]] = {}

def __init_subclass__(cls, **kwargs: Any) -> None:
if cls.__name__ in cls._subclass_registry:
msg = f"Duplicate context name: {cls.__name__}"
raise ValueError(msg)

Check warning on line 14 in capsula/_context/_base.py

View check run for this annotation

Codecov / codecov/patch

capsula/_context/_base.py#L13-L14

Added lines #L13 - L14 were not covered by tests
cls._subclass_registry[cls.__name__] = cls
super().__init_subclass__(**kwargs)

Expand Down
3 changes: 3 additions & 0 deletions capsula/_reporter/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
_subclass_registry: Final[dict[str, type[ReporterBase]]] = {}

def __init_subclass__(cls, **kwargs: Any) -> None:
if cls.__name__ in cls._subclass_registry:
msg = f"Duplicate reporter name: {cls.__name__}"
raise ValueError(msg)

Check warning on line 18 in capsula/_reporter/_base.py

View check run for this annotation

Codecov / codecov/patch

capsula/_reporter/_base.py#L17-L18

Added lines #L17 - L18 were not covered by tests
cls._subclass_registry[cls.__name__] = cls
super().__init_subclass__(**kwargs)

Expand Down
3 changes: 3 additions & 0 deletions capsula/_watcher/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
_subclass_registry: Final[dict[str, type[WatcherBase]]] = {}

def __init_subclass__(cls, **kwargs: Any) -> None:
if cls.__name__ in cls._subclass_registry:
msg = f"Duplicate watcher name: {cls.__name__}"
raise ValueError(msg)

Check warning on line 21 in capsula/_watcher/_base.py

View check run for this annotation

Codecov / codecov/patch

capsula/_watcher/_base.py#L20-L21

Added lines #L20 - L21 were not covered by tests
cls._subclass_registry[cls.__name__] = cls
super().__init_subclass__(**kwargs)

Expand Down