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
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
1# SPDX-License-Identifier: MIT
3"""
4Classes Without Boilerplate
5"""
7from functools import partial
8from typing import Callable
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
31s = attributes = attrs
32ib = attr = attrib
33dataclass = partial(attrs, auto_attribs=True) # happy Easter ;)
36class AttrsInstance(Protocol):
37 pass
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]
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 """
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)
88 try:
89 from importlib.metadata import metadata
90 except ImportError:
91 from importlib_metadata import metadata
93 meta = metadata("attrs")
95 if name == "__version_info__":
96 return VersionInfo._from_version_string(meta["version"])
98 return meta["version"]
100 return __getattr__
103__getattr__ = _make_getattr(__name__)