Skip to content

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

Open

Description

@yangdanny97

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

Activity

  1. added
    needs-discussion
    on Aug 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-discussiontypechecking

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions