Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
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.

__init__.py 3.2KB

1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. # SPDX-License-Identifier: MIT
  2. """
  3. Classes Without Boilerplate
  4. """
  5. from functools import partial
  6. from typing import Callable
  7. from . import converters, exceptions, filters, setters, validators
  8. from ._cmp import cmp_using
  9. from ._config import get_run_validators, set_run_validators
  10. from ._funcs import asdict, assoc, astuple, evolve, has, resolve_types
  11. from ._make import (
  12. NOTHING,
  13. Attribute,
  14. Factory,
  15. attrib,
  16. attrs,
  17. fields,
  18. fields_dict,
  19. make_class,
  20. validate,
  21. )
  22. from ._next_gen import define, field, frozen, mutable
  23. from ._version_info import VersionInfo
  24. s = attributes = attrs
  25. ib = attr = attrib
  26. dataclass = partial(attrs, auto_attribs=True) # happy Easter ;)
  27. class AttrsInstance:
  28. pass
  29. __all__ = [
  30. "Attribute",
  31. "AttrsInstance",
  32. "Factory",
  33. "NOTHING",
  34. "asdict",
  35. "assoc",
  36. "astuple",
  37. "attr",
  38. "attrib",
  39. "attributes",
  40. "attrs",
  41. "cmp_using",
  42. "converters",
  43. "define",
  44. "evolve",
  45. "exceptions",
  46. "field",
  47. "fields",
  48. "fields_dict",
  49. "filters",
  50. "frozen",
  51. "get_run_validators",
  52. "has",
  53. "ib",
  54. "make_class",
  55. "mutable",
  56. "resolve_types",
  57. "s",
  58. "set_run_validators",
  59. "setters",
  60. "validate",
  61. "validators",
  62. ]
  63. def _make_getattr(mod_name: str) -> Callable:
  64. """
  65. Create a metadata proxy for packaging information that uses *mod_name* in
  66. its warnings and errors.
  67. """
  68. def __getattr__(name: str) -> str:
  69. dunder_to_metadata = {
  70. "__title__": "Name",
  71. "__copyright__": "",
  72. "__version__": "version",
  73. "__version_info__": "version",
  74. "__description__": "summary",
  75. "__uri__": "",
  76. "__url__": "",
  77. "__author__": "",
  78. "__email__": "",
  79. "__license__": "license",
  80. }
  81. if name not in dunder_to_metadata.keys():
  82. raise AttributeError(f"module {mod_name} has no attribute {name}")
  83. import sys
  84. import warnings
  85. if sys.version_info < (3, 8):
  86. from importlib_metadata import metadata
  87. else:
  88. from importlib.metadata import metadata
  89. if name != "__version_info__":
  90. warnings.warn(
  91. f"Accessing {mod_name}.{name} is deprecated and will be "
  92. "removed in a future release. Use importlib.metadata directly "
  93. "to query for attrs's packaging metadata.",
  94. DeprecationWarning,
  95. stacklevel=2,
  96. )
  97. meta = metadata("attrs")
  98. if name == "__license__":
  99. return "MIT"
  100. elif name == "__copyright__":
  101. return "Copyright (c) 2015 Hynek Schlawack"
  102. elif name in ("__uri__", "__url__"):
  103. return meta["Project-URL"].split(" ", 1)[-1]
  104. elif name == "__version_info__":
  105. return VersionInfo._from_version_string(meta["version"])
  106. elif name == "__author__":
  107. return meta["Author-email"].rsplit(" ", 1)[0]
  108. elif name == "__email__":
  109. return meta["Author-email"].rsplit("<", 1)[1][:-1]
  110. return meta[dunder_to_metadata[name]]
  111. return __getattr__
  112. __getattr__ = _make_getattr(__name__)