KotlinIsland / KotlinIsland/basedmypy
an `UnsafeVariance` modifier
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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