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 — Add attributes to tomllib.TOMLDecodeError · Issue #126175 · python/cpython

Add attributes to tomllib.TOMLDecodeError #126175

New issue
Copy link
New issue
Copy link
Closed
Closed
Add attributes to tomllib.TOMLDecodeError#126175
Copy link
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement

Description

@hukkin
hukkin
opened on Oct 30, 2024
Issue body actions

Feature or enhancement

Proposal:

Add the same attributes to tomllib.TOMLDecodeError that json.JSONDecodeError also has, namely: msg, doc, pos, lineno, colno. This will help user facing apps show customized errors to users.

This draft PR in Tomli shows the proposed changes.

Has this already been discussed elsewhere?

I have already discussed this feature proposal on Discourse

Links to previous discussion of this feature:

https://discuss.python.org/t/69546

Linked PRs

  • gh-126175: Add attributes to TOMLDecodeError. Deprecate free-form __init__ args #126428

Activity

  1. hukkin
    added
    type-featureA feature request or enhancementA feature request or enhancement
    on Oct 30, 2024
  2. hukkin commented on Oct 30, 2024

    @hukkin
    hukkin
    on Oct 30, 2024
    ContributorAuthor
    More actions

    Pinging codeowners @hauntsaninja and @encukou

    Thoughts on my concern in Discourse about the change breaking TOMLDecodeError init with no arguments would be much appreciated:

    Unfortunately, this changes signature of TOMLDecodeError so breaks any users instantiating the error. Not sure why anyone would do that though? Some less breaking options are using keyword arguments, or dynamically injecting attributes after instantiation.

  3. nineteendo commented on Oct 30, 2024

    @nineteendo
    nineteendo
    on Oct 30, 2024
    Contributor
    More actions

    I would use keywords arguments defaulting to None. Also see PEP-387.

    Reacted by Petr Viktorin, Taneli Hukkinen and Bénédikt Tran
  4. picnixz
    added
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    on Oct 30, 2024
  5. picnixz commented on Oct 30, 2024

    @picnixz
    picnixz
    on Oct 30, 2024
    Member
    More actions

    Unfortunately, this changes signature of TOMLDecodeError so breaks any users instantiating the error. Not sure why anyone would do that though? Some less breaking options are using keyword arguments, or dynamically injecting attributes after instantiation.

    You can instantiate those errors if you create a custom tomllib extension (e.g., to handle extended syntax not supported by TOML but you still want to use the same exceptions for that).

    I would use keywords arguments defaulting to None

    Agreed.

  6. hukkin commented on Oct 30, 2024

    @hukkin
    hukkin
    on Oct 30, 2024
    ContributorAuthor
    More actions

    Thanks all for the feedback! I've updated my PoC draft PR in Tomli to be fully backwards compatible. It also adds a deprecation warning for use of positional arguments, which is simple to remove if folks think it's unnecessary. With it I think we could eventually move to the same exact signature that json.JSONDecodeError has.

  7. encukou
    added a commit that references this issue on Nov 13, 2024

    gh-126175: Add attributes to TOMLDecodeError. Deprecate free-form `__…

    29b5323
  8. encukou
    closed this as completedon Nov 13, 2024
  9. picnixz
    added a commit that references this issue on Dec 8, 2024

    pythongh-126175: Add attributes to TOMLDecodeError. Deprecate free-fo…

    ae19768
  10. ebonnal
    added a commit that references this issue on Jan 12, 2025

    pythongh-126175: Add attributes to TOMLDecodeError. Deprecate free-fo…

    3b3fc2f
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/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402520 — 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.