Add a __init__ method to *cls*. If *frozen* is True, make it immutable. This function used to be part of _make. It wasn't used anymore however the tests for it are still useful to test the behavior of _make_init.
(cls, frozen)
| 78 | |
| 79 | |
| 80 | def _add_init(cls, frozen): |
| 81 | class="st">""" |
| 82 | Add a __init__ method to *cls*. If *frozen* is True, make it immutable. |
| 83 | |
| 84 | This function used to be part of _make. It wasn&class="cm">#x27;t used anymore however |
| 85 | the tests for it are still useful to test the behavior of _make_init. |
| 86 | class="st">""" |
| 87 | has_pre_init = bool(getattr(cls, class="st">"__attrs_pre_init__", False)) |
| 88 | |
| 89 | script, globs, annots = _make_init_script( |
| 90 | cls, |
| 91 | cls.__attrs_attrs__, |
| 92 | has_pre_init, |
| 93 | ( |
| 94 | len(inspect.signature(cls.__attrs_pre_init__).parameters) > 1 |
| 95 | if has_pre_init |
| 96 | else False |
| 97 | ), |
| 98 | getattr(cls, class="st">"__attrs_post_init__", False), |
| 99 | frozen, |
| 100 | class="st">"__slots__" in cls.__dict__, |
| 101 | cache_hash=False, |
| 102 | base_attr_map={}, |
| 103 | is_exc=False, |
| 104 | cls_on_setattr=None, |
| 105 | attrs_init=False, |
| 106 | ) |
| 107 | _compile_and_eval(script, globs, filename=class="st">"__init__") |
| 108 | cls.__init__ = globs[class="st">"__init__"] |
| 109 | cls.__init__.__annotations__ = annots |
| 110 | return cls |
| 111 | |
| 112 | |
| 113 | class InitC: |
no test coverage detected