Skip to content

Commit a06985f

Browse files
authored
Merge pull request #198 from tylerriccio33/typing
Add experimental gradual typing for development
2 parents 3068f77 + 227d176 commit a06985f

File tree

8 files changed

+89
-72
lines changed

8 files changed

+89
-72
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,6 @@ benchmark/data/*.json
141141
uv.lock
142142
memory
143143
.vscode/mcp.json
144+
145+
# While typing is experimental, don't mark the entire package as typed
146+
pointblank/py.typed

CONTRIBUTING.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ Once there is consensus that a PR based on the issue would be helpful, adhering
2525

2626
### Setting Up Your Development Environment
2727

28-
To set up your development environment, you can follow these steps:
28+
To set up your development environment, first clone the posit-dev/pointblank repository.
2929

30-
- Clone the posit-dev/pointblank repository
31-
- Create a virtual environment for the folder
32-
- Install the package in editable mode with `pip install -e .` from the root of the project folder
30+
If you're using UV, you may run `uv sync` and your environment is setup! If using pip or another package manager, keep following these steps:
31+
32+
- Create a virtual environment for the folder.
33+
- Install the package in editable mode with `pip install -e .` from the root of the project folder.
3334
- Install the development dependencies with `pip install '.[dev]'` (have a look at the `pyproject.toml` file for the list of development dependencies)
3435

3536
Our documentation uses `quartodoc` which in turn requires a local install of the Quarto CLI. To install Quarto, go to <https://quarto.org/docs/get-started/> to get the latest build for your platform.
@@ -43,3 +44,7 @@ Building the documentation can be done with `make docs-build` from the root of t
4344
The tests are located in the `tests` folder and we use `pytest` for running them. To run all of the tests, use `make test`. If you want to run a specific test file, you can use `pytest tests/test_file.py`.
4445

4546
If you create new tests involving snapshots, please ensure that the resulting snapshots are relatively small. After adding snapshots, use `make test-update` (this runs `pytest --snapshot-update`). A subsequent use of `make test` should pass without any issues.
47+
48+
### Linting and Type Checking
49+
50+
We use `ruff` for linting, the settings used are fairly loose and objective. Linting is run in pre-commit in CI. You can run it locally with `make lint`. Type checking is currently not enforced, but we intend on gradually typing the codebase. You can run `make type` to run Astral's new experimental type checker `ty`. Feel free to leverage type hints and occasionally type checking but it's not obligatory at this time.

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ install-pre-commit: # Install pre-commit hooks
4545
run-pre-commit: # Run pre-commit hooks
4646
@uvx pre-commit run --all-files
4747

48+
49+
type: ## Run experimental type checking
50+
@uv run ty check pointblank
51+
52+
4853
check:
4954
pyright --pythonversion 3.8 pointblank
5055
pyright --pythonversion 3.9 pointblank

pointblank/_typing.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from __future__ import annotations
22

3+
import datetime
34
import sys
5+
from collections.abc import Container
46
from typing import List, Tuple, Union
57

68
# Check Python version for TypeAlias support
@@ -15,6 +17,12 @@
1517
SegmentTuple: TypeAlias = Tuple[str, SegmentValue]
1618
SegmentItem: TypeAlias = Union[str, SegmentTuple]
1719
SegmentSpec: TypeAlias = Union[str, SegmentTuple, List[SegmentItem]]
20+
21+
_CompliantValue: TypeAlias = Union[str, int, float, datetime.datetime, datetime.date]
22+
"""A compliant value that pointblank can use in a validation step"""
23+
_CompliantValues: TypeAlias = Container[_CompliantValue]
24+
"""A collection of compliant values that pointblank can use in a validation step"""
25+
1826
else:
1927
# Python 3.8 and 3.9 compatible type aliases
2028
AbsoluteBounds = Tuple[int, int]
@@ -24,6 +32,10 @@
2432
SegmentTuple = Tuple[str, SegmentValue]
2533
SegmentItem = Union[str, SegmentTuple]
2634
SegmentSpec = Union[str, SegmentTuple, List[SegmentItem]]
35+
_CompliantValue = Union[str, int, float, datetime.datetime, datetime.date]
36+
"""A compliant value that pointblank can use in a validation step"""
37+
_CompliantValues = Container[_CompliantValue]
38+
"""A collection of compliant values that pointblank can use in a validation step"""
2739

2840
# Add docstrings for better IDE support
2941
# In Python 3.14+, __doc__ attribute on typing.Union objects became read-only

pointblank/schema.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22

33
import copy
44
from dataclasses import dataclass
5+
from typing import TYPE_CHECKING
56

67
import narwhals as nw
78

89
from pointblank._constants import IBIS_BACKENDS
910
from pointblank._utils import _get_tbl_type, _is_lazy_frame, _is_lib_present, _is_narwhals_table
1011

12+
if TYPE_CHECKING:
13+
from typing import Any
14+
1115
__all__ = ["Schema", "_check_schema_match"]
1216

1317

@@ -272,14 +276,14 @@ class Schema:
272276
columns: str | list[str] | list[tuple[str, str]] | list[tuple[str]] | dict[str, str] | None = (
273277
None
274278
)
275-
tbl: any | None = None
279+
tbl: Any | None = None
276280

277281
def __init__(
278282
self,
279283
columns: (
280284
str | list[str] | list[tuple[str, str]] | list[tuple[str]] | dict[str, str] | None
281285
) = None,
282-
tbl: any | None = None,
286+
tbl: Any | None = None,
283287
**kwargs,
284288
):
285289
if tbl is None and columns is None and not kwargs:
@@ -889,7 +893,7 @@ def _schema_info_generate_params_dict(
889893

890894

891895
def _get_schema_validation_info(
892-
data_tbl: any,
896+
data_tbl: Any,
893897
schema: Schema,
894898
passed: bool,
895899
complete: bool,

0 commit comments

Comments
 (0)