facebook / facebook/pyrefly

implicit-any-lambda fires before generic callback contextual typing

Open
#4,368 2 comments 7 reactions 1 assignee Claimed by @samwgoldman View on GitHub
contextual-typing stale
Dominant language
Rust
Stars
7k
Forks
516
PR merge metrics
No merged PRs in 30d

Description

## Summary

The new `implicit-any-lambda` rule reports fully contextualized callback
parameters for generic functions such as `sorted`. Pyrefly's own test added
with the rule labels generic callback contextual typing as a known `bug`, but
the diagnostic now inherits strict `implicit-any` severity and reaches users.

Most of 24 new `implicit-any-lambda` corpus diagnostics follow this pattern.

## Reproduction

```python
typed_dict: dict[int, int] = {1: 2}

typed_items = sorted(typed_dict.items(), key=lambda item: (item[1], item[0]))
typed_keys = sorted(typed_dict, key=lambda key: (typed_dict[key], key))
```

With the same strict preset and interpreter:

- Pyrefly 1.1.1: clean
- Pyrefly 1.2.0-dev.3: two `implicit-any-lambda` diagnostics, plus a downstream
`unknown-argument-type`

Both lambda parameters have an unambiguous contextual type from `sorted`.
Genuinely dynamic callbacks should still report; the request is to apply
generic callback contextual typing before emitting this rule.

Related umbrella feature issue: #3661. Causal commits: 830170e3c and
c92007872.

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.