docs: def prefer_master(nodes: List[DiscoveredNode]) -> Optional[DiscoveredNode]:
      """
      Select the master if available, otherwise fall back to a replica.
      """
      return max(nodes, key=attrgetter("state"))