KotlinIsland / KotlinIsland/basedmypy

use site variance with `in`/`out` modifiers

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

Description

```py
a = [1]
b: list[Out[object]] = a # no error
```

```py
class A(Generic[T]):
def foo(self, t: T): ...
def foo(a: A[out[int]]):
a.foo(0) # error

foo(A[bool]()) # no error
```

I wonder if there is potential for an invariant use site variance modifier:
```py
class A(Generic[T_co]):
def foo(self): ..
def bar(self, t: Invariant[T_co]): ...

a1: A[int]
a1.foo()
a1.bar(1) # error
a2: A[Invariant[int]]
a2.foo()
a2.bar(1) # no error
```

Contributor guide

Open the contributing guide

Research direction

The issue provides Python typing examples but names no files, tests, or implementation entry points. Start by locating the existing handling for `in`/`out` modifiers and use-site variance, then determine whether invariant modifiers are intended and how their behavior should be specified and tested.

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.