Skip to content

chore: require pylance 12 and drop dead compatibility code - #5301

Closed
jonasdedden wants to merge 1 commit into
lance-format:mainfrom
jonasdedden:chore/pylance-12-typing-cleanup
Closed

jonasdedden wants to merge 1 commit into
lance-format:mainfrom
jonasdedden:chore/pylance-12-typing-cleanup

Conversation

@jonasdedden

Copy link
Copy Markdown
Contributor

Summary

Raises the minimum pylance version to 12.0.0, then removes the typing workarounds and version-compatibility code that the new minimum makes unnecessary.

This overlaps with #5295, which makes the same bump. This PR also includes that PR's typing fixes and the legacy-blob test fix, so whichever lands second will need a small rebase.

Typing cleanups enabled by pylance 12

  • Removed type: ignores that pylance 12's annotations make unused:
    • LanceSchema.field() in field_path.py
    • max_rows_per_group and the write_fragments return type in fragment.py; mypy now picks the correct overload because return_transaction=False is passed explicitly
    • create_index_uncommitted(index_type=...) in index.py
  • Removed the redundant FixedSizeListArray cast on the train_pq_model result.
  • Index.fragment_ids is now annotated as Bitmap, so we pass Bitmap(...) instead of a set.
  • CompactionOptions is now TypedDict(total=False):
    • compact_files passes compaction_options or {} without a cast.
    • The tests build options with CompactionOptions(...) instead of a cast helper.
  • Removed the redundant is not None / isinstance(..., LanceDataset) asserts on lr.optimize_indices, which is already typed -> lance.LanceDataset.

Removed dead compatibility code

Every removed shim targeted an API that already exists in pylance 10.0.0b7, the previous minimum. I checked each one against an installed 10.0.0b7.

  • utils.py: the pylance 4.x namespace / storage_options_provider path, including _pylance_version and _create_storage_options_provider. LanceNamespaceStorageOptionsProvider doesn't exist in any supported release. get_write_fragments_kwargs was just an alias for get_namespace_kwargs, so it's gone too.
  • fragment.py: signature probing of write_fragments and the "installed pylance does not support ..." errors. The write options are now passed directly. prepare_fragment_write_options keeps its real validation: target_bases and target_all_bases are mutually exclusive, and it still warns when allow_external_blob_outside_bases is combined with ingest.
  • index.py:
    • the pylance >= 0.36.0 version checks, including _check_pylance_version
    • merge_index_metadata_compat, whose one-argument fallback is never used
    • the hasattr(dataset, "optimize") / optimize_indices guards
  • search.py: the index_segments signature probing, plus the initial_storage_options and fragment_id fallbacks.
  • datasource.py: the initial_storage_options and serialized_manifest fallbacks.
  • Tests:
    • Deleted tests/_utils.py, which only held the write-option probing helpers, and the skipifs that used them.
    • Removed the "unsupported by the installed pylance" tests and the always-skipped optimize_indices test.
    • Removed the 0.36/0.37 version gates and the "not yet implemented" / packed-struct skip branches.
    • Removed the import fallbacks for DatasetBasePath / blob_array / blob_field.

_declare_table_with_fallback in datasink.py stays. It covers namespace implementations that don't implement declare_table, not older pylance versions.

Behavior change in pylance 12

Pylance 12's default file format rejects legacy lance-encoding:blob columns, so the tests in tests/test_blob.py now pin data_storage_version="2.1".

Testing

  • uv run mypy (strict): no issues in 33 source files.
  • uv run ruff check / ruff format --check: clean.
  • uv run pytest -n 8: 297 passed, 0 skipped, with pylance==12.0.0 on Python 3.13.

Bump the minimum pylance to 12.0.0 and resolve the typing workarounds its
annotations make obsolete: unused `type: ignore`s in field_path, fragment
and index, the redundant PQ codebook cast, and the `CompactionOptions`
casts (the TypedDict is now `total=False`). `Index.fragment_ids` is now
annotated as `Bitmap`, so build one explicitly.

Remove compatibility shims for pylance versions below the minimum:
the pylance 4.x namespace/storage-options-provider path, the 0.36 version
checks, signature probing of `write_fragments` and `scanner`, fallbacks
for `initial_storage_options`, `fragment_id`, `serialized_manifest` and the
single-argument `merge_index_metadata`, and the `optimize` API guards.
Drop the tests and skips that only exercised those paths, plus redundant
asserts on `optimize_indices`' already-typed return value.

Pylance 12 defaults to a file format that rejects legacy blob columns, so
the legacy blob tests now pin `data_storage_version="2.1"`.
@github-actions github-actions Bot added the chore label Sep 23, 2026
@jonasdedden

jonasdedden commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor Author

@ddupg Mentioning it here once again for explicitness: Let's definitely merge #5295 first, but this PR works on much deeper simplifications and removals of dead code.

@jonasdedden

Copy link
Copy Markdown
Contributor Author

Converting to Draft for now until #5295 is merged. Probably will split the PR into smaller parts then anyways.

@jonasdedden

Copy link
Copy Markdown
Contributor Author

jiaoew1991 pushed a commit that referenced this pull request Nov 9, 2026
## Summary

Part 3/3 of splitting up #5301. pylance 12 declares `CompactionOptions`
as `TypedDict(total=False)`. An empty dict and partial
`CompactionOptions(...)` literals now type-check, so the cast in
`compact_files` and the test-only `_compaction_options` cast helper are
no longer needed.

No behavior change. `pyproject.toml` and `uv.lock` are untouched.

## Testing
- `uv run mypy` (strict), `ruff check`, `ruff format --check`: clean
- `pytest tests/test_distributed_compaction.py`: 14 passed
- Full suite with all three split PRs combined: 299 passed, 0 skipped
(pylance 12.0.0, Python 3.12)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant