(expr, or_components)
| 4021 | |
| 4022 | |
| 4023 | def _replace_common_or_components(expr, or_components): |
| 4024 | and_component = _get_predicate_components(expr, [], type_=And) |
| 4025 | mapping = _convert_mapping(and_component) |
| 4026 | and_components = [ |
| 4027 | _get_predicate_components(c, [], type_=And) for c in or_components |
| 4028 | ] |
| 4029 | and_components = list(map(_convert_mapping, and_components)) |
| 4030 | |
| 4031 | replacements = [] |
| 4032 | for c in mapping.keys(): |
| 4033 | if all(c in comp for comp in and_components): |
| 4034 | # We can pull this component out if it's part of all or components |
| 4035 | replacements.append(c) |
| 4036 | if len(replacements) == 0: |
| 4037 | # exit if we can't replace anything |
| 4038 | return |
| 4039 | |
| 4040 | outer_component = mapping[replacements[0]] |
| 4041 | for r in replacements[1:]: |
| 4042 | # construct the outer component |
| 4043 | outer_component = outer_component & mapping[r] |
| 4044 | |
| 4045 | # |
| 4046 | result_components = [] |
| 4047 | for comp in [mapping] + and_components: |
| 4048 | keep_components = [c for c in comp if c not in replacements] |
| 4049 | if len(keep_components) == 0: |
| 4050 | # Just return outer_component if we can replace a whole OR component |
| 4051 | return outer_component |
| 4052 | result_component = comp[keep_components[0]] |
| 4053 | for c in keep_components[1:]: |
| 4054 | result_component = result_component & comp[c] |
| 4055 | result_components.append(result_component) |
| 4056 | |
| 4057 | or_component = result_components[0] |
| 4058 | for c in result_components[1:]: |
| 4059 | or_component = or_component | c |
| 4060 | return outer_component & or_component |
| 4061 | |
| 4062 | |
| 4063 | def _check_dependents_are_predicates( |
no test coverage detected
searching dependent graphs…