Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
HardNorth committed Dec 4, 2024
1 parent b444b14 commit f49eb08
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions reportportal_client/_internal/static/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

from abc import ABCMeta as _ABCMeta, abstractmethod

__all__ = ["AbstractBaseClass", "abstractmethod"]
__all__ = ['AbstractBaseClass', 'abstractmethod']


class AbstractBaseClass(_ABCMeta):
Expand All @@ -35,19 +35,19 @@ class Implementation(Interface):
i = Implementation() -> success
"""

_abc_registry = []
_abc_registry = set()

def __call__(cls, *args, **kwargs):
"""Disable instantiation for the interface classes."""
if cls.__name__ in AbstractBaseClass._abc_registry:
raise TypeError("No instantiation allowed for Interface-Class '{}'. Please inherit.".format(cls.__name__))
raise TypeError(f'No instantiation allowed for Interface-Class "{cls.__name__}". Please inherit.')

result = super(AbstractBaseClass, cls).__call__(*args, **kwargs)
return result

def __new__(mcs, name, bases, namespace):
"""Register instance of the implementation class."""
class_ = super(AbstractBaseClass, mcs).__new__(mcs, name, bases, namespace)
if namespace.get("__metaclass__") is AbstractBaseClass:
mcs._abc_registry.append(name)
if namespace.get('__metaclass__') is AbstractBaseClass:
mcs._abc_registry.add(name)
return class_

0 comments on commit f49eb08

Please sign in to comment.