def resolve_topic(topic): """Return class described by given topic. Args: topic: A string describing a class. Returns: A class. Raises: TopicResolutionError: If there is no such class. """ # Substitute one topic for another, if so defined. # - this allows classes to be moved and renamed topic = substitutions.get(topic, topic) # Partition topic into module and class names. module_name, _, class_name = topic.partition('#') # Import the module. try: module = importlib.import_module(module_name) except ImportError as e: raise TopicResolutionError("{}: {}".format(topic, e)) # Identify the class. try: cls = resolve_attr(module, class_name) except AttributeError as e: raise TopicResolutionError("{}: {}".format(topic, e)) return cls
def resolve_topic(topic: str) -> Any: """ Resolves topic to the object it references. :param topic: A string describing a code object (e.g. an object class). :raises TopicResolutionError: If there is no such class. :return: Code object that the topic references. """ # Substitute one topic for another, if so defined. # - this allows classes to be moved and renamed topic = substitutions.get(topic, topic) # Partition topic into module and class names. module_name, _, class_name = topic.partition("#") # Import the module. try: module = importlib.import_module(module_name) except ImportError as e: raise TopicResolutionError("{}: {}".format(topic, e)) # Identify the class. try: cls = resolve_attr(module, class_name) except AttributeError as e: raise TopicResolutionError("{}: {}".format(topic, e)) return cls
def resolve_domain_topic(topic): """Return domain class described by given topic. Args: topic: A string describing a domain class. Returns: A domain class. Raises: TopicResolutionError: If there is no such domain class. """ try: module_name, _, class_name = topic.partition('#') module = importlib.import_module(module_name) except ImportError as e: raise TopicResolutionError("{}: {}".format(topic, e)) try: cls = resolve_attr(module, class_name) except AttributeError as e: raise TopicResolutionError("{}: {}".format(topic, e)) return cls