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.

39 lines
1.1KB

  1. # This file is dual licensed under the terms of the Apache License, Version
  2. # 2.0, and the BSD License. See the LICENSE file in the root of this repository
  3. # for complete details.
  4. from __future__ import absolute_import, division, print_function
  5. import sys
  6. from ._typing import TYPE_CHECKING
  7. if TYPE_CHECKING: # pragma: no cover
  8. from typing import Any, Dict, Tuple, Type
  9. PY2 = sys.version_info[0] == 2
  10. PY3 = sys.version_info[0] == 3
  11. # flake8: noqa
  12. if PY3:
  13. string_types = (str,)
  14. else:
  15. string_types = (basestring,)
  16. def with_metaclass(meta, *bases):
  17. # type: (Type[Any], Tuple[Type[Any], ...]) -> Any
  18. """
  19. Create a base class with a metaclass.
  20. """
  21. # This requires a bit of explanation: the basic idea is to make a dummy
  22. # metaclass for one level of class instantiation that replaces itself with
  23. # the actual metaclass.
  24. class metaclass(meta): # type: ignore
  25. def __new__(cls, name, this_bases, d):
  26. # type: (Type[Any], str, Tuple[Any], Dict[Any, Any]) -> Any
  27. return meta(name, bases, d)
  28. return type.__new__(metaclass, "temporary_class", (), {})