[red-knot] Add diagnostic for class-object access to pure instance variables (#16036)

## Summary

Add a diagnostic if a pure instance variable is accessed on a class object. For example

```py
class C:
    instance_only: str

    def __init__(self):
        self.instance_only = "a"

# error: Attribute `instance_only` can only be accessed on instances, not on the class object `Literal[C]` itself.
C.instance_only
```


---------

Co-authored-by: David Peter <mail@david-peter.de>
This commit is contained in:
Mike Perlov
2025-02-24 09:17:16 -05:00
committed by GitHub
parent e7a6c19e3a
commit 68991d09a8
8 changed files with 246 additions and 136 deletions

View File

@@ -116,8 +116,8 @@ MyType = int
class Aliases:
MyType = str
forward: "MyType"
not_forward: MyType
forward: "MyType" = "value"
not_forward: MyType = "value"
reveal_type(Aliases.forward) # revealed: str
reveal_type(Aliases.not_forward) # revealed: str