def background(self, bg): if isinstance(bg, background.Background): self._background = bg self._background.owner = self elif isinstance(bg, type) and issubclass(bg, background.Background): self._background = bg(owner=self) elif isinstance(bg, str): try: self._background = findattr(background, bg)(owner=self) except AttributeError: msg = (f'Background "{bg}" not defined. ' f'Please add it to ``background.py``') self._background = background.Background(owner=self) warnings.warn(msg)
def background(self, bg): if isinstance(bg, background.Background): self._background = bg self._background.owner = self elif isinstance(bg, type) and issubclass(bg, background.Background): self._background = bg(owner=self) elif isinstance(bg, str): try: self._background = find_content( bg, valid_classes=[background.Background])(owner=self) except exceptions.ContentNotFound: msg = ( f'Background "{bg}" not defined. Please add it to ``background.py``' ) self._background = background.Background(owner=self) warnings.warn(msg)