GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Raise `TypeError` in pure Python `hmac.digest` for non-bytes keys · Issue #155426 · python/cpython

Raise TypeError in pure Python hmac.digest for non-bytes keys #155426

New issue
Copy link
New issue
Copy link
Closed
Closed
Raise TypeError in pure Python hmac.digest for non-bytes keys#155426
Copy link
Assignees
picnixz
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@picnixz
picnixz
opened on Aug 9, 2026
Issue body actions

Bug report

Bug description:

hmac.digest() reaches key.ljust() with a key type its own class rejects by name, so hmac.digest(memoryview(key), msg, "md5") raises AttributeError instead of TypeError as hmac.HMAC does. I'm aligning the exceptions here but I may consider accepting other types later.

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Linked PRs

  • gh-155426: correctly reject non-bytes keys in hmac.digest #155427
  • [3.15] gh-155426: correctly reject non-bytes keys in hmac.digest (GH-155427) #159743
  • [3.14] gh-155426: correctly reject non-bytes keys in hmac.digest (GH-155427) #159744

Activity

  1. picnixz
    self-assigned this
    on Aug 9, 2026
  2. picnixz
    added a parent issue on Aug 9, 2026
    • Meta-issue for bugs in Lib/hmac.py and Lib/hashlib.py #155413
  3. picnixz
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    on Aug 9, 2026
  4. picnixz
    added 3 commits that reference this issue on Aug 9, 2026

    pythongh-155426: correctly accept bytes-like keys in `hmac.digest`

    38dffc4

    pythongh-155426: correctly accept bytes-like keys in `hmac.digest`

    fe28b30

    pythongh-155426: correctly accept bytes-like keys in `hmac.digest`

    0c1bf69
  5. picnixz
    changed the title [-]Pure-Python fallback of `hmac.digest` only accept `bytes` objects as keys[/-] [+]Raise `TypeError` in pure Python `hmac.digest` for non-bytes keys[/+] on Aug 9, 2026
  6. picnixz
    added 3 commits that reference this issue on Oct 19, 2026

    gh-155426: correctly reject non-bytes keys in `hmac.digest` (#155427)

    197d332

    [3.15] gh-155426: correctly reject non-bytes keys in `hmac.digest` (G…

    e0685b7

    [3.14] gh-155426: correctly reject non-bytes keys in `hmac.digest` (G…

    cf0658d
  7. hugovk
    closed this as completedon Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @picnixz
    picnixz

Labels

stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.