KotlinIsland / KotlinIsland/basedmypy

A way to describe how a lambda will be executed (inplace / execution count)

Open
#190 0 comments 0 reactions 0 assignees View on GitHub
feature
Dominant language
Python
Stars
202
Forks
6
PR merge metrics
No merged PRs in 30d

Description

# inplace / borrowed
```py
from typing import Callable

def run(fn: Callable[[], object]):
fn()

for i in [1, "s"]:
if isinstance(i, int):
reveal_type(i) # int
run(lambda: reveal_type(i)) # object
```
pylint says `W0640: Cell variable i defined in loop (cell-var-from-loop)`

so what about:
```py
def run(fn: InPlace[Callable[[], object]]):
fn()
```

# count: exactly once, at least once, at most once, and unknown
- TODO, figure out an example where a lambda has a type effect

Contributor guide

Open the contributing guide

Research direction

Start with the issue's lambda examples and the proposed InPlace wrapper, then clarify how execution count and in-place or borrowed execution should affect typing. The work is done when the intended semantics are specified and the checker behavior for those cases is covered, including a concrete example for execution counts.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.