-
Notifications
You must be signed in to change notification settings - Fork 23
Jp/fix linter (ignore) #91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -37,7 +37,7 @@ | |||||
| from smp import message as smpmsg | ||||||
| from typing_extensions import assert_never | ||||||
|
|
||||||
| from smpclient.exceptions import SMPBadSequence, SMPUploadError | ||||||
| from smpclient.exceptions import SMPBadSequence, SMPUploadError, SMPValidationException | ||||||
| from smpclient.generics import SMPRequest, TEr1, TEr2, TRep, error, success | ||||||
| from smpclient.requests.file_management import FileDownload, FileUpload | ||||||
| from smpclient.requests.image_management import ImageUploadWrite | ||||||
|
|
@@ -52,6 +52,47 @@ | |||||
| logger = logging.getLogger(__name__) | ||||||
|
|
||||||
|
|
||||||
| def _hexdump_ascii(data: bytes) -> str: | ||||||
| """Python 3.12+ has builtin hexdump, prior to that we need to reinvent the wheel.""" | ||||||
| lines = [] | ||||||
| for i in range(0, len(data), 16): | ||||||
| chunk = data[i : i + 16] | ||||||
| hexpart = " ".join(f"{b:02x}" for b in chunk) | ||||||
| ascpart = "".join(chr(b) if 32 <= b <= 126 else "." for b in chunk) | ||||||
| lines.append(f"\t{i:04x} {hexpart:<47} {ascpart}") | ||||||
| return "\n".join(lines) | ||||||
|
|
||||||
|
|
||||||
| def _prettify_validation_error(exc: ValidationError) -> str: | ||||||
| lines: list[str] = [] | ||||||
| for err in exc.errors(): | ||||||
| err_type = err["type"] | ||||||
| msg = err["msg"] | ||||||
| loc = ".".join(str(x) for x in err["loc"]) | ||||||
| lines.append(f"\t\t[{err_type}] {msg}: {loc}; input: {err['input']})") | ||||||
|
||||||
| lines.append(f"\t\t[{err_type}] {msg}: {loc}; input: {err['input']})") | |
| lines.append(f"\t\t[{err_type}] {msg}: {loc}; input: {err['input']}") |
Copilot
AI
Feb 24, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Type annotations for errs are inconsistent: _smp_validation_error_message() declares errs: dict[type[smpmsg.Response], ValidationError], but request() builds errs: dict[Type, ValidationError] and includes error classes (_ErrorV1/_ErrorV2). This is likely to fail mypy due to dict invariance. Align the types (e.g., make both use dict[type[object] | type[Any], ValidationError], or tighten request() to the exact common base type).
| errs: dict[type[smpmsg.Response], ValidationError], | |
| errs: dict[Type, ValidationError], |
Copilot
AI
Feb 24, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
request() now raises SMPValidationException instead of bubbling a pydantic.ValidationError when the frame can't be parsed. There are existing SMPClient request tests, but none covering this new failure mode; please add/adjust a test to assert the new exception type and (at minimum) that details contains header/frame context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
_hexdump_asciidocstring claims Python 3.12+ has a built-in hexdump; the stdlib doesn't provide a general-purpose bytes hexdump helper. Consider updating the docstring to reflect why this helper exists (e.g., for readable debug logging) without referencing a non-existent built-in.