Skip to content

feat(client): rename upload's slot to image, deprecating slot - #151

Merged
JPHutchins merged 2 commits into
mainfrom
feat/#150/upload-image
Dec 4, 2026
Merged

JPHutchins merged 2 commits into
mainfrom
feat/#150/upload-image

Conversation

@JPHutchins

@JPHutchins JPHutchins commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

Warning

LLM Disclosure

This post was authored by claude-opus-5-5 on behalf of @JPHutchins. June asked for an smpclient PR that renames upload's slot to the SMP wire name image and deprecates slot with overloads (#150). A /code-review xhigh pass ran on the branch and its fixes are amended in. A second session re-reviewed it, tested its compatibility against main (evidence), and amended an mmap fix.

Summary

SMPClient.upload's slot was always the SMP upload request's image field ("Image number" in smp). The parameter is now image, and slot is deprecated:

async for offset in client.upload(firmware, image=2):  # new
async for offset in client.upload(firmware, 2):        # DeprecationWarning, same request
async for offset in client.upload(firmware, slot=2):   # DeprecationWarning, same request
async for offset in client.upload(image=firmware):     # DeprecationWarning, same request
  • Typed: there are three overloads, and the two old shapes are @deprecated (PEP 702). mypy now reports them as errors, because this PR enables its deprecated code (see below); pyright strikes them through in editors. Both checkers accept the implementation with no type: ignore.
  • Runtime: upload resolves its arguments when called. The DeprecationWarning is attributed to the caller's line, and a bad call raises TypeError immediately. On main, only binding errors raised at the call; a wrong type surfaced on the first anext, often as a pydantic ValidationError.
  • Compatible: every call that type-checks against main's signature sends the same requests. All 98 call shapes, with bytes and bytearray payloads, were diffed against main. Payloads main duck-typed, bytearray and mmap, still work. Two narrower breaks remain:
    • A slot that isn't an int instance ("2", 2.0, Decimal(2), an __index__ integer), which pydantic coerced, now raises TypeError.
    • A subclass that overrides upload with main's signature now fails mypy ([override]) and pyright (reportIncompatibleMethodOverride). This is inherent to reusing the name image with a new type. Neither smpclient nor smpmgr has one.
  • Consistent: the docstring and both examples are updated. ImageState.slot and ImageErase(slot=) really are slots and are unchanged.

Closes #150

Helps resolve intercreate/smpmgr#3: this is the library half of renaming smpmgr's --slot to --image. That issue's other steps, the upgrade mark logic and QEMU coverage, are smpmgr's.

Decided in review (@JPHutchins):

  1. src/smpclient/__init__.py grows to 668 lines and is not split.
  2. mypy's deprecated error code is enabled (3181614). It is off by default (mypy 2.4.1, default_enabled=False), so until now nothing flagged a call to a deprecated overload. The only hits are 15 test lines that exercise deprecated APIs on purpose: the new upload shapes, plus SMPSerialTransport's existing line_length/line_buffers/max_smp_encoded_frame_size overloads. Each carries # type: ignore[deprecated]; there is no module-wide override, so any other deprecated call is still reported. pyright's reportDeprecated is off in this repo's standard mode (it reports nothing for the call), and this PR leaves it alone.
Design details: why three overloads, eager resolution, edge cases
  • Why not one deprecated overload, as upload(slot=...) is the SMP image field: rename it to image and deprecate slot #150 sketched? Its image: bytes is positional-or-keyword. The implementation needs the payload positional-only as firmware and image keyword-only (int | bytes). mypy ([misc]) and pyright (reportInconsistentOverload) both reject that. Splitting the old signature into its positional half (firmware, /, slot, upgrade, ...) and its keyword half (self, /, *, image: bytes, slot, ...) describes exactly the calls the old signature accepted.
  • Eager resolution. upload is a plain def that resolves its arguments, then returns the private async generator _upload_image. As an async generator it would warn and raise on the first anext, attributed to whichever frame awaited it (probed: asyncio/tasks.py under wait_for).
  • match on (firmware, image, slot) in _resolve_upload_arguments. It warns for slot or image=<bytes>, and raises TypeError for both slot and an int image, for a payload given twice, and for a missing payload. The catch-all names the argument types it got. It ends in case _, not assert_never, because mypy 2.4 doesn't narrow a tuple subject to Never.
  • Warning text. One constant, repeated as a literal in both @deprecated decorators, because PEP 702 checkers ignore names. A test asserts the literals equal the constant.
  • Known, accepted:
    • upload(fw, None, True), where None is passed for slot, doesn't warn, because None reads as the default. It also sends image=0 where main left image out of the request; SMP treats a missing image as 0.
    • A bytearray payload is copied when upload is called, so changing it before iterating no longer changes what is uploaded.
    • typing.get_overloads shows 2 of the 3 overloads, because both @deprecated wrappers share a line number. encoded.py has the same quirk.
Checks

camas passes: format, ruff, pydoclint, mypy, pyright, and the tests (424 passed, 14 skipped), on Python 3.14 and 3.10. The intermediate feat commit also passes on its own. The integration suite wasn't run locally; CI runs it.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Mdn8NixcieCrCpmV9UNADV

JPHutchins and others added 2 commits December 3, 2026 17:37
`SMPClient.upload(image: bytes, slot: int = 0, ...)` sent `slot` as the SMP
`ImageUploadWriteRequest.image` field. smp documents that field as "Image
number"; each SMP server maps it to flash its own way (MCUboot serial
recovery, Zephyr app img_mgmt, DIRECT_UPLOAD builds all differ), and smp's
`ImageState.slot` is a different number with the same name. The parameter is
now `image`, matching the wire field and `smp`, and `slot` is deprecated.

New call shape: `upload(firmware, /, *, image=0, upgrade=..., ...)`. The
payload is positional-only, so its name is not API, and everything after it
is keyword-only, which frees the name `image` for the number.

Overloads (typing_extensions.overload + typing_extensions.deprecated, the
pattern SMPSerialTransport.__init__ already uses):

1. `(self, firmware: bytes, /, *, image: int = ..., ...)`: current.
2. `@deprecated (self, firmware: bytes, /, slot: int = ..., upgrade, ...)`:
   positional `slot`, `slot=`, positional `upgrade`/timeouts.
3. `@deprecated (self, /, *, image: bytes, slot: int = ..., ...)`: the old
   keyword name of the payload, `image=<bytes>`.

The stubs use `= ...` defaults, as SMPSerialTransport.__init__'s overloads
do, so the implementation is the only place the defaults live.

Issue #150 sketched a single deprecated overload with the old signature
`(self, image: bytes, slot: int = 0, ...)`. Both mypy ("Overloaded function
implementation does not accept all possible parameters of signature 2
[misc]") and pyright (reportInconsistentOverload) reject it: its `image` is
positional-or-keyword, while the implementation must take the payload
positionally as `firmware` (positional-only) and by keyword as `image`
(keyword-only, `int | bytes | None`); a single parameter can't be both
without colliding with `upload(data, image=2)`. Splitting the old signature
into its positional (2) and keyword (3) halves describes exactly the calls
the old signature accepted, and both checkers accept the implementation
without any `type: ignore`. Overload 3 needs `self, /` because the
implementation's `/` after `firmware` makes `self` positional-only too.

The runtime implementation resolves every old call shape with a `match` on
`(firmware, image, slot)` in `_resolve_upload_arguments`:
- `upload(data)`, `upload(data, image=N)`: no warning.
- `slot` given, or `image` is bytes: `DeprecationWarning`, same request.
- both `slot` and an int `image`: `TypeError`.
- the payload both positionally and as `image=`, or missing: `TypeError`,
  as Python itself raised for the old signature.

`upload` is now a plain `def` that resolves its arguments eagerly and
returns the private async generator `_upload_image`. So the `TypeError`s
raise at the call, as argument binding did on main, and the
`DeprecationWarning` (`stacklevel=3`: emitted from the helper, one frame
below `upload`) is attributed to the code that called `upload`. Had `upload`
stayed an async generator, both would surface on the first `anext`, and the
warning would point at whichever frame awaited it, e.g. asyncio/tasks.py
under `asyncio.wait_for(anext(gen), ...)`, hiding it from `__main__` and
module-scoped warning filters. The tests assert both happen before
iteration. pydoclint therefore wants `Returns:` instead of `Yields:`/`Raises:`
in the public docstring.

The `match` ends in `case _` rather than `assert_never`: mypy 2.4 does not
narrow a tuple subject to `Never` after exhaustive tuple patterns (it
reports "Missing return statement"), while pyright does. A missing payload,
`(None, None | int, _)`, has its own arm; the catch-all names the argument
types it received.

A `bytearray` payload, which the `bytes` annotation never admitted, worked
on main by duck typing (pydantic turns the slices into bytes) and still
type-checks under mypy 1.x's default `--no-strict-bytes`. An `mmap.mmap`
payload worked the same way: `len()`, `sha256()` and slicing accept it, and
its slices are `bytes`. So the payload arms match
`bytes() | bytearray() | mmap()` and upload a `bytes(...)` snapshot of the
whole buffer; only the implementation's annotations widen, the overloads
stay `bytes`. `memoryview` and `array.array` stay rejected, as they were on
main (a pydantic ValidationError there), and so does a `str` payload, which
main uploaded as UTF-8 only with `use_sha=False`. A `slot` that is not an
`int` instance now raises `TypeError` at the call: "2", 2.0, `Decimal(2)`
and `__index__` integers such as numpy's, all of which pydantic coerced on
main. `slot` was always typed `int` and is deprecated.

The warning text is a module constant, `_UPLOAD_SLOT_DEPRECATION`, which
both `@deprecated` decorators must repeat as a string literal, because PEP
702 type checkers ignore a name reference there. A test asserts that the two
literals equal the constant, so they can't drift.

Type checker reporting of the deprecated overloads, checked with a scratch
file of every call shape:
- mypy: the `deprecated` error code is off by default and this repo does not
  enable it. With `--enable-error-code deprecated` mypy flags exactly the
  five deprecated shapes (`upload(d, 2)`, `slot=2`, `image=d`,
  `image=d, slot=2`, `upload(d, 0, True)`) and none of `upload(d)`,
  `upload(d, image=2)`, `upload(d, upgrade=True, use_sha=False)`. Both
  `TypeError` shapes are `[call-overload]` errors regardless.
- pyright: `reportDeprecated` is off in "standard" mode, so the repo's
  pyright run reports nothing for the deprecated shapes (editors render them
  struck through); the `TypeError` shapes are errors.

The docstring describes `image` as the SMP image number interpreted by the
server, not a slot. The BLE and USB examples now pass `image=`; the USB
example's local `slot` was the image number and is renamed. docs/ and
README.md do not mention upload's slot. `ImageState.slot` and
`ImageErase(slot=...)` really are slots and are unchanged. Renaming
smpmgr's `--slot` to `--image` is intercreate/smpmgr#3; this is the library
half of it.

Closes #150

Co-Authored-By: claude-opus-5-5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Mdn8NixcieCrCpmV9UNADV
mypy reports use of PEP 702 `@deprecated` APIs only under the `deprecated`
error code, which is off by default (mypy 2.4.1: `default_enabled=False`
in mypy/errorcodes.py). Without it, `camas` couldn't see a call to a
deprecated overload such as `upload(firmware, 2)` or
`SMPSerialTransport(line_length=...)`. Enable it so a deprecated call in
src/ or examples/ fails the type check.

The only hits are tests that call deprecated APIs on purpose, to pin
their runtime behavior: the `upload` `slot`/`image=<bytes>` shapes (#150)
and SMPSerialTransport's `max_smp_encoded_frame_size`/`line_length`/
`line_buffers` overloads. Those 15 lines carry
`# type: ignore[deprecated]`; no module-wide override, so any other
deprecated call in tests is still reported.

pyright's `reportDeprecated` is off in the "standard" mode this repo
uses; this change leaves pyright alone.

Co-Authored-By: claude-opus-5-5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Mdn8NixcieCrCpmV9UNADV
@JPHutchins
JPHutchins force-pushed the feat/#150/upload-image branch from 3181614 to 812c33d Compare December 4, 2026 01:43
@JPHutchins
JPHutchins merged commit b80164a into main Dec 4, 2026
33 checks passed
@JPHutchins
JPHutchins deleted the feat/#150/upload-image branch December 4, 2026 01:53
@JPHutchins

Copy link
Copy Markdown
Collaborator Author

Warning

LLM Disclosure

This post was authored by claude-opus-5-5 on behalf of @JPHutchins. June asked for a second /code-review xhigh of this PR and for hard evidence on whether it is non-breaking: a runtime and static differential against main, plus subclass and smpmgr checks. Fixes are amended into the two commits.

Verdict

Non-breaking for every call that type-checks against main's signature, at runtime and under the type checkers' default settings. Two narrower breaks remain. Both are inherent to the design, and both hit code that main's types already rejected or that neither smpclient nor smpmgr contains:

Who Result
Callers of main's signature, at runtime ✅ All 98 call shapes, with bytes and bytearray payloads, send the same requests as on main (1372 requests compared). DeprecationWarning fires exactly for the 82 deprecated shapes, attributed to the caller's line.
The same callers, statically ✅ mypy 2.4 and pyright standard report nothing new by default. With mypy's deprecated code or pyright's reportDeprecated enabled, they report only that, on exactly the 82 lines.
A subclass that overrides upload with main's signature ❌ Static only: mypy [override], pyright reportIncompatibleMethodOverride. At runtime it still works. The override would have to accept image=<int>, which main's image: bytes can't. No such override exists in smpclient or smpmgr.
Inputs main's types rejected but its runtime tolerated ⚠️ A non-int slot ("2", 2.0, Decimal(2), an __index__ integer) or a str payload now raises TypeError. mmap payloads broke too; that is fixed (below).
smpmgr ✅ Its unit tests, its own mypy, and its real upload_with_progress_bar all pass: requests identical to main for --slot 0, 1, 2 and 4. QEMU e2e: 9 passed and 4 expected failures (smpmgr marks them for intercreate/smpmgr#116), the same on main and 3181614. A run against 812c33d didn't finish before this post; the amend only added mmap handling, which smpmgr's bytes payload never reaches.

What I amended

Merged as b80164a. The branch was a50f581 feat, then 812c33d build. It is still two commits, and the build commit changed only its parent.

  • mmap.mmap payloads work again. main accepted them by duck typing: len(), sha256() and slicing all work, and the slices are bytes. The PR's bytes() | bytearray() patterns rejected them with TypeError. The review found this. Three new tests (positional, slot, image=) fail without the fix.
  • Warning-site test: test_upload_slot_is_deprecated now asserts that the warning's (filename, lineno) equals the calling lambda's co_filename/co_firstlineno. Before, it compared only the filename against __file__, which fails after a checkout moves.
  • The feat commit message now names every coerced-slot case and says this PR is the library half of --slot argument unclear smpmgr#3.
  • Checks: lint and types are green. The tests pass on Python 3.14 and 3.10 (424 passed, 14 skipped). The intermediate feat commit is green on its own.

Behavioral deltas

Each row was measured on both trees, same interpreter, with only src/ swapped:

Input main This PR
Any deprecated shape silent DeprecationWarning; fails under -W error or filterwarnings = error
slot="2", 2.0, Decimal(2) or an __index__ object pydantic coerces it and sends image=2 TypeError at the call
slot=2.5, or a memoryview or array payload pydantic ValidationError (a ValueError) on the first anext TypeError at the call
str payload TypeError on the first anext; uploaded as UTF-8 if use_sha=False TypeError at the call
None payload, no arguments, the payload twice, 7 positionals TypeError with Python's binding message (on anext for a None payload) TypeError at the call, with the PR's message
slot=None (untyped) image left out of the request image=0 sent. The first chunk is 7 bytes smaller, so later offsets shift. SMP treats a missing image as 0.
bytearray changed between the call and iterating uploads the changed bytes uploads a copy taken at the call
inspect.isasyncgenfunction(SMPClient.upload) True False; upload still returns an async generator
inspect.signature(SMPClient.upload) (self, image: bytes, slot: int = 0, ...) (self, firmware=None, /, slot=None, ..., *, image=None)
The returned generator's __qualname__ SMPClient.upload SMPClient._upload_image

No delta, beyond the warning wherever slot or image=<bytes> is given: slot=True, an IntEnum, -1, a bytes subclass, upgrade=None, first_timeout_s=None, functools.partial(c.upload, slot=2), *args/**kwargs spreading, an unknown keyword, and a subclass calling super().upload(fw, 2).

Call-shape matrix: all 98 shapes main's signature accepts

Shapes: the payload is passed positionally or as image=. After it, every positional prefix, then every subset of the remaining parameters by keyword, plus explicit slot=0. Each parameter has its own sentinel so a swap would show: slot=2, upgrade=True, first_timeout_s=3.25, subsequent_timeout_s=7.75, use_sha=False, and a client timeout of 11.5. "Requests" compares every request: masked wire bytes (sequence byte zeroed), off/len/image/upgrade/sha, timeout_s, and the yielded offsets. pyright ran with reportDeprecated enabled; in this repo's standard mode it reports nothing for these calls.

# call (fw = payload) requests vs main (bytes / bytearray) DeprecationWarning mypy (main → PR) pyright (main → PR)
1 upload(fw) same / same none clean → clean clean → clean
2 upload(fw, slot=2) same / same 1, caller's line clean → deprecated clean → reportDeprecated
3 upload(fw, upgrade=True) same / same none clean → clean clean → clean
4 upload(fw, first_timeout_s=3.25) same / same none clean → clean clean → clean
5 upload(fw, subsequent_timeout_s=7.75) same / same none clean → clean clean → clean
6 upload(fw, use_sha=False) same / same none clean → clean clean → clean
7 upload(fw, slot=2, upgrade=True) same / same 1, caller's line clean → deprecated clean → reportDeprecated
8 upload(fw, slot=2, first_timeout_s=3.25) same / same 1, caller's line clean → deprecated clean → reportDeprecated
9 upload(fw, slot=2, subsequent_timeout_s=7.75) same / same 1, caller's line clean → deprecated clean → reportDeprecated
10 upload(fw, slot=2, use_sha=False) same / same 1, caller's line clean → deprecated clean → reportDeprecated
11 upload(fw, upgrade=True, first_timeout_s=3.25) same / same none clean → clean clean → clean
12 upload(fw, upgrade=True, subsequent_timeout_s=7.75) same / same none clean → clean clean → clean
13 upload(fw, upgrade=True, use_sha=False) same / same none clean → clean clean → clean
14 upload(fw, first_timeout_s=3.25, subsequent_timeout_s=7.75) same / same none clean → clean clean → clean
15 upload(fw, first_timeout_s=3.25, use_sha=False) same / same none clean → clean clean → clean
16 upload(fw, subsequent_timeout_s=7.75, use_sha=False) same / same none clean → clean clean → clean
17 upload(fw, slot=2, upgrade=True, first_timeout_s=3.25) same / same 1, caller's line clean → deprecated clean → reportDeprecated
18 upload(fw, slot=2, upgrade=True, subsequent_timeout_s=7.75) same / same 1, caller's line clean → deprecated clean → reportDeprecated
19 upload(fw, slot=2, upgrade=True, use_sha=False) same / same 1, caller's line clean → deprecated clean → reportDeprecated
20 upload(fw, slot=2, first_timeout_s=3.25, subsequent_timeout_s=7.75) same / same 1, caller's line clean → deprecated clean → reportDeprecated
21 upload(fw, slot=2, first_timeout_s=3.25, use_sha=False) same / same 1, caller's line clean → deprecated clean → reportDeprecated
22 upload(fw, slot=2, subsequent_timeout_s=7.75, use_sha=False) same / same 1, caller's line clean → deprecated clean → reportDeprecated
23 upload(fw, upgrade=True, first_timeout_s=3.25, subsequent_timeout_s=7.75) same / same none clean → clean clean → clean
24 upload(fw, upgrade=True, first_timeout_s=3.25, use_sha=False) same / same none clean → clean clean → clean
25 upload(fw, upgrade=True, subsequent_timeout_s=7.75, use_sha=False) same / same none clean → clean clean → clean
26 upload(fw, first_timeout_s=3.25, subsequent_timeout_s=7.75, use_sha=False) same / same none clean → clean clean → clean
27 upload(fw, slot=2, upgrade=True, first_timeout_s=3.25, subsequent_timeout_s=7.75) same / same 1, caller's line clean → deprecated clean → reportDeprecated
28 upload(fw, slot=2, upgrade=True, first_timeout_s=3.25, use_sha=False) same / same 1, caller's line clean → deprecated clean → reportDeprecated
29 upload(fw, slot=2, upgrade=True, subsequent_timeout_s=7.75, use_sha=False) same / same 1, caller's line clean → deprecated clean → reportDeprecated
30 upload(fw, slot=2, first_timeout_s=3.25, subsequent_timeout_s=7.75, use_sha=False) same / same 1, caller's line clean → deprecated clean → reportDeprecated
31 upload(fw, upgrade=True, first_timeout_s=3.25, subsequent_timeout_s=7.75, use_sha=False) same / same none clean → clean clean → clean
32 upload(fw, slot=2, upgrade=True, first_timeout_s=3.25, subsequent_timeout_s=7.75, use_sha=False) same / same 1, caller's line clean → deprecated clean → reportDeprecated
33 upload(fw, 2) same / same 1, caller's line clean → deprecated clean → reportDeprecated
34 upload(fw, 2, upgrade=True) same / same 1, caller's line clean → deprecated clean → reportDeprecated
35 upload(fw, 2, first_timeout_s=3.25) same / same 1, caller's line clean → deprecated clean → reportDeprecated
36 upload(fw, 2, subsequent_timeout_s=7.75) same / same 1, caller's line clean → deprecated clean → reportDeprecated
37 upload(fw, 2, use_sha=False) same / same 1, caller's line clean → deprecated clean → reportDeprecated
38 upload(fw, 2, upgrade=True, first_timeout_s=3.25) same / same 1, caller's line clean → deprecated clean → reportDeprecated
39 upload(fw, 2, upgrade=True, subsequent_timeout_s=7.75) same / same 1, caller's line clean → deprecated clean → reportDeprecated
40 upload(fw, 2, upgrade=True, use_sha=False) same / same 1, caller's line clean → deprecated clean → reportDeprecated
41 upload(fw, 2, first_timeout_s=3.25, subsequent_timeout_s=7.75) same / same 1, caller's line clean → deprecated clean → reportDeprecated
42 upload(fw, 2, first_timeout_s=3.25, use_sha=False) same / same 1, caller's line clean → deprecated clean → reportDeprecated
43 upload(fw, 2, subsequent_timeout_s=7.75, use_sha=False) same / same 1, caller's line clean → deprecated clean → reportDeprecated
44 upload(fw, 2, upgrade=True, first_timeout_s=3.25, subsequent_timeout_s=7.75) same / same 1, caller's line clean → deprecated clean → reportDeprecated
45 upload(fw, 2, upgrade=True, first_timeout_s=3.25, use_sha=False) same / same 1, caller's line clean → deprecated clean → reportDeprecated
46 upload(fw, 2, upgrade=True, subsequent_timeout_s=7.75, use_sha=False) same / same 1, caller's line clean → deprecated clean → reportDeprecated
47 upload(fw, 2, first_timeout_s=3.25, subsequent_timeout_s=7.75, use_sha=False) same / same 1, caller's line clean → deprecated clean → reportDeprecated
48 upload(fw, 2, upgrade=True, first_timeout_s=3.25, subsequent_timeout_s=7.75, use_sha=False) same / same 1, caller's line clean → deprecated clean → reportDeprecated
49 upload(fw, 2, True) same / same 1, caller's line clean → deprecated clean → reportDeprecated
50 upload(fw, 2, True, first_timeout_s=3.25) same / same 1, caller's line clean → deprecated clean → reportDeprecated
51 upload(fw, 2, True, subsequent_timeout_s=7.75) same / same 1, caller's line clean → deprecated clean → reportDeprecated
52 upload(fw, 2, True, use_sha=False) same / same 1, caller's line clean → deprecated clean → reportDeprecated
53 upload(fw, 2, True, first_timeout_s=3.25, subsequent_timeout_s=7.75) same / same 1, caller's line clean → deprecated clean → reportDeprecated
54 upload(fw, 2, True, first_timeout_s=3.25, use_sha=False) same / same 1, caller's line clean → deprecated clean → reportDeprecated
55 upload(fw, 2, True, subsequent_timeout_s=7.75, use_sha=False) same / same 1, caller's line clean → deprecated clean → reportDeprecated
56 upload(fw, 2, True, first_timeout_s=3.25, subsequent_timeout_s=7.75, use_sha=False) same / same 1, caller's line clean → deprecated clean → reportDeprecated
57 upload(fw, 2, True, 3.25) same / same 1, caller's line clean → deprecated clean → reportDeprecated
58 upload(fw, 2, True, 3.25, subsequent_timeout_s=7.75) same / same 1, caller's line clean → deprecated clean → reportDeprecated
59 upload(fw, 2, True, 3.25, use_sha=False) same / same 1, caller's line clean → deprecated clean → reportDeprecated
60 upload(fw, 2, True, 3.25, subsequent_timeout_s=7.75, use_sha=False) same / same 1, caller's line clean → deprecated clean → reportDeprecated
61 upload(fw, 2, True, 3.25, 7.75) same / same 1, caller's line clean → deprecated clean → reportDeprecated
62 upload(fw, 2, True, 3.25, 7.75, use_sha=False) same / same 1, caller's line clean → deprecated clean → reportDeprecated
63 upload(fw, 2, True, 3.25, 7.75, False) same / same 1, caller's line clean → deprecated clean → reportDeprecated
64 upload(image=fw) same / same 1, caller's line clean → deprecated clean → reportDeprecated
65 upload(image=fw, slot=2) same / same 1, caller's line clean → deprecated clean → reportDeprecated
66 upload(image=fw, upgrade=True) same / same 1, caller's line clean → deprecated clean → reportDeprecated
67 upload(image=fw, first_timeout_s=3.25) same / same 1, caller's line clean → deprecated clean → reportDeprecated
68 upload(image=fw, subsequent_timeout_s=7.75) same / same 1, caller's line clean → deprecated clean → reportDeprecated
69 upload(image=fw, use_sha=False) same / same 1, caller's line clean → deprecated clean → reportDeprecated
70 upload(image=fw, slot=2, upgrade=True) same / same 1, caller's line clean → deprecated clean → reportDeprecated
71 upload(image=fw, slot=2, first_timeout_s=3.25) same / same 1, caller's line clean → deprecated clean → reportDeprecated
72 upload(image=fw, slot=2, subsequent_timeout_s=7.75) same / same 1, caller's line clean → deprecated clean → reportDeprecated
73 upload(image=fw, slot=2, use_sha=False) same / same 1, caller's line clean → deprecated clean → reportDeprecated
74 upload(image=fw, upgrade=True, first_timeout_s=3.25) same / same 1, caller's line clean → deprecated clean → reportDeprecated
75 upload(image=fw, upgrade=True, subsequent_timeout_s=7.75) same / same 1, caller's line clean → deprecated clean → reportDeprecated
76 upload(image=fw, upgrade=True, use_sha=False) same / same 1, caller's line clean → deprecated clean → reportDeprecated
77 upload(image=fw, first_timeout_s=3.25, subsequent_timeout_s=7.75) same / same 1, caller's line clean → deprecated clean → reportDeprecated
78 upload(image=fw, first_timeout_s=3.25, use_sha=False) same / same 1, caller's line clean → deprecated clean → reportDeprecated
79 upload(image=fw, subsequent_timeout_s=7.75, use_sha=False) same / same 1, caller's line clean → deprecated clean → reportDeprecated
80 upload(image=fw, slot=2, upgrade=True, first_timeout_s=3.25) same / same 1, caller's line clean → deprecated clean → reportDeprecated
81 upload(image=fw, slot=2, upgrade=True, subsequent_timeout_s=7.75) same / same 1, caller's line clean → deprecated clean → reportDeprecated
82 upload(image=fw, slot=2, upgrade=True, use_sha=False) same / same 1, caller's line clean → deprecated clean → reportDeprecated
83 upload(image=fw, slot=2, first_timeout_s=3.25, subsequent_timeout_s=7.75) same / same 1, caller's line clean → deprecated clean → reportDeprecated
84 upload(image=fw, slot=2, first_timeout_s=3.25, use_sha=False) same / same 1, caller's line clean → deprecated clean → reportDeprecated
85 upload(image=fw, slot=2, subsequent_timeout_s=7.75, use_sha=False) same / same 1, caller's line clean → deprecated clean → reportDeprecated
86 upload(image=fw, upgrade=True, first_timeout_s=3.25, subsequent_timeout_s=7.75) same / same 1, caller's line clean → deprecated clean → reportDeprecated
87 upload(image=fw, upgrade=True, first_timeout_s=3.25, use_sha=False) same / same 1, caller's line clean → deprecated clean → reportDeprecated
88 upload(image=fw, upgrade=True, subsequent_timeout_s=7.75, use_sha=False) same / same 1, caller's line clean → deprecated clean → reportDeprecated
89 upload(image=fw, first_timeout_s=3.25, subsequent_timeout_s=7.75, use_sha=False) same / same 1, caller's line clean → deprecated clean → reportDeprecated
90 upload(image=fw, slot=2, upgrade=True, first_timeout_s=3.25, subsequent_timeout_s=7.75) same / same 1, caller's line clean → deprecated clean → reportDeprecated
91 upload(image=fw, slot=2, upgrade=True, first_timeout_s=3.25, use_sha=False) same / same 1, caller's line clean → deprecated clean → reportDeprecated
92 upload(image=fw, slot=2, upgrade=True, subsequent_timeout_s=7.75, use_sha=False) same / same 1, caller's line clean → deprecated clean → reportDeprecated
93 upload(image=fw, slot=2, first_timeout_s=3.25, subsequent_timeout_s=7.75, use_sha=False) same / same 1, caller's line clean → deprecated clean → reportDeprecated
94 upload(image=fw, upgrade=True, first_timeout_s=3.25, subsequent_timeout_s=7.75, use_sha=False) same / same 1, caller's line clean → deprecated clean → reportDeprecated
95 upload(image=fw, slot=2, upgrade=True, first_timeout_s=3.25, subsequent_timeout_s=7.75, use_sha=False) same / same 1, caller's line clean → deprecated clean → reportDeprecated
96 upload(fw, 0) same / same 1, caller's line clean → deprecated clean → reportDeprecated
97 upload(fw, slot=0) same / same 1, caller's line clean → deprecated clean → reportDeprecated
98 upload(image=fw, slot=0) same / same 1, caller's line clean → deprecated clean → reportDeprecated

bytearray payloads, statically: they already fail on main (98 arg-type) and fail on this PR as call-overload. With --no-strict-bytes (mypy 1.x's default), main accepts them and this PR reports only the 82 [deprecated] lines.

Method
  • Runtime differential. A generator wrote one module of lambdas, one per shape. A harness ran each shape twice, once per payload type, against a mock request. The mock spans 7 chunks and answers the first request with off=0, which exercises the resend branch, subsequent_timeout_s and its None fallback. Both runs used the same interpreter (Python 3.14.8, smp 4.3.0, pydantic 2.14.3); only PYTHONPATH switched between main's and this branch's src/. A sidecar file recorded smpclient.__file__ to prove which tree each run imported. Warnings were recorded under simplefilter("always"), and the expected deprecated set came from the generator, not from this branch.
  • Static differential. mypy 2.4.1 and pyright 1.1.411 checked the same modules (bytes and bytearray variants) against both trees. A probe import of _UPLOAD_SLOT_DEPRECATION failed on main and resolved on this branch, proving which tree each checker read. A per-line comparison found no mismatch between flagged and expected-deprecated lines.
  • Subclasses. Overrides with main's signature, both as an async generator and as a plain def, are clean on main and fail on this branch, on both checkers. A *args, **kwargs passthrough override is clean on both. ICUploadClient doesn't override upload; its own ic_upload(data, image=0) already uses image for the number.
  • smpmgr (at 8cec303, an unmodified copy in throwaway environments): --slot → upload(image, slot) in smpmgr/image_management.py.
    • Unit tests: 49 passed against smpclient 7.4.0 (its pin), main and this PR. They don't exercise upload.
    • smpmgr's mypy 1.20.2: clean against all three. With --enable-error-code deprecated, the one hit is image_management.py:232.
    • Its real upload_with_progress_bar, driven with a recording mock: identical requests for the default slot and for 0, 1, 2 and 4. The warning is attributed to image_management.py:232. Python hides DeprecationWarning outside __main__ by default, so CLI users won't see it.
    • QEMU e2e: QEMU e2e (-m e2e, Zephyr application and MCUboot serial recovery servers): 9 passed and 4 xfailed (upgrade --slot 0 doesn't mark the image for test, so MCUboot direct-XIP with revert erases it smpmgr#116) on main and the pre-amend 3181614; the 812c33d run didn't finish before this post. The uploads run through the test's own deprecated client.upload(signed_image, recovery_image, subsequent_timeout_s=...) (MCUboot serial recovery, warning attributed to that line), and through python -m smpmgr upgrade --slot N (N = 1, 2, 4) in a subprocess, whose warning stays hidden.
  • Mutation tests. Swapping upgrade/use_sha, or the two timeouts, in the new internal _upload_image(...) call still type-checks, and the existing test_upload catches both. Removing the mmap patterns fails the 3 new tests.
Review findings not fixed here

All three predate this PR. My harness confirms the first two behave the same on main.

  • No progress guard: the upload loop never ends if the server repeats an off, or returns an off past the end of the image.
  • SHA dropped on resend: with use_sha=True, a first reply of off=0 triggers a resend at offset 0 without sha, so the final match check is skipped.
  • Undeclared dependency: typing_extensions is imported at runtime but isn't in [project].dependencies. It arrives through pydantic today; deprecated needs version 4.5 or later.

Nits not taken:

  • The overloads type the payload as bytes only. That isn't a regression, because main rejected bytearray statically too.
  • A Raises: TypeError docstring section. pydoclint flags Raises: on a function body without a raise.
  • The file length, which you decided earlier.
Open choice

The non-int slot row could be removed by passing slot through unvalidated on the deprecated path, so pydantic coerces it as before. The PR currently pins slot=2.0 → TypeError in _INVALID_UPLOAD_CALLS, so I left it as it is.

🤖 Generated with Claude Code

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.

--slot argument unclear upload(slot=...) is the SMP image field: rename it to image and deprecate slot

1 participant