Files
python-repositories/python_repositories/interfaces/connection_aware_interface.py
T
Brian Bjarke JensenandCursor f6ee9a3724
PR Title Check / check-title (pull_request) Successful in 7s
Test Python Package / unit-tests (pull_request) Successful in 9s
Code Quality Pipeline / code-quality (pull_request) Successful in 22s
Test Python Package / integration-tests (pull_request) Successful in 24s
Test Python Package / coverage-report (pull_request) Successful in 8s
Add runtime-checkable Protocol typing to all public interfaces.
Enables structural subtyping for consumers while preserving nominal adapter inheritance, instantiation guards, and scan_keys defaults.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-11 09:45:42 +02:00

32 lines
852 B
Python

"""Definition of ConnectionAwareInterface protocol and abstract base class."""
from abc import abstractmethod
from typing import Protocol, runtime_checkable
@runtime_checkable
class ConnectionAwareInterface(Protocol):
"""Interface that defines connection-related methods."""
@abstractmethod
def connect(self) -> None:
"""Connect to resource.
Implementations should be idempotent: calling connect while already
connected and healthy is a no-op.
"""
...
@abstractmethod
def disconnect(self) -> None:
"""Disconnect from resource."""
...
@abstractmethod
def is_connected(self) -> bool:
"""Return whether the adapter has an active, reachable connection.
Implementations may perform a cached network probe to verify liveness.
"""
...