KotlinIsland / KotlinIsland/basedmypy

an `UnsafeVariance` modifier

Open
#209 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature generic modifier
Dominant language
Python
Stars
202
Forks
6
PR merge metrics
No merged PRs in 30d

Description

```py
class A(Generic[T_co]):
def foo(self, t: T_co):
print(t)
```
This code is 100% type safe, the usage of `t` is safe. It would be nice if there was a form of generic where safe usages can be guaranteed, a stop gap would be to introduce an `UnsafeVariance` modifier that just allows these usages.
```py
def foo(self, t: UnsafeVariance[T_co]):
```

# egg
```py
class A[out T]:
def foo(self, t: UnsafeVariance[T]):
reveal_type(t) # object
a = A[int]
a.foo("") # error, expected int, found str
```

Related: #62

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the proposed UnsafeVariance examples and read the related issue #62 for existing design context. Trace where generic variance and argument checking are handled in basedmypy, then define completion by supporting the proposed syntax and preserving the shown type-checking behavior. No specific source file or test is named in the issue.

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
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.