Skip to content

fix: refine type annotation#3278

Merged
wjones127 merged 9 commits into
lance-format:mainfrom
chenkovsky:feature/pyi
Dec 23, 2024
Merged

fix: refine type annotation#3278
wjones127 merged 9 commits into
lance-format:mainfrom
chenkovsky:feature/pyi

Conversation

@chenkovsky

Copy link
Copy Markdown
Contributor

No description provided.

@github-actions github-actions Bot added bug Something isn't working A-python Python bindings labels Dec 20, 2024
yield LanceFragment(dataset, int(f))
elif isinstance(f, FragmentMetadata):
yield LanceFragment(dataset, f.fragment_id)
yield LanceFragment(dataset, f.id)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed fragment_id to id. because fragment metadata only has attribute id

@chenkovsky

Copy link
Copy Markdown
Contributor Author

maybe nextstep we can use pyright to guarantee python code quality

@westonpace westonpace left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is quite thorough. Did you use a tool of any kind to make it?

Overall I think these changes are good but might check @wjones127 for a second opinion.

Comment thread python/python/lance/__init__.py Outdated
Comment on lines 82 to 84
If specified, use the provided commit handler to lock the table while
committing a new version. Not necessary on object stores other than S3
or when there are no concurrent writers.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
If specified, use the provided commit handler to lock the table while
committing a new version. Not necessary on object stores other than S3
or when there are no concurrent writers.
A custom commit lock. Only needed if your object store does not support
atomic commits. See the user guide for more details.

Comment thread python/python/lance/dataset.py Outdated
Comment on lines +2493 to +2531
class Tag(TypedDict):
version: int
manifest_size: int


class Version(TypedDict):
version: int
timestamp: int | datetime
metadata: Dict[str, str]


class UpdateResult(TypedDict):
num_rows_updated: int


class AlterColumn(TypedDict):
path: str
name: Optional[str]
nullable: Optional[bool]
data_type: Optional[pa.DataType]


class ExecuteResult(TypedDict):
num_inserted_rows: int
num_updated_rows: int
num_deleted_rows: int


class Index(TypedDict):
name: str
type: str
uuid: str
fields: List[str]
version: int
fragment_ids: Set[int]


class OperationDict(TypedDict):
fragments: List[_FragmentMetadata]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be nice to document these properties but I think most of them should be obvious and that can always be done in a future PR.

Comment thread python/python/lance/lance/__init__.pyi Outdated
Comment on lines +400 to +405
def __lt__(self, other: BFloat16) -> bool: ...
def __le__(self, other: BFloat16) -> bool: ...
def __eq__(self, other: object) -> bool: ...
def __ne__(self, other: object) -> bool: ...
def __gt__(self, other: BFloat16) -> bool: ...
def __ge__(self, other: BFloat16) -> bool: ...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These methods seem out of place for _DataFile.

Comment thread python/python/lance/lance/__init__.pyi Outdated
): ...
def _json_to_schema(schema_json: str) -> pa.Schema: ...
def _schema_to_json(schema: pa.Schema) -> str: ...
def trace_to_chrome(file: Optional[str] = None, level: Optional[str] = None): ...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be in the tracing package?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you mean it should be organized like optimize.pyi, debug.pyi? But I get atttribute access issue, when I use pyright to check these files. putting all definition in init.pyi can solve this issue, because actually there's only one dynlib.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reorg the file path, now pyright doesn't complain error

Comment on lines +2504 to +2518
class UpdateResult(TypedDict):
num_rows_updated: int


class AlterColumn(TypedDict):
path: str
name: Optional[str]
nullable: Optional[bool]
data_type: Optional[pa.DataType]


class ExecuteResult(TypedDict):
num_inserted_rows: int
num_updated_rows: int
num_deleted_rows: int

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of these (e.g. UpdateResult and ExecuteResult) we had as a typed dict because we thought it might be likely we would add properties in the future and wanted to avoid this being a breaking change.

I wonder if this still holds if we have types declared. I guess, if this makes it a breaking change then it was technically always a breaking change so maybe it isn't a big deal 😆

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why will it be a break change? in the runtime, typeddict is just dict.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I guess I'm not really sure why we used typed dict then 😕. Either way, I'm happy with the change.

@wjones127 wjones127 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. This addresses quite a few issues I wanted fix.

Though I think it might be moot long term if we don't test any of this in CI. So I've created #3285 which outlines a plan to start type checking in CI.

@wjones127
wjones127 merged commit c40164b into lance-format:main Dec 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-python Python bindings bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants