apache / apache/iceberg-python
Add explicit truthiness semantics for constant BooleanExpressions
- Linguagem predominante
- Python
- Estrelas
- 1.1k
- Forks
- 581
- Merge médio
- 1d 13h
- PRs com merge (30d)
- 76
Descrição
While this PR can use expression negation via `__invert__,` I think it may be worth supporting Python truthiness for the constant expressions in a follow-up:
```
class AlwaysTrue:
def __bool__(self) -> bool:
return True
class AlwaysFalse:
def __bool__(self) -> bool:
return False
```
That would make patterns like this behave intuitively:
```
if not self.visit_starts_with(term, literal):
return AlwaysTrue()
```
When adding this, we should also be careful that Python truthiness is for control flow, not expression construction: `not expr` returns a Python `bool`, while `~expr` returns a negated BooleanExpression. It would probably be safest for non-constant `BooleanExpression.__bool__` to raise, with only `AlwaysTrue` and `AlwaysFalse` overriding it. The follow-up should also audit optional-expression checks like `expr or AlwaysTrue()` and REST residual/filter handling so explicit `AlwaysFalse()` values are not treated as missing.
_Originally posted by @kevinjqliu in https://github.com/apache/iceberg-python/issues/3503#issuecomment-4763176953_
Guia de contribuição
Nenhum guia de contribuição indexado para este repositório
Direção de pesquisa
Comece localizando BooleanExpression, AlwaysTrue e AlwaysFalse; em seguida, inspecione as verificações de expressões opcionais e o tratamento de residuais/filtros REST mencionados na issue. Verifique se apenas expressões constantes oferecem suporte à avaliação de truthiness do Python, se expressões não constantes a rejeitam e se valores explícitos AlwaysFalse() são preservados em vez de tratados como ausentes.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- python
- Domínio
- databases
- Tipo de issue
- Funcionalidade
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Status de atividade
- Pouca atividade
- Clareza
- Razoavelmente clara
- Facilidade para iniciantes
- 48/100