-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* try Python 3.9 in workflow * Update lint-and-test.yaml * try from __future__ import annotations * Update conftest.py * add eval-type-backport * more from __future__ import annotations * remove TypeAlias * replace zip with strict_zip * ignore 3.9 mypy issues * fix bug in backporting.py * Update lint-and-test.yaml * Update lint-and-test.yaml
- Loading branch information
Showing
33 changed files
with
295 additions
and
93 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
from __future__ import annotations | ||
|
||
from pathlib import Path | ||
|
||
import pytest | ||
|
This file contains 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,74 @@ | ||
import pytest | ||
|
||
from wind_up.backporting import strict_zip | ||
|
||
|
||
def test_equal_length_iterables() -> None: | ||
a = [1, 2, 3] | ||
b = ["a", "b", "c"] | ||
result = list(strict_zip(a, b, strict=True)) | ||
assert result == [(1, "a"), (2, "b"), (3, "c")] | ||
|
||
|
||
def test_unequal_length_raises_value_error() -> None: | ||
a = [1, 2, 3] | ||
b = ["a", "b"] | ||
|
||
with pytest.raises(ValueError): # noqa PT011 | ||
list(strict_zip(a, b, strict=True)) | ||
|
||
|
||
def test_unequal_length_non_strict() -> None: | ||
a = [1, 2, 3] | ||
b = ["a", "b"] | ||
|
||
result = list(strict_zip(a, b, strict=False)) | ||
assert result == [(1, "a"), (2, "b")] # Shorter iterable determines length | ||
|
||
|
||
def test_empty_iterables() -> None: | ||
a = [] | ||
b = [] | ||
|
||
result = list(strict_zip(a, b, strict=True)) | ||
assert result == [] | ||
|
||
|
||
def test_single_iterable() -> None: | ||
a = [1, 2, 3] | ||
|
||
result = list(strict_zip(a, strict=True)) | ||
assert result == [(1,), (2,), (3,)] | ||
|
||
|
||
def test_multiple_iterables() -> None: | ||
a = [1, 2, 3] | ||
b = ["a", "b", "c"] | ||
c = [True, False, True] | ||
|
||
result = list(strict_zip(a, b, c, strict=True)) | ||
assert result == [(1, "a", True), (2, "b", False), (3, "c", True)] | ||
|
||
|
||
def test_non_iterable_argument() -> None: | ||
a = [1, 2, 3] | ||
b = 5 # Not iterable | ||
|
||
with pytest.raises(TypeError): | ||
list(strict_zip(a, b, strict=True)) | ||
|
||
|
||
def test_tuple_and_generator() -> None: | ||
a = (1, 2, 3) | ||
b = (x for x in ["a", "b", "c"]) # Generator | ||
|
||
result = list(strict_zip(a, b, strict=True)) | ||
assert result == [(1, "a"), (2, "b"), (3, "c")] | ||
|
||
|
||
def test_nested_iterables() -> None: | ||
a = [[1], [2], [3]] | ||
b = [["a"], ["b"], ["c"]] | ||
|
||
result = list(strict_zip(a, b, strict=True)) | ||
assert result == [([1], ["a"]), ([2], ["b"]), ([3], ["c"])] |
This file contains 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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
from __future__ import annotations | ||
|
||
import numpy as np | ||
import pandas as pd | ||
import pytest | ||
|
This file contains 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 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 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,16 @@ | ||
import sys | ||
from collections.abc import Iterable, Iterator | ||
|
||
if sys.version_info >= (3, 10): | ||
|
||
def strict_zip(*iterables: Iterable, strict: bool = False) -> Iterator: | ||
return zip(*iterables, strict=strict) | ||
else: | ||
|
||
def strict_zip(*iterables: Iterable, strict: bool = False) -> Iterator: | ||
if strict: | ||
iterables = [list(it) for it in iterables] # type: ignore[assignment] | ||
if not all(len(it) == len(iterables[0]) for it in iterables): # type: ignore[arg-type] | ||
msg = "All iterables must have the same length" | ||
raise ValueError(msg) | ||
return zip(*iterables) # type: ignore[call-overload] |
This file contains 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 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 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 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 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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
from __future__ import annotations | ||
|
||
import logging | ||
import math | ||
|
||
|
This file contains 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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
from __future__ import annotations | ||
|
||
import numpy as np | ||
import numpy.typing as npt | ||
|
||
|
Oops, something went wrong.