-
Notifications
You must be signed in to change notification settings - Fork 4k
GH-49103: [Python] Add internal type system stubs (_types, error, _stubs_typing) #48622
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
rok
wants to merge
37
commits into
apache:main
Choose a base branch
from
rok:pyarrow-stubs-pr2-core-types
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
b4037db
Add GitHub Actions workflow for type checking (mypy, pyright, ty). Ad…
rok c789d3f
Update ci/scripts/python_test_type_annotations.sh
rok 750bd18
Apply suggestion from @raulcd
rok 09a9a63
review feedback
rok 18a1572
include dev/update_stub_docstrings.py
rok 6851321
Use PYARROW_TEST_ANNOTATIONS in windows build, disable wheel docstrin…
rok 4bfb3cd
work on dev/update_stub_docstrings.py
rok bee2f9d
further work on dev/update_stub_docstrings.py
rok 44cab7d
lint
rok 0c2fed5
add click for docstring population
rok ed124bb
Remove dependencies on click and griffe
rok b7a62e1
fix import paths
rok b8cbe92
add PYARROW_TEST_ANNOTATIONS to AMD64 Windows 2022 Python 3.13
rok 9cf8f09
move check to pre-commit
rok f586afe
change pre-commit, add note
rok 26d44bf
change pre-commit script
rok 45196ff
Revert from pre-commit to ci/scripts/python_test_type_annotations.sh
rok cbbe21b
Apply suggestions from code review
rok f0db4e4
apply review suggestion
rok 9de24df
fix shellcheck
rok 1bac491
Try single build
rok 12ff649
lint
rok 9d2fcf0
review feedback
rok 2ca0108
reintroduce pythonVersion = 3.10
rok 0a518b1
revert change
rok c78dafc
post rebase fix
rok 9e00fd7
--no-build-isolation bypasses pyproject.toml's build requirements
rok afc2f46
libcs added
rok e96017f
Added DYLD_LIBRARY_PATH export to python_build.sh
rok 7f174b4
Add GitHub Actions workflow for type checking (mypy, pyright, ty). Ad…
rok 0ab7dc7
Use PYARROW_TEST_ANNOTATIONS in windows build, disable wheel docstrin…
rok 93a93ea
move check to pre-commit
rok 4cfc357
Revert from pre-commit to ci/scripts/python_test_type_annotations.sh
rok 78044ff
add-type-stubs-for-internal-type-system
rok 65da759
fsspec comes without annotations
rok 367953c
verbosity setting
rok 7873930
post rebase
rok File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,7 @@ cython>=3.1 | |
| cloudpickle | ||
| fsspec | ||
| hypothesis | ||
| libcst>=1.8.6 | ||
| numpy>=1.16.6 | ||
| pytest | ||
| pytest-faulthandler | ||
|
|
||
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| #!/usr/bin/env bash | ||
| # | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| set -ex | ||
| pyarrow_dir=${1} | ||
|
|
||
| if [ -n "${ARROW_PYTHON_VENV:-}" ]; then | ||
| # shellcheck source=/dev/null | ||
| . "${ARROW_PYTHON_VENV}/bin/activate" | ||
| fi | ||
|
|
||
| # Install library stubs. Note some libraries contain their own type hints so they need to be installed. | ||
| pip install fsspec pandas-stubs scipy-stubs types-cffi types-psutil types-requests types-python-dateutil | ||
|
|
||
| # Install type checkers | ||
| pip install mypy pyright ty | ||
|
|
||
| # Run type checkers | ||
| pushd "${pyarrow_dir}" | ||
| mypy | ||
| pyright --stats | ||
| ty check --verbose --output-format concise | ||
| popd |
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| """Type stubs for PyArrow. | ||
|
|
||
| This is a placeholder stub file. | ||
| Complete type annotations will be added in subsequent PRs. | ||
| """ | ||
|
|
||
| from typing import Any | ||
|
|
||
| # TODO(GH-48970): remove __getattr__ before release as this | ||
| # will annotate non-existing attributes as Any. | ||
| # https://github.com/apache/arrow/issues/48970 | ||
| def __getattr__(name: str) -> Any: ... |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| import datetime as dt | ||
|
|
||
| from collections.abc import Collection, Iterator, Sequence | ||
| from decimal import Decimal | ||
| from typing import Any, Literal, Protocol, TypeAlias, TypeVar | ||
|
|
||
| import numpy as np | ||
|
|
||
| from numpy.typing import NDArray | ||
|
|
||
| from pyarrow.lib import BooleanArray, IntegerArray, ChunkedArray | ||
|
|
||
| ArrayLike: TypeAlias = Any | ||
| ScalarLike: TypeAlias = Any | ||
| Order: TypeAlias = Literal["ascending", "descending"] | ||
| JoinType: TypeAlias = Literal[ | ||
| "left semi", | ||
| "right semi", | ||
| "left anti", | ||
| "right anti", | ||
| "inner", | ||
| "left outer", | ||
| "right outer", | ||
| "full outer", | ||
| ] | ||
| Compression: TypeAlias = Literal[ | ||
| "gzip", "bz2", "brotli", "lz4", "lz4_frame", "lz4_raw", "zstd", "snappy" | ||
| ] | ||
| NullEncoding: TypeAlias = Literal["mask", "encode"] | ||
| NullSelectionBehavior: TypeAlias = Literal["drop", "emit_null"] | ||
| TimeUnit: TypeAlias = Literal["s", "ms", "us", "ns"] | ||
| Mask: TypeAlias = ( | ||
| Sequence[bool | None] | ||
| | NDArray[np.bool_] | ||
| | BooleanArray | ||
| | ChunkedArray[Any] | ||
| ) | ||
| Indices: TypeAlias = ( | ||
| Sequence[int | None] | ||
| | NDArray[np.integer[Any]] | ||
| | IntegerArray | ||
| | ChunkedArray[Any] | ||
| ) | ||
|
|
||
| PyScalar: TypeAlias = (bool | int | float | Decimal | str | bytes | | ||
| dt.date | dt.datetime | dt.time | dt.timedelta) | ||
|
|
||
| _T = TypeVar("_T") | ||
| _V = TypeVar("_V", covariant=True) | ||
|
|
||
| SingleOrList: TypeAlias = list[_T] | _T | ||
|
|
||
|
|
||
| class SupportEq(Protocol): | ||
| def __eq__(self, other) -> bool: ... | ||
|
|
||
|
|
||
| class SupportLt(Protocol): | ||
| def __lt__(self, other) -> bool: ... | ||
|
|
||
|
|
||
| class SupportGt(Protocol): | ||
| def __gt__(self, other) -> bool: ... | ||
|
|
||
|
|
||
| class SupportLe(Protocol): | ||
| def __le__(self, other) -> bool: ... | ||
|
|
||
|
|
||
| class SupportGe(Protocol): | ||
| def __ge__(self, other) -> bool: ... | ||
|
|
||
|
|
||
| FilterTuple: TypeAlias = ( | ||
| tuple[str, Literal["=", "==", "!="], SupportEq] | ||
| | tuple[str, Literal["<"], SupportLt] | ||
| | tuple[str, Literal[">"], SupportGt] | ||
| | tuple[str, Literal["<="], SupportLe] | ||
| | tuple[str, Literal[">="], SupportGe] | ||
| | tuple[str, Literal["in", "not in"], Collection] | ||
| | tuple[str, str, Any] # Allow general str for operator to avoid type errors | ||
| ) | ||
|
|
||
|
|
||
| class Buffer(Protocol): | ||
| ... | ||
|
|
||
|
|
||
| class SupportPyBuffer(Protocol): | ||
| ... | ||
|
|
||
|
|
||
| class SupportArrowStream(Protocol): | ||
| def __arrow_c_stream__(self, requested_schema=None) -> Any: ... | ||
|
|
||
|
|
||
| class SupportPyArrowArray(Protocol): | ||
| def __arrow_array__(self, type=None) -> Any: ... | ||
|
|
||
|
|
||
| class SupportArrowArray(Protocol): | ||
| def __arrow_c_array__(self, requested_schema=None) -> Any: ... | ||
|
|
||
|
|
||
| class SupportArrowDeviceArray(Protocol): | ||
| def __arrow_c_device_array__(self, requested_schema=None, **kwargs) -> Any: ... | ||
|
|
||
|
|
||
| class SupportArrowSchema(Protocol): | ||
| def __arrow_c_schema__(self) -> Any: ... | ||
|
|
||
|
|
||
| class NullableCollection(Protocol[_V]): # type: ignore[reportInvalidTypeVarUse] | ||
| def __iter__(self) -> Iterator[_V] | Iterator[_V | None]: ... | ||
| def __len__(self) -> int: ... | ||
| def __contains__(self, item: Any, /) -> bool: ... | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't the most exciting suggestion, but it's something that constantly frustrates me 😅
An alternative would just be
Array[Any].Using the concrete subclasses requires the stubs to do a carefully choreographed dance, or the user to
typing.casteverywhere - sadly