IEEE.org     |     IEEE Xplore Digital Library     |     IEEE Standards     |     IEEE Spectrum     |     More Sites

Verified Commit a379d6d2 authored by Emi Simpson's avatar Emi Simpson
Browse files

[new arch] Increase documentation for _fold_sources()

Resolves !8 (comment 10116)
parent 85dcdc25
Pipeline #896 passed with stage
in 56 seconds
......@@ -17,15 +17,36 @@ force_login: Tuple[outcome.ForceLogin] = (outcome.ForceLogin(),)
def _fold_sources(sources: Iterable[Source]) -> Mapping[Backend, Collection[Url]]:
"""
Group :class:`Source`'s :class:`Url`s by their :class:`Backend`
This is most useful for when formatting a list of sources to be fed to the
coordinator, which requires that sources be provided in this format (i.e. a backend
name -> url mapping).
## Example
```python
assert _fold_sources([
Source('git', 'https://my.git.forge/MyUser/MyProject1'),
Source('git', 'https://my.git.forge/MyUser/MyProject2'),
Source('rss', 'https://my.rss.feed/feed.rss')
]) == {
Backend('git'): [
Url('https://my.git.forge/MyUser/MyProject1'),
Url('https://my.git.forge/MyUser/MyProject2')
],
Backend('rss'): [ Url('https://my.rss.feed/feed.rss') ]
}
```
"""
return reduce(
lambda dict, source:
# Append the source to the dict as a backend: [url] pair, merging lists where
# needed
dict | {
Backend(source.source_type):\
dict.get(Backend(source.source_type), []) +\
[Url(source.url)] },
sources,
cast(Mapping[Backend, List[Url]], dict()))
cast(Mapping[Backend, List[Url]], dict())) # An empty dict + type annotations
def delete_source(req: Request) -> Outcomes | Query[Outcomes, Outcomes]:
"""
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment