Skip to content

refactor(snipeit): typisiere response payload als TypedDict statt dict[str, Any] (#67)#122

Merged
strausmann merged 1 commit into
mainfrom
fix/snipeit-typed-payload
Jun 14, 2026
Merged

refactor(snipeit): typisiere response payload als TypedDict statt dict[str, Any] (#67)#122
strausmann merged 1 commit into
mainfrom
fix/snipeit-typed-payload

Conversation

@strausmann

Copy link
Copy Markdown
Owner

Summary

dict[str, Any]_SnipeITAssetResponse TypedDict mit total=False für die 4 Felder die der Plugin tatsächlich konsumiert (id, asset_tag, name, serial).

class _SnipeITAssetResponse(TypedDict, total=False):
    id: int
    asset_tag: str | None
    name: str | None
    serial: str | None

Verhalten 1:1 (TypedDict ist zur Laufzeit ein dict, nur statische Analyse sieht die Struktur). Der Any-Import ist entfernt.

Test plan

  • tests/unit/integrations/test_snipeit_plugin.py — 10 passed
  • mypy ✓ ruff ✓

Refs #67 Audit-Punkt: PR #51 — snipeit/plugin.py:67 — Response payload dict[str, Any]

…t[str, Any] (#67)

Audit #67 Finding: das alte `dict[str, Any]` hat das Hub-mypy-strict-Verbot
von `Any` in Plugin-Responses verletzt. Refactor zu `_SnipeITAssetResponse`
TypedDict mit `total=False`:

  class _SnipeITAssetResponse(TypedDict, total=False):
      id: int
      asset_tag: str | None
      name: str | None
      serial: str | None

Beschränkt auf die Felder die `_payload_to_label` tatsächlich konsumiert.
Verhalten 1:1 (TypedDict wird zur Laufzeit als dict behandelt, nur mypy
sieht die Struktur). Die Verwendung von `.get(...)` bleibt unverändert.

Tests:
- tests/unit/integrations/test_snipeit_plugin.py — 10 passed
- mypy ✓ ruff ✓

Refs #67 Audit-Punkt: "PR #51 — snipeit/plugin.py:67 — Response payload dict[str, Any]"

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 14, 2026 14:35

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

Dieser Pull Request verbessert die Typsicherheit innerhalb des Snipe-IT-Plugins, indem das generische 'dict[str, Any]' durch ein explizites 'TypedDict' ersetzt wird. Dies stellt sicher, dass die konsumierten Felder ('id', 'asset_tag', 'name', 'serial') korrekt typisiert sind, während die Laufzeitlogik unverändert bleibt.

Highlights

  • Typisierung des Response-Payloads: Ersetzung von 'dict[str, Any]' durch ein spezifisches 'TypedDict' namens '_SnipeITAssetResponse' zur Verbesserung der statischen Code-Analyse.
  • Einhaltung der Mypy-Strict-Richtlinien: Entfernung des 'Any'-Imports und Adressierung des Audit-Punkts aus PR feat(integrations): LabelData schema + Snipe-IT lookup client #51, um die strikten Typisierungsanforderungen des Projekts zu erfüllen.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@strausmann
strausmann merged commit e88601b into main Jun 14, 2026
13 checks passed
@strausmann
strausmann deleted the fix/snipeit-typed-payload branch June 14, 2026 14:36

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request replaces the use of dict[str, Any] with a strictly-typed _SnipeITAssetResponse TypedDict in the Snipe-IT integration plugin to comply with strict type-checking rules. The review feedback suggests improving the type definition by removing total=False and explicitly marking optional fields with NotRequired so that the required id field remains mandatory in the type system.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

from __future__ import annotations

from typing import Any
from typing import TypedDict

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Importieren Sie NotRequired aus typing, um optionale Felder in der TypedDict explizit zu kennzeichnen, anstatt total=False zu verwenden.

Suggested change
from typing import TypedDict
from typing import NotRequired, TypedDict

Comment on lines +20 to +33
class _SnipeITAssetResponse(TypedDict, total=False):
"""Subset of Snipe-IT `/api/v1/hardware/bytag/{tag}` response we actually
read. Strikt-typisiert statt `dict[str, Any]` — beschränkt sich auf die
Felder die `_payload_to_label` konsumiert. `total=False` weil alle Felder
außer `id` optional sind (User-Mapping kann Snipe-IT-fields ausblenden).

Audit #67 / PR #51 Finding: das alte `dict[str, Any]` hat das Hub-mypy-
strict-Verbot von `Any` in Plugin-Responses verletzt.
"""

id: int
asset_tag: str | None
name: str | None
serial: str | None

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Mit total=False werden alle Felder der TypedDict als optional markiert, einschließlich id. Dies widerspricht dem Docstring, der besagt, dass alle Felder außer id optional sind.

Da das Projekt Python 3.12+ verwendet, ist es sauberer, total=False zu entfernen und stattdessen die optionalen Felder explizit mit NotRequired zu typisieren. Dadurch bleibt id als einziges erforderliches Feld im Typ-System bestehen.

Suggested change
class _SnipeITAssetResponse(TypedDict, total=False):
"""Subset of Snipe-IT `/api/v1/hardware/bytag/{tag}` response we actually
read. Strikt-typisiert statt `dict[str, Any]`beschränkt sich auf die
Felder die `_payload_to_label` konsumiert. `total=False` weil alle Felder
außer `id` optional sind (User-Mapping kann Snipe-IT-fields ausblenden).
Audit #67 / PR #51 Finding: das alte `dict[str, Any]` hat das Hub-mypy-
strict-Verbot von `Any` in Plugin-Responses verletzt.
"""
id: int
asset_tag: str | None
name: str | None
serial: str | None
class _SnipeITAssetResponse(TypedDict):
"""Subset of Snipe-IT /api/v1/hardware/bytag/{tag} response we actually
read. Strikt-typisiert statt dict[str, Any] — beschränkt sich auf die
Felder die _payload_to_label konsumiert.
Audit #67 / PR #51 Finding: das alte dict[str, Any] hat das Hub-mypy-
strict-Verbot von Any in Plugin-Responses verletzt.
"""
id: int
asset_tag: NotRequired[str | None]
name: NotRequired[str | None]
serial: NotRequired[str | None]

@codecov

codecov Bot commented Jun 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.27%. Comparing base (48215b4) to head (567762b).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #122      +/-   ##
==========================================
- Coverage   89.28%   89.27%   -0.02%     
==========================================
  Files          91       91              
  Lines        4257     4262       +5     
  Branches      368      368              
==========================================
+ Hits         3801     3805       +4     
- Misses        358      359       +1     
  Partials       98       98              
Components Coverage Δ
Printer Backends (transport) 86.87% <ø> (ø)
Printer Models (drivers) 88.20% <ø> (ø)
Services 91.20% <ø> (-0.07%) ⬇️
REST API 84.97% <ø> (ø)
Pydantic Schemas 100.00% <ø> (ø)
Integration Plugins 100.00% <100.00%> (ø)
Files with missing lines Coverage Δ
backend/app/integrations/snipeit/plugin.py 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

Flag Coverage Δ
backend 89.27% <100.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 48215b4...567762b. Read the comment docs.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

github-actions Bot pushed a commit that referenced this pull request Jun 15, 2026
## <small>0.10.2 (2026-06-15)</small>

* refactor(main): _resolve_model_id_from_config nimmt PrinterYAMLConfig statt Any (#67) (#123) ([2ff51d2](2ff51d2)), closes [#67](#67) [#123](#123) [#67](#67) [#59](#59) [#67](#67) [#59](#59)
* refactor(snipeit): typisiere response payload als TypedDict statt dict[str, Any] (#67) (#122) ([e88601b](e88601b)), closes [#67](#67) [#122](#122) [#67](#67) [#67](#67) [#51](#51)
* perf(lifespan): plugin-discovery in Thread auslagern (Audit #67) (#121) ([48215b4](48215b4)), closes [#67](#67) [#121](#121) [#67](#67) [#59](#59)
* fix(config): stricter validation for log_level + webhook_api_key (#46) (#116) ([6b8ac30](6b8ac30)), closes [#46](#46) [#116](#116) [#46](#46) [#46](#46) [#46](#46) [#46](#46) [#116](#116)
* fix(print): copies-replication erzeugt UNIQUE job_ids (Round 2 #hangar-109) (#120) ([bd781ae](bd781ae)), closes [#hangar-109](https://github.com/strausmann/label-printer-hub/issues/hangar-109) [#120](#120) [#115](#115)
* fix(print): PrintOptions.copies replicates images for hardware print (#hangar-109) (#115) ([d27bbcc](d27bbcc)), closes [#hangar-109](https://github.com/strausmann/label-printer-hub/issues/hangar-109) [#115](#115) [strausmann/hangar#109](https://github.com/strausmann/hangar/issues/109)
* docs(metrics): präzisiere sse_events_published_total Beschreibung (Audit #67) (#119) ([ab8c4c4](ab8c4c4)), closes [#67](#67) [#119](#119) [#67](#67) [#67](#67) [#65](#65)
* docs(ptouch): korrigiere Tape-Klassen-Namen in ptouch-integration.md (Audit #67) (#118) ([0faab99](0faab99)), closes [#67](#67) [#118](#118) [#67](#67) [#59](#59)
* chore(readme): codecov badge ohne embedded Token (Audit #67) (#117) ([4bb5423](4bb5423)), closes [#67](#67) [#117](#117) [#67](#67) [#59](#59)

[skip ci]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants