Skip to content

Commit

Permalink
Mypy disallow untyped calls (#4140)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Jul 24, 2022
1 parent 8f5cde8 commit 1e2fbd9
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 8 deletions.
48 changes: 47 additions & 1 deletion .github/workflows/test-python.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ "3.7", "3.10" ]
python-version: [ "3.10" ]
steps:
- uses: actions/checkout@v3
- name: Install latest Rust nightly
Expand Down Expand Up @@ -51,3 +51,49 @@ jobs:
run: |
pip uninstall pandas -y
python -c "import polars"
test-python-37:
name: Build and test Python 3.7
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ "3.7" ]
steps:
- uses: actions/checkout@v3
- name: Install latest Rust nightly
uses: actions-rs/toolchain@v1
with:
toolchain: nightly-2022-06-22
override: true
components: rustfmt, clippy
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r py-polars/build.requirements.txt
- name: Run formatting checks
run: |
cd py-polars && black --check . && blackdoc --check . && isort --check . && rustup override set nightly-2022-06-22 && cargo fmt --all -- --check && cd ..
- name: Run linting
run: |
cd py-polars && flake8 && cd ..
# this step is different, note the flag
- name: Run type checking
run: |
cd py-polars && mypy --allow-untyped-calls && cd ..
- name: Run tests
run: |
export RUSTFLAGS="-C debuginfo=0"
cd py-polars && rustup override set nightly-2022-06-22 && make venv && make test-with-cov
cargo clippy
- name: Check doc examples
run: |
cd py-polars && make doctest
# test if we can import polars without any requirements
- name: Import polars
run: |
pip uninstall pandas -y
python -c "import polars"
2 changes: 1 addition & 1 deletion py-polars/polars/internals/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -2296,7 +2296,7 @@ def to_numpy(
kwargs will be sent to pyarrow.Array.to_numpy
"""

def convert_to_date(arr): # type: ignore[no-untyped-def]
def convert_to_date(arr: np.ndarray) -> np.ndarray:
if self.dtype == Date:
tp = "datetime64[D]"
elif self.dtype == Duration:
Expand Down
2 changes: 1 addition & 1 deletion py-polars/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ warn_unused_ignores = true
strict_concatenate = true
# TODO: Uncomment flags below and fix mypy errors
# disallow_any_generics = true
# disallow_untyped_calls = true
disallow_untyped_calls = true
warn_redundant_casts = true
# warn_return_any = true
# no_implicit_reexport = true
Expand Down
10 changes: 5 additions & 5 deletions py-polars/tests/test_df.py
Original file line number Diff line number Diff line change
Expand Up @@ -1096,13 +1096,13 @@ def test_hashing_on_python_objects() -> None:
df = pl.DataFrame({"a": [1, 1, 3, 4], "b": [1, 1, 2, 2]})

class Foo:
def __init__(self): # type: ignore[no-untyped-def]
def __init__(self) -> None:
pass

def __hash__(self): # type: ignore[no-untyped-def]
def __hash__(self) -> int:
return 0

def __eq__(self, other): # type: ignore[no-untyped-def]
def __eq__(self, other: Any) -> bool:
return True

df = df.with_column(pl.col("a").apply(lambda x: Foo()).alias("foo"))
Expand Down Expand Up @@ -1304,10 +1304,10 @@ def name_generator() -> Iterator[str]:

def test_extension() -> None:
class Foo:
def __init__(self, value): # type: ignore[no-untyped-def]
def __init__(self, value: Any) -> None:
self.value = value

def __repr__(self): # type: ignore[no-untyped-def]
def __repr__(self) -> str:
return f"foo({self.value})"

foos = [Foo(1), Foo(2), Foo(3)]
Expand Down

0 comments on commit 1e2fbd9

Please sign in to comment.