| 115 | return clause |
| 116 | |
| 117 | def replace_expressions(self, replacements): |
| 118 | if not replacements: |
| 119 | return self |
| 120 | clone = self.create(connector=self.connector, negated=self.negated) |
| 121 | for child in self.children: |
| 122 | child_replacement = child |
| 123 | if isinstance(child, tuple): |
| 124 | lhs, rhs = child |
| 125 | if LOOKUP_SEP in lhs: |
| 126 | path, lookup = lhs.rsplit(LOOKUP_SEP, 1) |
| 127 | else: |
| 128 | path = lhs |
| 129 | lookup = None |
| 130 | field = models.F(path) |
| 131 | if ( |
| 132 | field_replacement := field.replace_expressions(replacements) |
| 133 | ) is not field: |
| 134 | # Handle the implicit __exact case by falling back to an |
| 135 | # extra transform when get_lookup returns no match for the |
| 136 | # last component of the path. |
| 137 | if lookup is None: |
| 138 | lookup = "exact" |
| 139 | if (lookup_class := field_replacement.get_lookup(lookup)) is None: |
| 140 | if ( |
| 141 | transform_class := field_replacement.get_transform(lookup) |
| 142 | ) is not None: |
| 143 | field_replacement = transform_class(field_replacement) |
| 144 | lookup = "exact" |
| 145 | lookup_class = field_replacement.get_lookup(lookup) |
| 146 | if rhs is None and lookup == "exact": |
| 147 | lookup_class = field_replacement.get_lookup("isnull") |
| 148 | rhs = True |
| 149 | if lookup_class is not None: |
| 150 | child_replacement = lookup_class(field_replacement, rhs) |
| 151 | else: |
| 152 | child_replacement = child.replace_expressions(replacements) |
| 153 | clone.children.append(child_replacement) |
| 154 | return clone |
| 155 | |
| 156 | def flatten(self): |
| 157 | """ |