Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/attr/__init__.py: 75%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

32 statements  

1# SPDX-License-Identifier: MIT 

2 

3""" 

4Classes Without Boilerplate 

5""" 

6 

7from functools import partial 

8from typing import Callable 

9 

10from . import converters, exceptions, filters, setters, validators 

11from ._cmp import cmp_using 

12from ._compat import Protocol 

13from ._config import get_run_validators, set_run_validators 

14from ._funcs import asdict, assoc, astuple, evolve, has, resolve_types 

15from ._make import ( 

16 NOTHING, 

17 Attribute, 

18 Converter, 

19 Factory, 

20 attrib, 

21 attrs, 

22 fields, 

23 fields_dict, 

24 make_class, 

25 validate, 

26) 

27from ._next_gen import define, field, frozen, mutable 

28from ._version_info import VersionInfo 

29 

30 

31s = attributes = attrs 

32ib = attr = attrib 

33dataclass = partial(attrs, auto_attribs=True) # happy Easter ;) 

34 

35 

36class AttrsInstance(Protocol): 

37 pass 

38 

39 

40__all__ = [ 

41 "Attribute", 

42 "AttrsInstance", 

43 "Converter", 

44 "Factory", 

45 "NOTHING", 

46 "asdict", 

47 "assoc", 

48 "astuple", 

49 "attr", 

50 "attrib", 

51 "attributes", 

52 "attrs", 

53 "cmp_using", 

54 "converters", 

55 "define", 

56 "evolve", 

57 "exceptions", 

58 "field", 

59 "fields", 

60 "fields_dict", 

61 "filters", 

62 "frozen", 

63 "get_run_validators", 

64 "has", 

65 "ib", 

66 "make_class", 

67 "mutable", 

68 "resolve_types", 

69 "s", 

70 "set_run_validators", 

71 "setters", 

72 "validate", 

73 "validators", 

74] 

75 

76 

77def _make_getattr(mod_name: str) -> Callable: 

78 """ 

79 Create a metadata proxy for packaging information that uses *mod_name* in 

80 its warnings and errors. 

81 """ 

82 

83 def __getattr__(name: str) -> str: 

84 if name not in ("__version__", "__version_info__"): 

85 msg = f"module {mod_name} has no attribute {name}" 

86 raise AttributeError(msg) 

87 

88 try: 

89 from importlib.metadata import metadata 

90 except ImportError: 

91 from importlib_metadata import metadata 

92 

93 meta = metadata("attrs") 

94 

95 if name == "__version_info__": 

96 return VersionInfo._from_version_string(meta["version"]) 

97 

98 return meta["version"] 

99 

100 return __getattr__ 

101 

102 

103__getattr__ = _make_getattr(__name__)