Skip to content

Fix AssertionError when completing after dot followed by newline#2090

Closed
worksbyfriday wants to merge 1 commit intodavidhalter:masterfrom
worksbyfriday:fix-newline-after-dot-completion
Closed

Fix AssertionError when completing after dot followed by newline#2090
worksbyfriday wants to merge 1 commit intodavidhalter:masterfrom
worksbyfriday:fix-newline-after-dot-completion

Conversation

@worksbyfriday
Copy link
Copy Markdown

Summary

Completing object. \n at position (1, 8) crashes with AssertionError: unhandled operator '.' in ....

from jedi.api import Interpreter
Interpreter("object. \n", []).complete(1, 8)  # AssertionError

Root cause

In Completion._complete_python, the code gets the leaf at the cursor position. When there's a space + newline after the dot, the leaf is a newline node, not the dot. The code handles endmarker as a special case but not newline, so the newline leaf falls through and the dot operator itself gets passed to _complete_trailer_infer_node, which raises AssertionError on non-ellipsis operators.

Fix

Added "newline" to the type check alongside "endmarker" on line 293 of completion.py:

if dot.type in ("endmarker", "newline"):

Test plan

  • Added test_whitespace_and_newline_after_dot regression test
  • All 143 existing completion tests pass
  • Manually verified with Interpreter, Script, and various whitespace patterns

Fixes #1954

🤖 Generated with Claude Code

When completing `object. \n` at position (1, 8), jedi gets the leaf
at the cursor position, which is a newline node. The code only
checked for `endmarker` as a special case where the leaf isn't the
dot, but newline nodes need the same treatment.

Without this fix, the newline leaf gets passed through to
`_complete_trailer`, which eventually calls `_infer_node` on the
dot operator, triggering an AssertionError ("unhandled operator '.'").

The fix adds `newline` to the type check alongside `endmarker`.

Fixes davidhalter#1954

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@davidhalter
Copy link
Copy Markdown
Owner

Hi, I'm sorry to say this, but I decided to not work at all with AI generated pull requests/content. There are multiple reasons for this:

  1. I feel like at this point it's pretty subpar to what a good engineer can create. I have received many AI generated pull requests and they all have massive problems compared to what I received from actual people. People sometimes can't fix the problems they have without AI, but I regard this as a feature: If you don't understand the problem, I don't have to review your code.
  2. I love people. And I would like to interact with all of you; learn from you; teach you. But if you are simply a bridge to an LLM, I'm just wasting my time. I cannot build any form of relationship.
  3. LLMs are the antithesis to what I like about programming. I like the struggle of programming. Of writing code. I love how things come together after a good coding session. This is all missing. And while some form of AI might make that skill useless in the future, it's not useless now and I would really recommend anyone to avoid LLMs for generating complex code.
  4. Even for written English I generally prefer non-LLM text, because it shows something about the person. I understand that some people are incredibly non-fluent, but that's fine. Just do your best and try to learn English. Otherwise we won't have the ability to talk if we ever meet, which would be a pitty.
  5. LLMs are extremely good at generating code/text that looks reasonable. I use them a lot for brainstorming, they are incredible at putting out ideas. They are bad at facts. They are extremely bad at thinking. The positive thing here is that you have a brain and you can use it to think. Think hard first.

Thank you anyway for trying to contribute to Open Source. I would really appreciate if you avoid the usage of LLMs in my projects. It is obviously fine to use LLMs as a search/brainstorming tool with my projects, just don't use it to interact with me.

PS: As a side note I want to mention that I'm probably not the only maintainer that is annoyed by LLM content. So you probably should not use LLMs for other repositories either. My initial emotions towards LLM content was way more negative than this message is and I assume other maintainers frequently have very negative feelings as well.

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.

AssertionError completing a trailer with a space after dot

2 participants