GH-49103: [Python][Annotations] Add internal type system stubs (_types, error, _stubs_typing) - #48622
GH-49103: [Python][Annotations] Add internal type system stubs (_types, error, _stubs_typing)#48622rok wants to merge 21 commits into
Conversation
d3c5740 to
27d1c65
Compare
|
I've rebased this on the annotation infra check PR (#48618) to make sure we're on the right track. |
3f9ed3b to
0ac95b0
Compare
|
|
7873930 to
43e7cc6
Compare
51a7a4e to
7bc0a98
Compare
0d15871 to
8f3796d
Compare
8f3796d to
72571d2
Compare
Co-authored-by: Dan Redding <125183946+dangotbanned@users.noreply.github.com>
Co-authored-by: Dan Redding <125183946+dangotbanned@users.noreply.github.com>
Co-authored-by: Dan Redding <125183946+dangotbanned@users.noreply.github.com>
99f5809 to
8982d1e
Compare
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
Finally took some time to work on this again. @dangotbanned I accepted you proposals and added some other changes. Could you please take another look and maybe we can merge? |
paddyroddy
left a comment
There was a problem hiding this comment.
Had a scan thought. A lot of the stubs went over my head as I don't know the code base well enough, and hard to see them without the context of the function there too. Have some thoughts anyway.
Nice to see this coming along!
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| """Type stubs for PyArrow. |
| @@ -136,11 +136,22 @@ repos: | |||
| - id: flake8 | |||
There was a problem hiding this comment.
Out of scope, but would suggest we move to ruff at some point. Faster, more frequent updates, and nicer maintainer.
| # handle fsspec-compatible filesystems | ||
| try: | ||
| import fsspec | ||
| import fsspec # type: ignore[import-not-found,import-untyped] |
There was a problem hiding this comment.
Looks like #48618 introduced mypy, pyright, and ty. What about https://github.com/facebook/pyrefly?
There was a problem hiding this comment.
I haven't checked, do type: ignore statement codes work across these different type checkers. I've recently switched from mypy to ty and noticed some codes were different. But I have been using ty: ignore rather than type: ignore statements, which might explain things.
| IntoArray = TypeAliasType( | ||
| "IntoArray", |
There was a problem hiding this comment.
Is this "int to array" or "into array"?
| from typing import Any, Generic, Literal, Protocol, TypeAlias, overload | ||
|
|
||
| import numpy as np | ||
| import pandas as pd # type: ignore[import-not-found,import-untyped] # pyright: ignore[reportMissingImports,reportMissingTypeStubs] # noqa: E501 |
There was a problem hiding this comment.
Ah, so this is what I asked about elsewhere. So we're having to do different ignores per library? I've noticed that ty works with both type: ignore and ty: ignore.
| def fixed_shape_tensor( | ||
| value_type: _ValueT, | ||
| shape: Sequence[int], | ||
| dim_names: Sequence[str] | None = None, |
There was a problem hiding this comment.
Went to some talks at EuroPython about the new sentinel built-in. At some point we might want to consider, e.g. sentinel("MISSING"), see this Reddit example.
| def type_for_alias(name: str) -> DataType: ... | ||
| def schema( | ||
| fields: SupportsArrowSchema | _SchemaFieldsInput, | ||
| metadata: _KeyValueMetadataInput | KeyValueMetadata = None, |
There was a problem hiding this comment.
Only just spotted this now, but should we also have | None?
| metadata: _KeyValueMetadataInput | KeyValueMetadata = None, | |
| metadata: _KeyValueMetadataInput | KeyValueMetadata | None = None, |
| ) -> Schema: ... | ||
| def from_numpy_dtype(dtype: np.dtype[Any] | type | str) -> DataType: ... | ||
|
|
||
| __all__ = [ |
There was a problem hiding this comment.
These are usually sorted and are done automatically for me. Looks like that is coming from RUF022.
Rationale for this change
This is the second in series of PRs adding type annotations to pyarrow and resolving #32609. It builds on top of and should be merged after #48618.
What changes are included in this PR?
This adds:
_types.pyi- Core type definitions including_stubs_typing.pyi- Internal typing protocols and helpers used across stub fileserror.pyi- Exception classes (ArrowException,ArrowInvalid,ArrowIOError, etc.)lib.pyi,io.pyi,scalar.pyi- using__getattr__to allow imports to resolve while deferring to subsequent PRsAre these changes tested?
Via CI type checks established in #48618.
Are there any user-facing changes?
Users will start seeing some minimal annotated types.