mirror of
https://github.com/lancedb/lancedb.git
synced 2026-08-18 12:08:35 +00:00
fix(python): expose inline types to downstream checkers (#3817)
## Summary - publish the PEP 561 `py.typed` marker so downstream type checkers consume the inline public annotations - add a Pyright contract test that distinguishes synchronous `connect` from awaited `connect_async` - verify the marker is present in the installed package ## Root cause The public Python module already annotated `lancedb.connect` as synchronous and `lancedb.connect_async` as asynchronous. The private native `_lancedb.connect` stub is intentionally awaitable because it backs `connect_async`. However, the distribution did not include a PEP 561 marker, so downstream tools such as mypy could ignore the public inline annotations and expose misleading or incomplete type information. ## Validation - `python/.venv/bin/ruff format --check python/python/tests/test_db.py python/python/type_tests/connect.py` - `python/.venv/bin/ruff check .` - `cd python && .venv/bin/pytest python/tests/test_db.py::test_package_includes_pep_561_marker -q` - `cd python && .venv/bin/pyright --pythonpath .venv/bin/python` - downstream mypy contract check for both public connection functions Fixes #2159 <!-- lance-gatekeeper-fix:v1 agent=b07901451487187fc03f61890d3aa6bb generation=1 --> Co-authored-by: lancedb-gatefixer[bot] <313497061+lancedb-gatefixer[bot]@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
fc44535cee
commit
ec80acb668
@@ -0,0 +1 @@
|
||||
|
||||
@@ -6,6 +6,7 @@ import inspect
|
||||
import re
|
||||
import sys
|
||||
from datetime import timedelta
|
||||
from importlib import resources
|
||||
import os
|
||||
from types import SimpleNamespace
|
||||
|
||||
@@ -18,6 +19,10 @@ from lance_namespace.errors import NamespaceNotEmptyError, TableNotFoundError
|
||||
from lancedb.pydantic import LanceModel, Vector
|
||||
|
||||
|
||||
def test_package_includes_pep_561_marker():
|
||||
assert resources.files(lancedb).joinpath("py.typed").is_file()
|
||||
|
||||
|
||||
def test_basic(tmp_path):
|
||||
db = lancedb.connect(tmp_path)
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright The LanceDB Authors
|
||||
|
||||
from typing import assert_type
|
||||
|
||||
import lancedb
|
||||
from lancedb import AsyncConnection, DBConnection
|
||||
|
||||
|
||||
def check_connect_type() -> None:
|
||||
assert_type(lancedb.connect("memory://"), DBConnection)
|
||||
|
||||
|
||||
async def check_connect_async_type() -> None:
|
||||
assert_type(await lancedb.connect_async("memory://"), AsyncConnection)
|
||||
Reference in New Issue
Block a user