Skip to content
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

chore(python): Add minimal type stubs for .pyx files #468

Merged
merged 7 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@

dist/* linguist-generated
extensions/nanoarrow_ipc/thirdparty/* linguist-vendored
python/src/nanoarrow/*.pxi linguist-generated
13 changes: 13 additions & 0 deletions .github/workflows/python.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,19 @@ jobs:
run: |
pytest python/tests -v -s

- name: Check type stubs
if: success() && matrix.python-version == '3.12'
run: |
pip install mypy "black==22.3.0"
python/generate_type_stubs.sh

if git diff --name-only | grep -e "\\.pxi$"; then
echo "Type stubs were changed. Update them with python/generate_type_stubs.sh."
fi

stubtest nanoarrow._lib
stubtest nanoarrow._ipc_lib

- name: Run doctests
if: success() && matrix.python-version == '3.12'
run: |
Expand Down
33 changes: 33 additions & 0 deletions python/generate_type_stubs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# 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.

SOURCE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

# Generates src/nanoarrow/*.pxi given the currently installed copy of
# nanoarrow. Requires mypy and black (where black is pinned to the
# same version as in pre-commit)

pushd "${SOURCE_DIR}"

# Generate stubs using mypy
stubgen --module nanoarrow._lib --include-docstrings -o src
stubgen --module nanoarrow._ipc_lib --include-docstrings -o src

# Reformat stubs
black src/nanoarrow/*.pyi

popd
28 changes: 28 additions & 0 deletions python/src/nanoarrow/_ipc_lib.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import _cython_3_0_10
from _typeshed import Incomplete

__reduce_cython__: _cython_3_0_10.cython_function_or_method
__setstate_cython__: _cython_3_0_10.cython_function_or_method
__test__: dict
init_array_stream: _cython_3_0_10.cython_function_or_method

class CIpcInputStream:
@classmethod
def __init__(cls, *args, **kwargs) -> None:
"""Create and return a new object. See help(type) for accurate signature."""
@staticmethod
def from_readable(*args, **kwargs): ...
def is_valid(self, *args, **kwargs): ...
def release(self, *args, **kwargs): ...
def __reduce__(self): ...

class PyInputStreamPrivate:
close_obj: Incomplete
obj: Incomplete
@classmethod
def __init__(cls, *args, **kwargs) -> None:
"""Create and return a new object. See help(type) for accurate signature."""
def set_buffer(self, *args, **kwargs): ...
def __len__(self) -> int:
"""Return len(self)."""
def __reduce__(self): ...
Loading
Loading