Skip to content

Commit

Permalink
filesystem: match filter as a comprehension
Browse files Browse the repository at this point in the history
(cherry picked from commit f362397)
  • Loading branch information
dbungert committed Jul 5, 2024
1 parent 11910c5 commit b12d1ed
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions subiquity/models/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import secrets
import tempfile
from abc import ABC, abstractmethod
from typing import Dict, List, Optional, Sequence, Set, Tuple, Union
from typing import Callable, Dict, List, Optional, Sequence, Set, Tuple, Union

import attr
import more_itertools
Expand Down Expand Up @@ -1590,7 +1590,7 @@ def load_server_data(self, status):
status.config, blockdevs=None, is_probe_data=False
)

def _make_matchers(self, match):
def _make_matchers(self, match: dict) -> Sequence[Callable]:
def _udev_val(disk, key):
return self._probe_data["blockdev"].get(disk.path, {}).get(key, "")

Expand Down Expand Up @@ -1658,14 +1658,7 @@ def _sorted_matches(self, disks: Sequence[_Device], match: dict):

def _filtered_matches(self, disks: Sequence[_Device], match: dict):
matchers = self._make_matchers(match)
candidates = []
for candidate in disks:
for matcher in matchers:
if not matcher(candidate):
break
else:
candidates.append(candidate)
return candidates
return [disk for disk in disks if all(match_fn(disk) for match_fn in matchers)]

def disk_for_match(self, disks, match):
log.info(f"considering {disks} for {match}")
Expand Down

0 comments on commit b12d1ed

Please sign in to comment.