Repository navigation
Give each parse problem a code - #160
Merged
Merged
Conversation
rr-
force-pushed
the
rework/25-problem-codes
branch
from
November 6, 2026 16:40
de3e9c0 to
97e9851
Compare
parse_from_object() raised TypeError for a built-in class or module, which inspect.getsource() has no source for, and for an object whose __doc__ is not a string, such as a descriptor. Both now parse: the first without attribute docstrings, the second as no docstring.
A Problem now has a code, a short name such as missing-colon, which says what is wrong and stays the same between versions while the message may change. The Problem class documents every code. A test mutates every case input in every style and checks that try_parse() only reports problems with a documented code and a line in the docstring, and that parse() raises nothing but ParseError.
try_parse() never raises for a docstring's text. An exception from a user's parse_item hook is the hook's own and propagates, so say so instead of promising it never raises at all.
Python 3.13 dedents docstrings when compiling them, so the codes in Problem's docstring lost the indent the test looked for. Dedent the docstring first, as every version then agrees.
rr-
force-pushed
the
rework/25-problem-codes
branch
from
November 6, 2026 16:41
97e9851 to
4d026e6
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Each
Problemfromtry_parse()now has acode, a short name that says what is wrong. Tools built on top, such as a linter, can match on it or let users silence one by name. Messages may change between versions. Codes don't.The codes, documented on the
Problemclass:bad-field:param xwith no closing colonwrong-arguments:param a b c d:mixed-returns-and-yields@returnand@yieldmissing-colonmissing-nameno-itemsParseErroris unchanged. The code of what it reports is onerror.problems[0].code.This also checks that parsing fails only with problems or a
ParseError. A new test mutates every case input in every style and fails on any other exception, on a code the docs don't list, or on a line outside the docstring. Fuzzing turned up no crashes in the parsers themselves: about 190k stdlib, generated and whitespace-variant docstrings plus 180k mutated ones. It did find two inparse_from_object(), fixed in their own commit:parse_from_object(int)andparse_from_object(sys)raisedTypeError, because built-ins have no source to read attribute docstrings from. They now parse without them.__doc__is not a string, such ascollections._tuplegetter, whose__doc__is a descriptor, raisedTypeErrorfrom inside the parser. It now parses as having no docstring.Exceptions raised by a user's
parse_itemhook still propagate from bothparse()andtry_parse(). That's the user's code, not docstring text.Parity against main: 0 of 29,074 docstrings differ. Codes aren't part of what the tool compares, and no message changed. Bench on 3.8: every workload is 0.98–1.03x of main.