:param items: dict or set of indexes which will be normalized :param v_length: length of sequence indexes of which will be >>> self._normalize_indexes({0: True, -2: True, -1: True}, 4) {0: True, 2: True, 3: True} >>> self._normalize_indexes({'__all__': True}
(self, items: 'MappingIntStrAny', v_length: int)
| 521 | return item if not self.is_true(item) else None |
| 522 | |
| 523 | def _normalize_indexes(self, items: 'MappingIntStrAny', v_length: int) -> 'DictIntStrAny': |
| 524 | """ |
| 525 | :param items: dict or set of indexes which will be normalized |
| 526 | :param v_length: length of sequence indexes of which will be |
| 527 | |
| 528 | >>> self._normalize_indexes({0: True, -2: True, -1: True}, 4) |
| 529 | {0: True, 2: True, 3: True} |
| 530 | >>> self._normalize_indexes({'__all__': True}, 4) |
| 531 | {0: True, 1: True, 2: True, 3: True} |
| 532 | """ |
| 533 | |
| 534 | normalized_items: 'DictIntStrAny' = {} |
| 535 | all_items = None |
| 536 | for i, v in items.items(): |
| 537 | if not (isinstance(v, Mapping) or isinstance(v, AbstractSet) or self.is_true(v)): |
| 538 | raise TypeError(f'Unexpected type of exclude value for index "{i}" {v.__class__}') |
| 539 | if i == '__all__': |
| 540 | all_items = self._coerce_value(v) |
| 541 | continue |
| 542 | if not isinstance(i, int): |
| 543 | raise TypeError( |
| 544 | 'Excluding fields from a sequence of sub-models or dicts must be performed index-wise: ' |
| 545 | 'expected integer keys or keyword "__all__"' |
| 546 | ) |
| 547 | normalized_i = v_length + i if i < 0 else i |
| 548 | normalized_items[normalized_i] = self.merge(v, normalized_items.get(normalized_i)) |
| 549 | |
| 550 | if not all_items: |
| 551 | return normalized_items |
| 552 | if self.is_true(all_items): |
| 553 | for i in range(v_length): |
| 554 | normalized_items.setdefault(i, ...) |
| 555 | return normalized_items |
| 556 | for i in range(v_length): |
| 557 | normalized_item = normalized_items.setdefault(i, {}) |
| 558 | if not self.is_true(normalized_item): |
| 559 | normalized_items[i] = self.merge(all_items, normalized_item) |
| 560 | return normalized_items |
| 561 | |
| 562 | @classmethod |
| 563 | def merge(cls, base: Any, override: Any, intersect: bool = False) -> Any: |
no test coverage detected