Skip to content

[parsimonious] ParseError.line() can return None - #16868

Open
ArthDubey1011 wants to merge 1 commit into
python:mainfrom
ArthDubey1011:none-parsimonious
Open

ArthDubey1011 wants to merge 1 commit into
python:mainfrom
ArthDubey1011:none-parsimonious

Conversation

@ArthDubey1011

@ArthDubey1011 ArthDubey1011 commented Nov 19, 2026 •

Copy link
Copy Markdown

ParseError.line() returns None when the error comes from a TokenGrammar, because the text is then a list of tokens (source):

def line(self):

    if isinstance(self.text, list):  # TokenGrammar

        return None

    else:

        return self.text.count('\n', 0, self.pos) + 1

Checked with parsimonious 0.11.0:

>>> from parsimonious.grammar import TokenGrammar

>>> from parsimonious.utils import Token

>>> try:

...     TokenGrammar('foo = "token1" "token2"').parse([Token("token1"), Token("bogus")])

... except Exception as e:

...     print(e.line())

None

column() always returns an int, so it is unchanged.

AI assistance: Claude Code (Claude Opus 5.5) found this by comparing the stubs with the runtime source, ran the check above and made the edit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

This branch has not been deployed

No deployments
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.

1 participant