Skip to content

[v1.5 regression] Invalid context-manager use goes unchecked #5548

Closed

Description

@rchen152

Describe the Bug

Only affected one repository (four incorrectly removed diagnostics), but the cause is that a usually suppressed diagnostic causes us to discard valid context-manager errors, which seems bad.

from typing import Any, Generic, TypeVar

T = TypeVar("T")

class Envoy(Generic[T]):
    def __call__(self, *args: list[Any]) -> Any:
        return None

    def __getattr__(self, key: str) -> "Envoy[T] | T | Any":
        raise AttributeError(key)

def use(e: Envoy) -> None:
    with e:  # No longer reports bad-context-manager
        pass

use(Envoy())  # Raises TypeError

Sandbox Link

https://pyrefly.org/sandbox/?project=v2.pZXNboMwEIRfZQUHSKXU9976BlXFreTggEWQWrvCS9q8fcZrA_lRIkU5IPHn2WX9zfBoZM65mLIr7EeFztJlWWdVnckuJbPZvTuUadVXtZkAi7ZrMNPZdi_wwORY1NoIPDi5RfKpUGdYMw-zFqYmWSAadSZdoDpMVOGA6IzVAvI7BPrtyJHmEhLyHaHA6E0JJ4rMJdN_Pe8IDylHvNq2R0gZso6-ne3MgJbD8DxtdbtunGXzz-sfbTWeLQ1EFAEH6sSJrVZB8DM05heLXTOX00e8QWn7kLaAtRuR6YDwtbY54tzQjvnXvyk1LXdDp4xVrWu8OluhKNhL73Uvf4pzOXLiEQ_ZZ2AvIuvFPdSLQDreuEvvEQ

(Only applicable for extension issues) IDE Information

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions