facebook / facebook/pyrefly

Should we let `__getattr__` w/o `__setattr__` satisfy read-write attrs on protocols?

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

Description

### Describe the Bug

```
import importlib
from importlib import ModuleType
from typing import Protocol

class HasDescription(Protocol):
parser_description: str

def via_import_module(name: str) -> None:
module: HasDescription = importlib.import_module(name) # error
```

mypy accepts this

runtime does not error since you can arbitrarily set attributes unless you override `__setattr__` to error

### Sandbox Link

https://pyrefly.org/sandbox/?project=v2.fZRNDoMgEIWvQuLGbmTvuotumvQATQgRYkmsEH48f4cBNNDoyojDIG_e-86QmZOXHphFBMH-XjDw1CIsMnogV9SYLRg80vfg7i7dZBWq3ZeCYjzDLaCOiaMkZzplY1Ocpdbsiyf30TNY0notfR-bA0HE_Q7Df6cb6dL0UeFmvh15pQWSpQKygTHmAPyE1sN77QCdkny8N26ktGzXdqZypUJPjlY7KIlW5htXSOW6HdH4ww7aXhjLWOmkxyXQh4fFozuuRv4D

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