facebook / facebook/pyrefly

Constrained type var is lost after chained method calls

Open
#3,892 11 comments 0 reactions 1 assignee Assigned to @kz357 View on GitHub
typechecking
Dominant language
Rust
Stars
7k
Forks
516
PR merge metrics
No merged PRs in 30d

Description

### Describe the Bug

This is a little bit of a follow up to https://github.com/facebook/pyrefly/issues/3621 since it is related to polars and generics.

The output of `group_by` is affected after bumping to the newly released `v1.1.0` (and `v1.1.1`). The outputs of `group_by` is incorrectly being inferred as `pl.DataFrame | pl.LazyFrame` rather than staying generic.

```python
from typing import TypeVar
import polars as pl

Frame = TypeVar("Frame", pl.DataFrame, pl.LazyFrame)

def aggregation(df1: Frame) -> Frame:
return df1.group_by("a").agg(pl.len())

```

```
ERROR Returned type `DataFrame | LazyFrame` is not assignable to declared return type `Frame` [bad-return]
```

### Sandbox Link

_No response_

### (Only applicable for extension issues) IDE Information

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.