File tree Expand file tree Collapse file tree 5 files changed +43
-8
lines changed Expand file tree Collapse file tree 5 files changed +43
-8
lines changed Original file line number Diff line number Diff line change 1212__license__ = 'GPL-3.0-or-later'
1313__title__ = 'design-pytterns'
1414__url__ = 'https://github.com/Alchemy-Meister/python-design-patterns'
15- __version__ = '0.2 .0'
15+ __version__ = '0.3 .0'
Original file line number Diff line number Diff line change 1111import logging
1212from typing import MutableMapping , Type
1313
14+ from design_pytterns .errors import UnidentifiableSubclassError
1415from design_pytterns .interfaces import SubclassIdentifiable
1516
1617
@@ -30,18 +31,19 @@ class ConcreteSubclassRegister():
3031
3132 Raises
3233 ------
33- TypeError
34+ UnidentifiableSubclassError
3435 If `base_class` does not inherit from SubclassIdentifiable.
3536
37+ .. versionchanged:: 0.3.0 raises `UnidentifiableSubclassError` instead of
38+ `TypeError`.
39+
3640 """
3741
3842 __LOGGER = logging .getLogger (__name__ )
3943
4044 def __init__ (self , base_class : Type [SubclassIdentifiable ]) -> None :
4145 if not issubclass (base_class , SubclassIdentifiable ):
42- raise TypeError (
43- f'unidentifiable base class: { repr (base_class .__name__ )} '
44- )
46+ raise UnidentifiableSubclassError (base_class )
4547
4648 self .registered_classes = self ._register_subclasses (base_class )
4749
Original file line number Diff line number Diff line change 77"""Subpackage with the exception definitions."""
88
99from .design_pyttern_error import DesignPytternError
10+ from .unidentifiable_subclass_error import UnidentifiableSubclassError
1011from .unregistered_class_id_error import UnregisteredClassIdError
1112
12- __all__ = ['DesignPytternError' , 'UnregisteredClassIdError' ]
13+ __all__ = [
14+ 'DesignPytternError' ,
15+ 'UnidentifiableSubclassError' ,
16+ 'UnregisteredClassIdError'
17+ ]
Original file line number Diff line number Diff line change 1+ #! /usr/bin/env python3
2+
3+ # SPDX-FileCopyrightText: 2020 Alchemy-Meister
4+ #
5+ # SPDX-License-Identifier: GPL-3.0-or-later
6+
7+ """Unidentifiable subclass error."""
8+
9+ from .design_pyttern_error import DesignPytternError
10+
11+
12+ class UnidentifiableSubclassError (DesignPytternError ):
13+ """
14+ Raised when the base class of a subclass register is not identifiable.
15+
16+ Parameters
17+ ----------
18+ base_class : type
19+ Unidentifiable type that raised the exception.
20+
21+ """
22+
23+ def __init__ (self , base_class : type ):
24+ super ().__init__ (
25+ message = f'unidentifiable base class: { repr (base_class .__name__ )} '
26+ )
Original file line number Diff line number Diff line change 99from pytest import fixture , raises
1010
1111from design_pytterns .factory import SubclassFactory
12- from design_pytterns .errors import UnregisteredClassIdError
12+ from design_pytterns .errors import (
13+ UnidentifiableSubclassError , UnregisteredClassIdError
14+ )
1315from design_pytterns .interfaces import SubclassIdentifiable
1416
1517
@@ -85,7 +87,7 @@ class MyUnidentifiableBaseClass():
8587 class _UnidentifiableClass1 (MyUnidentifiableBaseClass ):
8688 pass
8789
88- with raises (TypeError ):
90+ with raises (UnidentifiableSubclassError ):
8991 SubclassFactory (MyUnidentifiableBaseClass )
9092
9193
You can’t perform that action at this time.
0 commit comments