15
15
16
16
from abc import ABCMeta as _ABCMeta , abstractmethod
17
17
18
- __all__ = [" AbstractBaseClass" , " abstractmethod" ]
18
+ __all__ = [' AbstractBaseClass' , ' abstractmethod' ]
19
19
20
20
21
21
class AbstractBaseClass (_ABCMeta ):
@@ -35,19 +35,19 @@ class Implementation(Interface):
35
35
i = Implementation() -> success
36
36
"""
37
37
38
- _abc_registry = []
38
+ _abc_registry = set ()
39
39
40
40
def __call__ (cls , * args , ** kwargs ):
41
41
"""Disable instantiation for the interface classes."""
42
42
if cls .__name__ in AbstractBaseClass ._abc_registry :
43
- raise TypeError (" No instantiation allowed for Interface-Class '{}' . Please inherit." . format ( cls . __name__ ) )
43
+ raise TypeError (f' No instantiation allowed for Interface-Class " { cls . __name__ } " . Please inherit.' )
44
44
45
45
result = super (AbstractBaseClass , cls ).__call__ (* args , ** kwargs )
46
46
return result
47
47
48
48
def __new__ (mcs , name , bases , namespace ):
49
49
"""Register instance of the implementation class."""
50
50
class_ = super (AbstractBaseClass , mcs ).__new__ (mcs , name , bases , namespace )
51
- if namespace .get (" __metaclass__" ) is AbstractBaseClass :
52
- mcs ._abc_registry .append (name )
51
+ if namespace .get (' __metaclass__' ) is AbstractBaseClass :
52
+ mcs ._abc_registry .add (name )
53
53
return class_
0 commit comments