Skip to content

Preliminary support for class decorators #2752

Description

@grievejia

Describe the Bug

Minimal repro:

class ActorHandle[T]:
    """Wrapper returned by the @remote decorator."""
    def remote(self) -> T: ...
    def options(self, num_cpus: int) -> "ActorHandle[T]": ...

def remote[T](cls: type[T]) -> ActorHandle[T]:
    """Decorator that replaces a class with an ActorHandle wrapper."""
    return ActorHandle()

@remote
class Worker:
    def compute(self) -> int:
        return 42

# After decoration, Worker is ActorHandle[Worker], so .remote() is valid
Worker.remote()  # pyrefly: Class `Worker` has no class attribute `remote`
Worker.options(num_cpus=2)  # pyrefly: Class `Worker` has no class attribute `options`

Today only Pyright actually accepts this kind of code. So low-pri.

Sandbox Link

https://pyrefly.org/sandbox/?project=N4IgZglgNgpgziAXKOBDAdgEwEYHsAeAdAA4CeSIAxlKnHAAQCClALrgE4ASGmsA2gBUAuogA66epPqiQMmQHV2qYsRjt67GCwCu7dDEz1speiwAWMegAFNAW1wtLmGJQ6o27QnNmyJU52AaMPaOABRwMFBgAJT0ALQAfPQCiPSE6eJS9AH0uMQsELjocOGRYAA09OjatgD6lMTacKkQ6CyxidIgzB7cWPzCMqnpXujiOXYOMIJCodTNpqSqMx1JPRx9vNPCYn6S3jIAIi5uHqZm7kHENJTw9Kj01LQMAO4Q5vcS61w8sPQvShUai8PjkeyCOj0TFYG1%2BMFC0XE4hswSm4iedHo8g4AGs1LssjlXLZGmEIlFVvRWiwCVkpJpIRIACwAJiR6AAxEwwI51M5XEoCkVKtj2Hj1BAGN9NvxReKhJU4Lg0pMwrFJfQAG6oKAQTDiOXA1Xw2L0LlkTRgKCkVIAYRomIABob2I76BcGOhlRiGO4WOwINhtI56I7jY6DbjgXkhcVQtU6g0mgBeFmm82kS3Wu0OhjOqOu920Kre3P3Fj%2BwPByyOmOFYqOkDlEDB6BwEjkRAgLkAVQKupYJjA2nQrHrcHZOTAHFs7lqCewalC%2BBabUpcH9tMkDN0EjAMgAcjVF%2BxUsB8ABfMFNkAWmBW0iENi2KAULkABUz9%2Bt9DQWDw%2BCPEUkAAOa6O49ajFyADKMCWGYFbEM0AD0yF3g%2BhAcCByEwOgyGYLglBwMhrjoKB4Gxsh9DTuoqDatAqDYH8pHkYK9a5Pk46jGQ5hFHEmpqHA7HJl0ADMhAAIxsr4IAXs2qBjgJABi0AwBQf44AQHayUAA

(Only applicable for extension issues) IDE Information

No response

Metadata

Metadata

Labels

decoratorstypecheckingusabilityUsability & readiness issues identified with running Pyrefly on top OSS projects

Fields

No fields configured for Feature.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions