Skip to content

Raise KeyError for missing keys in values() - #41

Open
Zhuyuyangyy wants to merge 1 commit into
gruns:masterfrom
Zhuyuyangyy:fix/values-missing-key
Open

Zhuyuyangyy wants to merge 1 commit into
gruns:masterfrom
Zhuyuyangyy:fix/values-missing-key

Conversation

@Zhuyuyangyy

Copy link
Copy Markdown

Change

values(key) is documented to raise KeyError when an explicitly supplied key is missing. Currently it falls through to the no-argument path and returns values for unrelated keys instead:

omdict([('present', 'value')]).values('missing')
# before: ['value']; documented behavior: KeyError('missing')

Keep the existing no-argument and present-key paths, and raise KeyError(key) for the missing-key case. The regression covers empty/non-empty dictionaries, repeated values for an existing key, and valid None/False keys. No other methods, dependencies or versions change.

Local validation

  • Original baseline: 55 unittest tests pass; the new missing-key regression fails before the implementation change.
  • Full unittest suite: 56 tests pass on each of CPython 3.8.20, 3.9.25, 3.10.21, 3.12.3 and 3.13.15.
  • The configured nose runner (python -m nose --exe): 56 tests pass on each of CPython 3.8.20 and 3.9.25.
  • Local Coverage.py statement coverage: 95% on Python 3.12.
  • git diff --check passes.

Quality-check caveat: modern Flake8 7.5.0 reports five existing F401 imports on unchanged line 25; mypy 2.4.1 (with six stubs) reports an existing object.value error on line 396. Both outputs are byte-for-byte identical on the original HEAD and this patch. I have not bundled unrelated cleanup into this fix. The full tox interpreter matrix and upstream CI have not been run locally.

AI assistance was used for the investigation, implementation and tests; the final diff and local results were checked before submission.

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.

1 participant