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 — fix rope autoimport completion by igmacs · Pull Request #724 · python-lsp/python-lsp-server

Conversation

@igmacs

@igmacs igmacs commented Aug 21, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

This PR fixes #721, see issue for more details on the error that was occurring, its root cause, and the proposed fixes.

pylsp completion works in two steps: first a list of autocompletion suggestions is collected when the user requests it, and then the selected autocompletion candidate is further processed. This is implemented with hooks which multiple completion providers can implement, by default jedi, rope, or rope_autoimport. The hook for the first step is pylsp_completions, which should return a list, and the results for each provider which implements it are aggregated. The hook for the second step is pylsp_completion_item_resolve, which is called for each provider in an as far as I know undefined order until one of them returns not None. That hook might add additional information to the completion candidate, or it could leave it as it was.

One problem is that the jedi and rope providers do add additional information when they were the ones which suggested the candidate, but return the candidate as it was when they weren't, instead of returning None so other providers can have the chance to process it. This PR fixes that, ensuring that pylsp_completion_item_resolve is always processed by the same handler which provided the autocompletion suggestion. This was not strictly necessary to fix the original issue, but it's a clear improvement in consistency in the code I needed to touch to fix it, so that's what I decided to do. The original issue was just a KeyError in a dictionary access with no guard in the pylsp_completion_item_resolve implementation of both rope and jedi providers.

This change doesn't have any consequence with the built-in providers, as before there was only one active at a given time. With plugins, it enables other completion providers to be able to post-process their candidates properly. But by Hyrum's law, there might be a plugin which relies on the default providers handling the pylsp_completion_item_resolve step (rope_autoimport handler did, after all). So just in case I added a catch-all clause in the hook caller, and then I didn't need to implement it for rope_autoimport either.

Finally, both the previous and current implemention rely on the completion labels being unique, which might not be the case. But I think it's not a problem to keep that assumption for now, and fix it at a later point if it ever comes to be a problem.

Let me know what you think

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@igmacs
igmacs force-pushed the develop branch 2 times, most recently from 2aeb3aa to 8e97504 Compare August 28, 2026 10:23
@igmacs
fix rope autoimport completion
044c538
@igmacs
igmacs force-pushed the develop branch from 8e97504 to 044c538 Compare August 28, 2026 10:31
@igmacs
igmacs marked this pull request as ready for review August 28, 2026 10:32
@igmacs igmacs mentioned this pull request Sep 4, 2026
pylsp_completion_item_resolve crashes sometimes on rope auto-import completion #721
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

pylsp_completion_item_resolve crashes sometimes on rope auto-import completion

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@igmacs
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.
You are visitor 01402503 — 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.