Repository navigation
feat(client): rename upload's slot to image, deprecating slot - #151
Conversation
`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
3181614 to
812c33d
Compare
|
Warning LLM Disclosure This post was authored by VerdictNon-breaking for every call that type-checks against
What I amendedMerged as
Behavioral deltasEach row was measured on both trees, same interpreter, with only
No delta, beyond the warning wherever Call-shape matrix: all 98 shapes
|
| # | 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 withoff=0, which exercises the resend branch,subsequent_timeout_sand itsNonefallback. Both runs used the same interpreter (Python 3.14.8, smp 4.3.0, pydantic 2.14.3); onlyPYTHONPATHswitched betweenmain's and this branch'ssrc/. A sidecar file recordedsmpclient.__file__to prove which tree each run imported. Warnings were recorded undersimplefilter("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 (
bytesandbytearrayvariants) against both trees. A probe import of_UPLOAD_SLOT_DEPRECATIONfailed onmainand 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 plaindef, are clean onmainand fail on this branch, on both checkers. A*args, **kwargspassthrough override is clean on both.ICUploadClientdoesn't overrideupload; its ownic_upload(data, image=0)already usesimagefor the number. - smpmgr (at
8cec303, an unmodified copy in throwaway environments):--slot→upload(image, slot)insmpmgr/image_management.py.- Unit tests: 49 passed against smpclient 7.4.0 (its pin),
mainand this PR. They don't exerciseupload. - smpmgr's mypy 1.20.2: clean against all three. With
--enable-error-code deprecated, the one hit isimage_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 toimage_management.py:232. Python hidesDeprecationWarningoutside__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 0doesn't mark the image for test, so MCUboot direct-XIP with revert erases it smpmgr#116) onmainand the pre-amend3181614; the812c33drun didn't finish before this post. The uploads run through the test's own deprecatedclient.upload(signed_image, recovery_image, subsequent_timeout_s=...)(MCUboot serial recovery, warning attributed to that line), and throughpython -m smpmgr upgrade --slot N(N = 1, 2, 4) in a subprocess, whose warning stays hidden.
- Unit tests: 49 passed against smpclient 7.4.0 (its pin),
- Mutation tests. Swapping
upgrade/use_sha, or the two timeouts, in the new internal_upload_image(...)call still type-checks, and the existingtest_uploadcatches both. Removing themmappatterns 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 anoffpast the end of the image. - SHA dropped on resend: with
use_sha=True, a first reply ofoff=0triggers a resend at offset 0 withoutsha, so the finalmatchcheck is skipped. - Undeclared dependency:
typing_extensionsis imported at runtime but isn't in[project].dependencies. It arrives through pydantic today;deprecatedneeds version 4.5 or later.
Nits not taken:
- The overloads type the payload as
bytesonly. That isn't a regression, becausemainrejectedbytearraystatically too. - A
Raises: TypeErrordocstring section. pydoclint flagsRaises:on a function body without araise. - 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
Warning
LLM Disclosure
This post was authored by
claude-opus-5-5on behalf of @JPHutchins. June asked for an smpclient PR that renamesupload'sslotto the SMP wire nameimageand deprecatesslotwith overloads (#150). A/code-review xhighpass ran on the branch and its fixes are amended in. A second session re-reviewed it, tested its compatibility againstmain(evidence), and amended anmmapfix.Summary
SMPClient.upload'sslotwas always the SMP upload request'simagefield ("Image number" insmp). The parameter is nowimage, andslotis deprecated:@deprecated(PEP 702). mypy now reports them as errors, because this PR enables itsdeprecatedcode (see below); pyright strikes them through in editors. Both checkers accept the implementation with notype: ignore.uploadresolves its arguments when called. TheDeprecationWarningis attributed to the caller's line, and a bad call raisesTypeErrorimmediately. Onmain, only binding errors raised at the call; a wrong type surfaced on the firstanext, often as a pydanticValidationError.main's signature sends the same requests. All 98 call shapes, withbytesandbytearraypayloads, were diffed againstmain. Payloadsmainduck-typed,bytearrayandmmap, still work. Two narrower breaks remain:slotthat isn't anintinstance ("2",2.0,Decimal(2), an__index__integer), which pydantic coerced, now raisesTypeError.uploadwithmain's signature now fails mypy ([override]) and pyright (reportIncompatibleMethodOverride). This is inherent to reusing the nameimagewith a new type. Neither smpclient nor smpmgr has one.ImageState.slotandImageErase(slot=)really are slots and are unchanged.Closes #150
Helps resolve intercreate/smpmgr#3: this is the library half of renaming smpmgr's
--slotto--image. That issue's other steps, theupgrademark logic and QEMU coverage, are smpmgr's.Decided in review (@JPHutchins):
src/smpclient/__init__.pygrows to 668 lines and is not split.deprecatederror 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 newuploadshapes, plusSMPSerialTransport's existingline_length/line_buffers/max_smp_encoded_frame_sizeoverloads. Each carries# type: ignore[deprecated]; there is no module-wide override, so any other deprecated call is still reported. pyright'sreportDeprecatedis off in this repo'sstandardmode (it reports nothing for the call), and this PR leaves it alone.Design details: why three overloads, eager resolution, edge cases
imagefield: rename it toimageand deprecateslot#150 sketched? Itsimage: bytesis positional-or-keyword. The implementation needs the payload positional-only asfirmwareandimagekeyword-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.uploadis a plaindefthat resolves its arguments, then returns the private async generator_upload_image. As an async generator it would warn and raise on the firstanext, attributed to whichever frame awaited it (probed:asyncio/tasks.pyunderwait_for).matchon(firmware, image, slot)in_resolve_upload_arguments. It warns forslotorimage=<bytes>, and raisesTypeErrorfor bothslotand an intimage, for a payload given twice, and for a missing payload. The catch-all names the argument types it got. It ends incase _, notassert_never, because mypy 2.4 doesn't narrow a tuple subject toNever.@deprecateddecorators, because PEP 702 checkers ignore names. A test asserts the literals equal the constant.upload(fw, None, True), whereNoneis passed forslot, doesn't warn, becauseNonereads as the default. It also sendsimage=0wheremainleftimageout of the request; SMP treats a missingimageas 0.bytearraypayload is copied whenuploadis called, so changing it before iterating no longer changes what is uploaded.typing.get_overloadsshows 2 of the 3 overloads, because both@deprecatedwrappers share a line number.encoded.pyhas the same quirk.Checks
camaspasses: format, ruff, pydoclint, mypy, pyright, and the tests (424 passed, 14 skipped), on Python 3.14 and 3.10. The intermediatefeatcommit 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