KotlinIsland / KotlinIsland/basedmypy

Conditional types with `If`

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

Description

Would make a lot of overloads simpler
```py
def foo(a: bool) -> If[a, str, int]:
if a:
return str(a)
return 1

def bar(s: str) -> If[s == "AMONGUS", str, int]:
if a == "AMONGUS":
return str(a)
return 1
```

In the same way that overloads are not checked, these also wouldn't be.

What about `if`?
```py
def foo(a: bool) -> str if a else int: ...
```

Contributor guide

Open the contributing guide

Research direction

No file, test, or entry point is named. Start by tracing how basedmypy handles overload checking and parses function return annotations, then compare the proposed `If` form with the conditional `if` annotation form. Done would require a settled design for both forms and tests defining their supported behavior.

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.