facebook / facebook/pyrefly

Unannotated method where parent returns None, child returns T | None

Open
#3,061 0 comments 0 reactions 0 assignees View on GitHub
typechecking usability
Dominant language
Rust
Stars
7k
Forks
519
PR merge metrics
No merged PRs in 30d

Description

### Describe the Bug

Minimal repro:
```python
class Expr:
def _tune_down(self, cond: bool):
return None

class HLGExprSequence(Expr):
def _tune_down(self, cond: bool): # FP: HLGExprSequence | None not assignable to None
if cond:
return None
return HLGExprSequence()
```
Pyright doesn't like this, whereas mypy and ty are fine.

### Sandbox Link

https://pyrefly.org/sandbox/?project=N4IgZglgNgpgziAXKOBDAdgEwEYHsAeAdAA4CeSIAxlKnHAAQCi%2BxATogDrr0-2Yxh6AfQAuAV3QwhmXAHd0ACjgwoYADT1KuLInp5cUAJSduvM6xjjW3AHLaYXR%2Bmq0GACQAyAcWZsAyjAAjmIwzjAKvqzGXGb8gqISUjLySirqmtqYuvpGuvQAxPQAYgAKup4%2BLKwBwaGUMPQAPvR2kvTouCL0rhAA5uio2LD0Irgt9jFmvBCCWjqTU1MWVrYTpovLYtb0FZE1IWEKhiBqIGIi0HAk5IgghQCqF1AQIqT0YBKUF9pwTnHvuFYAFtUCIhOgxEDsDBWAp8LoIOgRIZ6ABaAB89DgInYC3om22YA4IBskOh7HowHwAF9iVwTiAyBYwFBSIRRkCoBRCiVSMzWViMDgCBl0JBeltQRBtIQuIUAg0ABYiETEOCIAD0GqZAlZhEBvQ1oQ1MkocA1c3Fku%2B6A1ANY3QAbqhoINhpa%2BtbpdxcMQbVcuGQRIrtKjHTC4N76ABeejEgDMhAAjAAmOnoEDU06oL4QcNFaAwChoLB4IhkTNAA

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