Is there a way to get rid of the warning:
Unresolved reference 'DeviceManager' ...
for this kind of singleton pattern?
class DeviceManager:
""" Holds all devices and manages their distributed use. """
instance: Union[DeviceManager, None] = None # warning Unresolved reference 'DeviceManager'
@staticmethod
def get_instance() -> DeviceManager: # warning Unresolved reference 'DeviceManager'
""" Singleton instance. """
if DeviceManager.instance is None:
DeviceManager()
return cast(DeviceManager, DeviceManager.instance)
def __init__(self) -> None:
""" Create instance. """
if DeviceManager.instance is None:
DeviceManager.instance = self
else:
raise Exception("This class is a singleton!")
Screenshot: