File size: 3,241 Bytes
4a51346
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# SPDX-License-Identifier: MIT

"""
Classes Without Boilerplate
"""

from functools import partial
from typing import Callable

from . import converters, exceptions, filters, setters, validators
from ._cmp import cmp_using
from ._config import get_run_validators, set_run_validators
from ._funcs import asdict, assoc, astuple, evolve, has, resolve_types
from ._make import (
    NOTHING,
    Attribute,
    Factory,
    attrib,
    attrs,
    fields,
    fields_dict,
    make_class,
    validate,
)
from ._next_gen import define, field, frozen, mutable
from ._version_info import VersionInfo


s = attributes = attrs
ib = attr = attrib
dataclass = partial(attrs, auto_attribs=True)  # happy Easter ;)


class AttrsInstance:
    pass


__all__ = [
    "Attribute",
    "AttrsInstance",
    "Factory",
    "NOTHING",
    "asdict",
    "assoc",
    "astuple",
    "attr",
    "attrib",
    "attributes",
    "attrs",
    "cmp_using",
    "converters",
    "define",
    "evolve",
    "exceptions",
    "field",
    "fields",
    "fields_dict",
    "filters",
    "frozen",
    "get_run_validators",
    "has",
    "ib",
    "make_class",
    "mutable",
    "resolve_types",
    "s",
    "set_run_validators",
    "setters",
    "validate",
    "validators",
]


def _make_getattr(mod_name: str) -> Callable:
    """
    Create a metadata proxy for packaging information that uses *mod_name* in
    its warnings and errors.
    """

    def __getattr__(name: str) -> str:
        dunder_to_metadata = {
            "__title__": "Name",
            "__copyright__": "",
            "__version__": "version",
            "__version_info__": "version",
            "__description__": "summary",
            "__uri__": "",
            "__url__": "",
            "__author__": "",
            "__email__": "",
            "__license__": "license",
        }
        if name not in dunder_to_metadata.keys():
            raise AttributeError(f"module {mod_name} has no attribute {name}")

        import sys
        import warnings

        if sys.version_info < (3, 8):
            from importlib_metadata import metadata
        else:
            from importlib.metadata import metadata

        if name != "__version_info__":
            warnings.warn(
                f"Accessing {mod_name}.{name} is deprecated and will be "
                "removed in a future release. Use importlib.metadata directly "
                "to query for attrs's packaging metadata.",
                DeprecationWarning,
                stacklevel=2,
            )

        meta = metadata("attrs")
        if name == "__license__":
            return "MIT"
        elif name == "__copyright__":
            return "Copyright (c) 2015 Hynek Schlawack"
        elif name in ("__uri__", "__url__"):
            return meta["Project-URL"].split(" ", 1)[-1]
        elif name == "__version_info__":
            return VersionInfo._from_version_string(meta["version"])
        elif name == "__author__":
            return meta["Author-email"].rsplit(" ", 1)[0]
        elif name == "__email__":
            return meta["Author-email"].rsplit("<", 1)[1][:-1]

        return meta[dunder_to_metadata[name]]

    return __getattr__


__getattr__ = _make_getattr(__name__)