Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/attr/__init__.py: 80%
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, Literal, Protocol
10from . import converters, exceptions, filters, setters, validators
11from ._cmp import cmp_using
12from ._config import get_run_validators, set_run_validators
13from ._funcs import asdict, assoc, astuple, has, resolve_types
14from ._make import (
15 NOTHING,
16 Attribute,
17 Converter,
18 Factory,
19 _Nothing,
20 attrib,
21 attrs,
22 evolve,
23 fields,
24 fields_dict,
25 make_class,
26 validate,
27)
28from ._next_gen import define, field, frozen, mutable
29from ._version_info import VersionInfo
32s = attributes = attrs
33ib = attr = attrib
34dataclass = partial(attrs, auto_attribs=True) # happy Easter ;)
37class AttrsInstance(Protocol):
38 pass
41NothingType = Literal[_Nothing.NOTHING]
43__all__ = [
44 "NOTHING",
45 "Attribute",
46 "AttrsInstance",
47 "Converter",
48 "Factory",
49 "NothingType",
50 "asdict",
51 "assoc",
52 "astuple",
53 "attr",
54 "attrib",
55 "attributes",
56 "attrs",
57 "cmp_using",
58 "converters",
59 "define",
60 "evolve",
61 "exceptions",
62 "field",
63 "fields",
64 "fields_dict",
65 "filters",
66 "frozen",
67 "get_run_validators",
68 "has",
69 "ib",
70 "make_class",
71 "mutable",
72 "resolve_types",
73 "s",
74 "set_run_validators",
75 "setters",
76 "validate",
77 "validators",
78]
81def _make_getattr(mod_name: str) -> Callable:
82 """
83 Create a metadata proxy for packaging information that uses *mod_name* in
84 its warnings and errors.
85 """
87 def __getattr__(name: str) -> str:
88 if name not in ("__version__", "__version_info__"):
89 msg = f"module {mod_name} has no attribute {name}"
90 raise AttributeError(msg)
92 from importlib.metadata import metadata
94 meta = metadata("attrs")
96 if name == "__version_info__":
97 return VersionInfo._from_version_string(meta["version"])
99 return meta["version"]
101 return __getattr__
104__getattr__ = _make_getattr(__name__)