Repository navigation
Add structure hook for optional notebook filter union - #466
Open
Shubham Padkonde (Shubham-Padkonde) wants to merge 1 commit into
Open
Shubham Padkonde (Shubham-Padkonde) wants to merge 1 commit into
Shubham Padkonde (Shubham-Padkonde) wants to merge 1 commit into
Conversation
NotebookDocumentFilterWithCells.notebook is declared as Optional[Union[str, NotebookDocumentFilter]], but only the non-optional union had a structure hook. Recent cattrs releases (26.x) build a structurer for every field type up front, so structuring any notebookSelector entry, including the cells-only form, fails with StructureHandlerNotFoundError. Register a hook for the optional union that passes None through and delegates to the existing notebook filter hook. Fixes microsoft#462 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
Fixes #462
Fixes #430
NotebookDocumentFilterWithCells.notebookis typedOptional[Union[str, NotebookDocumentFilter]]._hooks.pyregisters_notebook_filter_hookonly for the non-optional union (NotebookCellTextDocumentFilter.notebook), so the optional form has no structure hook.This happens to work with the pinned cattrs 24.1.3. With cattrs 26.x, structuring any
notebookSelectorentry fails withStructureHandlerNotFoundError, even the cells-only form wherenotebookis absent. That's the formty serversends in the issue. The repo's owntest_notebook_sync_optionsfails as well once cattrs is upgraded.This registers a hook for the optional union (taken from
attrs.fields(NotebookDocumentFilterWithCells).notebook.type, likeNotebookSelectorItem). It returnsNoneforNoneand otherwise defers to_notebook_filter_hook.Tests
New tests in
tests/python/test_cattrs_special_cases.py:InitializeResponsefrom the issue (cells-only selector), checking thatnotebookisNone;notebook+cellsselector round-trip for each variant: plain string,notebookType,schemeandpattern.Results for
pytest tests/python:test_notebook_sync_optionsand the newInitializeResponsetestruff format --checkis clean on both files, andmypy --strictonpackages/python/lsprotocolreports no issues.This change was written with help from an AI coding assistant (Claude Code). I reviewed and tested it as described above.
🤖 Generated with Claude Code