You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

dataloader_context.py 736B

1 year ago
12345678910111213141516171819202122232425262728
  1. from typing import TYPE_CHECKING
  2. if TYPE_CHECKING:
  3. from .data_loader import DataLoader
  4. class classproperty(property):
  5. def __get__(self, obj, objtype=None):
  6. return super(classproperty, self).__get__(objtype)
  7. def __set__(self, obj, value):
  8. super(classproperty, self).__set__(type(obj), value)
  9. def __delete__(self, obj):
  10. super(classproperty, self).__delete__(type(obj))
  11. class DataloaderContext:
  12. _instance: 'DataloaderContext' = None
  13. def __init__(self) -> None:
  14. self.dataloader: 'DataLoader' = None
  15. @classproperty
  16. def instance(cls) -> 'DataloaderContext':
  17. if cls._instance is None:
  18. cls._instance = DataloaderContext()
  19. return cls._instance