KotlinIsland / KotlinIsland/basedmypy

assert style type guards

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

Description

```py
def f(x: object) -> TypeAssertion[int]: # demarcation is tentative, maybe `Asserts[x is int]`
assert isinstance(x, int)
a: object
f(a)
reveal_type(a) # int is
```

# Notes:
- Would want to be able to provide an assertion and a return type
```py
def f(x: object) -> Asserts[x is int] & str: ...
```
- Would want to be able to do 'truthy' assertions / invariants
```py
def asserts(x: object) -> Asserts[x] ...
a: object
asserts(isinstance(a, bool))
reveal_type(a) # bool
```

Contributor guide

Open the contributing guide

Research direction

No file, test, or entry point is named. Start by locating the type-checker tests for annotations and type narrowing, then use the examples to define the assertion syntax and inference behavior. Done means supported assertion and return-type forms narrow the caller’s type as shown.

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.