typing: type aura, web plugin and export plugin - #6937
Conversation
|
Thank you for the PR! The changelog has not been updated, so here is a friendly reminder to check if you need to add an entry. |
There was a problem hiding this comment.
Pull request overview
grug see PR make typing more sharp in plugin boundary. goal: type checker stop lying, and runtime edge case less crash.
Changes:
- Add/adjust type annotations in
aura+ safer handling when included resource missing. - Refactor
exportinto one iterable pipeline across json/jsonlines/csv/xml, plus path-byte stringify. - Add clearer web plugin endpoint/decorator annotations, plus 404 when item missing.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| beetsplug/aura.py | Tighten document/query typing and make included resource fetching safer. |
| beetsplug/export.py | Unify export data flow across formats and improve typing around formats/paths. |
| beetsplug/web/init.py | Add endpoint/decorator typing and small runtime safety for missing items. |
Suppressed comments (2)
beetsplug/web/init.py:281
- grug see QueryConverter.to_url annotation say str, but to_python make list[str]. if str passed, code iterate chars and make bad url. type should be list[str] to match.
def to_url(self, value: str) -> str:
return "/".join([v.replace(os.sep, "\\") for v in value])
beetsplug/aura.py:289
- grug see get_included append Artist/Image resource_object even when None. then response have null in included list, JSON:API not like, and clients sad. only append when resource object not None, and keep included typed list[JSONDict].
included: list[JSONDict | None] = []
for identifier in unique_identifiers:
res_type = identifier["type"]
if res_type == "track":
track_id = int(identifier["id"])
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## type-bpd #6937 +/- ##
============================================
- Coverage 76.02% 76.01% -0.02%
============================================
Files 164 164
Lines 21572 21577 +5
Branches 3340 3341 +1
============================================
+ Hits 16400 16401 +1
- Misses 4380 4381 +1
- Partials 792 795 +3
🚀 New features to boost your workflow:
|
8311344 to
ca026db
Compare
d6d61b1 to
ccf872a
Compare
ca026db to
c764422
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Suppressed comments (2)
beetsplug/aura.py:181
- grug see filter convert use
list(...)when field type is multi-value (like genres/composers).list('rock')become ['r','o','c','k'] and MatchQuery then never match list field. grug think keep string for list-typed field.
value = converter(v) # type: ignore[arg-type, misc]
beetsplug/web/init.py:86
- grug see json_generator always
yieldstrings (docstring say so). return typeIterator[Any]too loose, typing gain gone. grug wantIterator[str].
def json_generator(
items: Sequence[LibModel], root: str, expand: bool = False
) -> Iterator[Any]:
c764422 to
48d67c4
Compare
48d67c4 to
b9de1ce
Compare
b9de1ce to
485ae8d
Compare
485ae8d to
01233c7
Compare
01233c7 to
7494176
Compare
7494176 to
87da1ca
Compare
Part of #6924.
This change tightens typing across
beetsplug/aura.py,beetsplug/export.py, andbeetsplug/web/__init__.pyso plugin interfaces better match real runtime behavior.High-level impact: no big feature shift, but architecture become more explicit. Plugin boundaries, data shapes, and format handling are clearer, which should make future changes safer and type errors easier to catch.
auraMultiDictI could not resolve typing without using
type: ignorein two places and I found both pieces of logic should be removed:sqlite3.InterfaceErrorwhen usingfilter[genres], because it was split into, e.g."genres" -> ["g", "e", "n", "r", "e", "s"].strandint.MatchQueryhappily accepts astrpattern when matchingintfields.field, excluding empty/null values: I'm pretty sure this is not the behaviour we want 😅.Extended tests to prove both of the above.
exportjson,jsonlines,csv, andxmlnow share one higher-level data path, with path-like byte fields normalized before writingweb404instead of failing later