(expr, or_components)
| 3977 | |
| 3978 | |
| 3979 | def _replace_common_or_components(expr, or_components): |
| 3980 | and_component = _get_predicate_components(expr, [], type_=And) |
| 3981 | mapping = _convert_mapping(and_component) |
| 3982 | and_components = [ |
| 3983 | _get_predicate_components(c, [], type_=And) for c in or_components |
| 3984 | ] |
| 3985 | and_components = list(map(_convert_mapping, and_components)) |
| 3986 | |
| 3987 | replacements = [] |
| 3988 | for c in mapping.keys(): |
| 3989 | if all(c in comp for comp in and_components): |
| 3990 | # We can pull this component out if it's part of all or components |
| 3991 | replacements.append(c) |
| 3992 | if len(replacements) == 0: |
| 3993 | # exit if we can't replace anything |
| 3994 | return |
| 3995 | |
| 3996 | outer_component = mapping[replacements[0]] |
| 3997 | for r in replacements[1:]: |
| 3998 | # construct the outer component |
| 3999 | outer_component = outer_component & mapping[r] |
| 4000 | |
| 4001 | # |
| 4002 | result_components = [] |
| 4003 | for comp in [mapping] + and_components: |
| 4004 | keep_components = [c for c in comp if c not in replacements] |
| 4005 | if len(keep_components) == 0: |
| 4006 | # Just return outer_component if we can replace a whole OR component |
| 4007 | return outer_component |
| 4008 | result_component = comp[keep_components[0]] |
| 4009 | for c in keep_components[1:]: |
| 4010 | result_component = result_component & comp[c] |
| 4011 | result_components.append(result_component) |
| 4012 | |
| 4013 | or_component = result_components[0] |
| 4014 | for c in result_components[1:]: |
| 4015 | or_component = or_component | c |
| 4016 | return outer_component & or_component |
| 4017 | |
| 4018 | |
| 4019 | def _check_dependents_are_predicates( |
no test coverage detected