bug: functools decorators are accepted but never applied, so singledispatch and total_ordering silently do nothing
- Langage dominant
- Rust
- Étoiles
- 22
- Forks
- 6
- Merge moyen
- 1 j 3 h
- PR mergées (30 j)
- 6
Description
## Description
Several `functools` decorators are accepted and then not applied. The name is recognised, the decorated function or class compiles, and the decorator's behaviour is simply absent, so the program gets a wrong answer with no warning.
Two are confirmed wrong. Both are silent, which `plan/OVERVIEW.md`'s correctness rule treats as the highest-priority class.
## Steps to Reproduce
`@singledispatch` never dispatches; the base implementation is always called:
```python
from functools import singledispatch
@singledispatch
def kind(x: int) -> int:
return 1
@kind.register
def _(x: str) -> int:
return 2
def call_int() -> int:
return kind(5)
def call_str() -> int:
return kind("hi")
```
| Function | waspy | CPython |
| --- | --- | --- |
| `call_int()` | `1` | `1` |
| `call_str()` | `1` | `2` |
`@total_ordering` never fills in the derived comparisons:
```python
from functools import total_ordering
@total_ordering
class N:
def __init__(self, v: int):
self.v = v
def __eq__(self, other) -> bool:
return self.v == other.v
def __lt__(self, other) -> bool:
return self.v < other.v
def gt_via_total_ordering() -> int:
a = N(5)
b = N(3)
if a > b:
return 1
return 0
```
`gt_via_total_ordering()` answers `0`. CPython answers `1`.
## Environment
- waspy 0.15.0, commit d7dcbc4
- Verified under both `wasmi` (the test harness) and Node 22
## Additional Context
`src/stdlib/functools.rs` maps these names to enum variants, and that is the whole of it: nothing consumes `FunctoolsFunction::Singledispatch` or `TotalOrdering` anywhere else in the tree. https://github.com/anistark/waspy/blob/d7dcbc4/src/stdlib/functools.rs#L9-L21
The same list also carries `partial`, `partialmethod`, `wraps`, `update_wrapper`, `cmp_to_key`, `lru_cache`, `cache`, and `cached_property`, so they are worth checking together. Some are harmless as no-ops (`lru_cache` and `cache` only affect speed, `wraps` only metadata); `partial` and `cmp_to_key` change results and probably are not.
Either implement them or reject them, but accepting one and ignoring it is the combination to avoid. Rejecting is the smaller change and restores the correctness rule immediately.
This also blocks a decision on #11: closing method overloading as wontfix rests on `functools.singledispatch` being the supported Pythonic alternative, and today it is not.
Guide de contribution
Ouvrir le guide de contribution
Piste de recherche
Start in src/stdlib/functools.rs and trace where FunctoolsFunction::Singledispatch and TotalOrdering are consumed; compare the handling of the other listed names. Run the reproductions under the wasmi harness and Node 22, then add focused tests for the affected behavior. Done means these decorators either work correctly or are explicitly rejected rather than silently ignored.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- python, rust, wasm
- Domaine
- compilers
- Type d'issue
- Bug
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- Active
- Clarté
- Plutôt claire
- Accessibilité débutants
- 58/100