Return the tuple of ``attrs`` attributes for a class. The tuple also allows accessing the fields by their names (see below for examples). :param type cls: Class to introspect. :raise TypeError: If *cls* is not a class. :raise attr.exceptions.NotAnAttrsClassError: If *cls*
(cls)
| 2027 | |
| 2028 | |
| 2029 | def fields(cls): |
| 2030 | """ |
| 2031 | Return the tuple of ``attrs`` attributes for a class. |
| 2032 | |
| 2033 | The tuple also allows accessing the fields by their names (see below for |
| 2034 | examples). |
| 2035 | |
| 2036 | :param type cls: Class to introspect. |
| 2037 | |
| 2038 | :raise TypeError: If *cls* is not a class. |
| 2039 | :raise attr.exceptions.NotAnAttrsClassError: If *cls* is not an ``attrs`` |
| 2040 | class. |
| 2041 | |
| 2042 | :rtype: tuple (with name accessors) of `attrs.Attribute` |
| 2043 | |
| 2044 | .. versionchanged:: 16.2.0 Returned tuple allows accessing the fields |
| 2045 | by name. |
| 2046 | """ |
| 2047 | if not isclass(cls): |
| 2048 | raise TypeError("Passed object must be a class.") |
| 2049 | attrs = getattr(cls, "__attrs_attrs__", None) |
| 2050 | if attrs is None: |
| 2051 | raise NotAnAttrsClassError( |
| 2052 | "{cls!r} is not an attrs-decorated class.".format(cls=cls) |
| 2053 | ) |
| 2054 | return attrs |
| 2055 | |
| 2056 | |
| 2057 | def fields_dict(cls): |