exaloop / exaloop/codon

`__bool__` should fall back to `__len__` when it is undefined

Open
#700 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
16.8k
Forks
603
Avg merge
4d 23h
Merged PRs (30d)
6

Description

Hello! I'm trying to use Codon.

According to , if a class does not define `__bool__`, Python should call `__len__` to determine truthiness.

However, in Codon 0.19.3, attempting to evaluate such an object in a boolean context causes an error.

Example:

```python
class A:
def __len__(self) -> int:
return 0

a = A()
print(bool(a))
```

This should output:

```
False
```

But Codon raises an error:

```
bool.codon:12 (16-31): error: 'A' object has no attribute '__bool__'
╰─ Main.py:6 (7-14): error: during the realization of __new__(what: A)
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.