facebook / facebook/pyrefly

Confusing error message when I forgot `global` keyword

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

Description

### Describe the Bug

I attempted to write the following incorrect code:
```
class A: ...

def f():
class A(A): ... # error: Class `f.A` inheriting from `f.A` creates a cycle
```
Pyrefly is right that there is an error in this code, but the real problem is that I need to add `global A` at the beginning of the function body. It would be really useful if it could somehow figure this out and tell me what I did wrong.

### Sandbox Link

https://pyrefly.org/sandbox/?project=N4IgZglgNgpgziAXKOBDAdgEwEYHsAeAdAA4CeSIAxlKnHAAQCCi9hbAOup5jGPWAAoAlIk71x9arQaMBjEazYgANCACuAF2hwS5RCADE9AKpaoEDaX5r0lLbnRxO3Xv1wAnALaoNAfXRqntgw7gL4LBDoGkL0ALQAfPRwGu6i6BL07jAaau7pYOwgAHKBwan0wPgAvoWcKiBkWWBQpIQauJ5QFEYACqRNLUkYOASSDpAA5rk%2BEA6EnEYAyjAw9AAWGhrEcIgA9LuNvC2EHhO7MOi7mLiUcLuU4xBT7jMOu27u9KgAbqjQqNhYGN0JNpvZ0rhiOCdJwyBo1g5Yt8QnBZukALz0QoAZkIAEYAEy1dAgKqqVB2CDIgBi0BgFDQWDwRDIpKAA

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