Skip to content

Commit

Permalink
feat: use None in extend extra to remove expected file from schema
Browse files Browse the repository at this point in the history
Co-authored-by: Rit <RitikShah@users.noreply.github.com>
  • Loading branch information
vberlier and RitikShah committed Oct 4, 2023
1 parent a831318 commit cbd8b02
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions beet/library/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ def scan(
prefix: str,
origin: FileOrigin,
extend_namespace: Iterable[Type[NamespaceFile]] = (),
extend_namespace_extra: Optional[Mapping[str, Type[PackFile]]] = None,
extend_namespace_extra: Optional[Mapping[str, Optional[Type[PackFile]]]] = None,
) -> Iterator[Tuple[str, "Namespace"]]:
"""Load namespaces by walking through a zipfile or directory."""
preparts = tuple(filter(None, prefix.split("/")))
Expand All @@ -580,7 +580,7 @@ def scan(

extra_info = cls.get_extra_info()
if extend_namespace_extra:
extra_info.update(extend_namespace_extra)
_update_with_none(extra_info, extend_namespace_extra)

scope_map = dict(cls.scope_map)
for file_type in extend_namespace:
Expand Down Expand Up @@ -826,9 +826,9 @@ class Pack(MatchMixin, MergeMixin, Container[str, NamespaceType]):
"filter", default_factory=lambda: {"block": []}
)

extend_extra: Dict[str, Type[PackFile]]
extend_extra: Dict[str, Optional[Type[PackFile]]]
extend_namespace: List[Type[NamespaceFile]]
extend_namespace_extra: Dict[str, Type[PackFile]]
extend_namespace_extra: Dict[str, Optional[Type[PackFile]]]

merge_policy: MergePolicy
unveiled: Dict[Union[Path, UnveilMapping], Set[str]]
Expand Down Expand Up @@ -1047,7 +1047,7 @@ def get_extra_info(cls) -> Dict[str, Type[PackFile]]:
def resolve_extra_info(self) -> Dict[str, Type[PackFile]]:
extra_info = self.get_extra_info()
if self.extend_extra:
extra_info.update(self.extend_extra)
_update_with_none(extra_info, self.extend_extra)
return extra_info

def resolve_scope_map(
Expand All @@ -1061,7 +1061,7 @@ def resolve_scope_map(
def resolve_namespace_extra_info(self) -> Dict[str, Type[PackFile]]:
namespace_extra_info = self.namespace_type.get_extra_info()
if self.extend_namespace_extra:
namespace_extra_info.update(self.extend_namespace_extra)
_update_with_none(namespace_extra_info, self.extend_namespace_extra)
return namespace_extra_info

def load(
Expand Down Expand Up @@ -1254,3 +1254,15 @@ def _dump_files(origin: FileOrigin, files: Mapping[str, PackFile]):
Path(origin, *directory).resolve().mkdir(parents=True, exist_ok=True)
for filename, f in entries:
f.dump(origin, "/".join(directory + (filename,)))


K = TypeVar("K")
V = TypeVar("V")


def _update_with_none(dst: MutableMapping[K, V], src: Mapping[K, Optional[V]]):
for k, v in list(src.items()):
if v is None:
dst.pop(k, None)
else:
dst[k] = v

0 comments on commit cbd8b02

Please sign in to comment.