(cls)
| 1509 | on_setattr = setters.pipe(*on_setattr) |
| 1510 | |
| 1511 | def wrap(cls): |
| 1512 | |
| 1513 | if getattr(cls, "__class__", None) is None: |
| 1514 | raise TypeError("attrs only works with new-style classes.") |
| 1515 | |
| 1516 | is_frozen = frozen or _has_frozen_base_class(cls) |
| 1517 | is_exc = auto_exc is True and issubclass(cls, BaseException) |
| 1518 | has_own_setattr = auto_detect and _has_own_attribute( |
| 1519 | cls, "__setattr__" |
| 1520 | ) |
| 1521 | |
| 1522 | if has_own_setattr and is_frozen: |
| 1523 | raise ValueError("Can't freeze a class with a custom __setattr__.") |
| 1524 | |
| 1525 | builder = _ClassBuilder( |
| 1526 | cls, |
| 1527 | these, |
| 1528 | slots, |
| 1529 | is_frozen, |
| 1530 | weakref_slot, |
| 1531 | _determine_whether_to_implement( |
| 1532 | cls, |
| 1533 | getstate_setstate, |
| 1534 | auto_detect, |
| 1535 | ("__getstate__", "__setstate__"), |
| 1536 | default=slots, |
| 1537 | ), |
| 1538 | auto_attribs, |
| 1539 | kw_only, |
| 1540 | cache_hash, |
| 1541 | is_exc, |
| 1542 | collect_by_mro, |
| 1543 | on_setattr, |
| 1544 | has_own_setattr, |
| 1545 | field_transformer, |
| 1546 | ) |
| 1547 | if _determine_whether_to_implement( |
| 1548 | cls, repr, auto_detect, ("__repr__",) |
| 1549 | ): |
| 1550 | builder.add_repr(repr_ns) |
| 1551 | if str is True: |
| 1552 | builder.add_str() |
| 1553 | |
| 1554 | eq = _determine_whether_to_implement( |
| 1555 | cls, eq_, auto_detect, ("__eq__", "__ne__") |
| 1556 | ) |
| 1557 | if not is_exc and eq is True: |
| 1558 | builder.add_eq() |
| 1559 | if not is_exc and _determine_whether_to_implement( |
| 1560 | cls, order_, auto_detect, ("__lt__", "__le__", "__gt__", "__ge__") |
| 1561 | ): |
| 1562 | builder.add_order() |
| 1563 | |
| 1564 | builder.add_setattr() |
| 1565 | |
| 1566 | if ( |
| 1567 | hash_ is None |
| 1568 | and auto_detect is True |
no test coverage detected