Skip to content

Passing bytes to tomllib.loads() gives wrong error message #132655

@dargueta-accompanyhealth

Description

Bug report

Edit: It looks like this was fixed in #124587 but either regressed or that hasn't been released yet? It was merged October 2024.

Bug description:

If you call tomllib.loads() and mistakenly pass in a bytes object instead of a string...

tomllib.loads(b'a="asdf"')

...you get a TypeError as expected, but the error message is wrong:

TypeError: a bytes-like object is required, not 'str'

The error message should be the reverse, something like "a string-like object is required, not 'bytes'".

The bug is present on macOS with the following versions:

  • 3.13.3
  • 3.12.10
  • 3.11.12

CPython versions tested on:

3.13, 3.12, 3.11

Operating systems tested on:

macOS

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions