facebook / facebook/pyrefly

Narrow arbitrary index in a list

Open
#1,094 5 comments 0 reactions 0 assignees View on GitHub
narrowing needs-discussion typechecking
Dominant language
Rust
Stars
7k
Forks
516
PR merge metrics
No merged PRs in 30d

Description

### Describe the Bug

In my class I have:

```python
def __init__(self, ...):
...
self.gps_time: Optional[datetime] = None
...
```

But in expression like following:
```python
(gps_seq[i].gps_time is None or gps_seq[i + 1].gps_time is None or gps_seq[i].gps_time >= gps_seq[i + 1].gps_time
```

It cannot "smart"-cast 'gps_seq[i].gps_time' and 'gps_seq[i + 1].gps_time' and consider that both values could be NoneType

I think more such cased should be handled using smart-casting variable, otherwise type checking is not pleasent at all

### 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.