Skip to content

Avoid raising plain exception#728

Merged
Tinche merged 4 commits intopython-attrs:mainfrom
EpicWink:literal-exception
Mar 12, 2026
Merged

Avoid raising plain exception#728
Tinche merged 4 commits intopython-attrs:mainfrom
EpicWink:literal-exception

Conversation

@EpicWink
Copy link
Contributor

Raise a new CattrsError instead of built-in Exception, and make all other exceptions inherit from this.

This makes it more reliable to catch validation issues due to invalid literal or date-time values when structuring (instead of having to parse the exception message when catching Exception).

@codspeed-hq
Copy link

codspeed-hq bot commented Feb 26, 2026

Merging this PR will not alter performance

✅ 54 untouched benchmarks


Comparing EpicWink:literal-exception (7433724) with main (304e370)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (21b1954) during the generation of this report, so 304e370 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@Tinche
Copy link
Member

Tinche commented Feb 26, 2026

I'm good with this; I was somewhat lazy in the past about it. Backwards compatibility should be fine, right?

@EpicWink
Copy link
Contributor Author

Backwards compatibility should be fine, right?

@Tinche yes. Only possible breakages would be from some inane strict equality checks on Exception

@Tinche Tinche requested review from Tinche and hynek March 1, 2026 10:11
@EpicWink EpicWink changed the title Avoid raising plan exception Avoid raising plain exception Mar 1, 2026
@Tinche
Copy link
Member

Tinche commented Mar 12, 2026

Thanks!

@Tinche Tinche merged commit a829300 into python-attrs:main Mar 12, 2026
14 checks passed
@EpicWink EpicWink deleted the literal-exception branch March 13, 2026 02:01
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.

3 participants