Skip to content

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

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

Activity

  1. StanFromIreland commented on Apr 17, 2025

    @StanFromIreland
    Member

    This should be closed, the problem is an update was not backported (it only works on 3.14) as it is a semi-bug/feature, if we want to backport it discussion should be moved to the original issue #124835.

    Backporting would only go as far as 3.13, there is nothing to do for other versions.

  2. added
    stdlibStandard Library Python modules in the Lib/ directory
    on Apr 17, 2025
  3. StanFromIreland commented on Apr 17, 2025

    @StanFromIreland
    Member

    @picnixz Any thoughts -- should it be backported?

  4. hauntsaninja commented on Apr 17, 2025

    @hauntsaninja
    Contributor

    I'd intentionally chosen not to backport as per #124835 (comment)

  5. StanFromIreland commented on Apr 17, 2025

    @StanFromIreland
    Member

    This can be closed then :-)

  6. hauntsaninja commented on Apr 17, 2025

    @hauntsaninja
    Contributor

    Thank you for reporting this!!

  7. dargueta-accompanyhealth commented on Apr 17, 2025

    @dargueta-accompanyhealth
    Author

    Got it, makes sense. Thanks for the quick response as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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