Skip to content

fix(const): make Command.get reject a non-str key as Method.get does (#1824) - #1826

Merged
JarryShaw merged 1 commit into
mainfrom
fix/1824-command-get-key-type
Oct 16, 2026
Merged

JarryShaw merged 1 commit into
mainfrom
fix/1824-command-get-key-type

Conversation

@JarryShaw

Copy link
Copy Markdown
Owner

Please follow the guide below

What is the purpose of your pull request?

Tick the commit type your subject line carries.

  • fix — corrects a defect
  • feat — adds a feature
  • perf — changes performance, not behaviour
  • refactor — changes neither behaviour nor performance
  • test — tests only
  • docs — documentation only
  • ci — workflows or build tooling
  • release — bumps the version or rolls up a distribution
  • chore — anything else

Description

Closes #1824. Command.get was a staticmethod that called key.upper() on any key:

  • get(b'\x01') minted a member keyed by bytes;
  • get(-1) raised a builtin AttributeError and ignored default.

It now follows Method.get (#908). It is a classmethod, and a non-str key goes to EnumLookup.get, whose _validate_value (from #1823) raises EnumValueError. Mirroring Method.get, default does not rescue a refused key: this override's default is the value of the unregistered member it builds, not a registered fallback.

A str key behaves exactly as before: a case-insensitive lookup, with the unregistered-member fallback in the caller's casing.

  • Template: changed in pcapkit/vendor/ftp/command.py, and the const file was regenerated offline. An AST check against main shows that only Command.get and the _validate_value docstring changed, and no member data. FEATCode.get was already correct.
  • Directive: .. versionchanged:: 1.5.0 on Command.get. registry-protocol.rst and test_conventions_doc_claims.py no longer list it as a staticmethod.
  • Tests: the new tests/const/test_const_ftp_command_get_key_type_1824_unit.py covers each key type, a key paired with a default, case handling and parity with Method.get. It fails 9 times on main. tests/const (355 passed) and tests/project (959 passed, 1 skipped) pass.

…1824)

Command.get was a staticmethod that called key.upper() on any key, so a
bytes key returned an unregistered member keyed by the bytes object and an
int key raised a builtin AttributeError, ignoring default.

- The vendor template's get is now a classmethod that hands a non-str key
  to EnumLookup.get, whose _validate_value call raises EnumValueError.
  default is not forwarded there, as Method.get forwards none, so a refused
  key raises with or without one. A str key keeps the case-insensitive
  lookup and the unregistered-member fallback unchanged.
- pcapkit/const/ftp/command.py is re-rendered offline from the template;
  only get and its docstring change, plus _validate_value's docstring,
  which now says get reaches it too.
- registry-protocol.rst no longer lists Command.get as a surviving
  staticmethod, and the tests that pinned that shape follow.
- A new test pins bytes, int, int-with-default and the str cases, and fails
  on main.

Closes #1824
@JarryShaw JarryShaw added fix Pull requests that fix a defect (fix: subject prefix) const Regenerated IANA or vendor constant tables; members keep their numeric values review: running A cross-review is in flight against the current head - no verdict yet labels Oct 16, 2026
@JarryShaw JarryShaw moved this to In review in PyPCAPKit Oct 16, 2026
@JarryShaw

Copy link
Copy Markdown
Owner Author

Verdict: GOOD TO GO at 9409c4589. A Sonnet cross-review (author: Opus) re-derived the following:

  • Non-str keys: bytes, int, None, float and container keys all raise EnumValueError, including when a default is given, which matches Method.get on main.
  • str keys: behaviour is identical to main, row for row.
  • Callers: the library's only caller passes a decoded str.
  • Generated file: the template, rendered against live IANA data, is byte-identical to the committed const file. The AST diff touches only Command.get and the _validate_value docstring.
  • Mutations: eight were applied, including restoring staticmethod, forwarding default, accepting bytes and case-sensitive lookup. The new tests caught every one.
  • Test suites: tests/const, tests/vendor and tests/project pass.

@JarryShaw JarryShaw added review: good-to-go Cross-review at the current head says ready; CI state is separate and removed review: running A cross-review is in flight against the current head - no verdict yet labels Oct 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Coverage: 90.05% (unit tier, Python 3.15, 9409c4589, Unit Tests run success)

Package Statements Missed Branches Partial Cover
pcapkit (top level) 104 2 20 2 96.77%
pcapkit/const 19595 881 2618 867 92.11%
pcapkit/corekit 2462 69 780 35 96.55%
pcapkit/dumpkit 276 3 100 3 98.40%
pcapkit/foundation 2915 164 1016 34 93.59%
pcapkit/interface 138 7 52 5 93.68%
pcapkit/protocols 17408 224 4580 189 98.10%
pcapkit/toolkit 872 177 298 8 77.18%
pcapkit/utilities 512 2 158 4 99.10%
pcapkit/vendor 4407 2342 1010 157 43.27%

Per-file detail: the coverage-html artifact of this run.

@JarryShaw
JarryShaw merged commit 542f278 into main Oct 16, 2026
59 checks passed
@JarryShaw
JarryShaw deleted the fix/1824-command-get-key-type branch October 16, 2026 16:51
@github-project-automation github-project-automation Bot moved this from In review to Done in PyPCAPKit Oct 16, 2026
@JarryShaw JarryShaw removed the review: good-to-go Cross-review at the current head says ready; CI state is separate label Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

const Regenerated IANA or vendor constant tables; members keep their numeric values fix Pull requests that fix a defect (fix: subject prefix)

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

fix(const): Command.get calls key.upper() on any key, so bytes mint and ints raise AttributeError

1 participant