Skip to content

Commit bef9426

Browse files
authored
Fix iterable sequence bug under unusual circumstances (#72)
Fixes #65
2 parents 0e22a38 + 577c752 commit bef9426

9 files changed

Lines changed: 29 additions & 16 deletions

File tree

.github/workflows/test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
pytest-flags: -vv mypy_pytest_plugin -n auto --shard-id=${{ matrix.shard }} --num-shards=${{ matrix.total-shards }} --inline-snapshot=disable
2222

2323
integration_tests:
24-
uses: George-Ogden/actions/.github/workflows/python-test.yaml@v4.0.2
24+
uses: George-Ogden/actions/.github/workflows/python-test.yaml@v4.3.0
2525
with:
2626
python-versions: "['3.12', '3.13', '3.14']"
2727
timeout-minutes: 10

.mirror.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# DANGER: EDIT AT YOUR OWN RISK. Track this file in version control so that others can sync files correctly.
2-
- commit: 7193772bffc9c387e2ba0c271cdf27b592ddd21f
2+
- commit: ef96ade262662786dd73eee856f6b20de499529e
33
files:
44
- .github/python-release.yaml
55
- .github/python-test.yaml

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ repos:
4040
args: [--severity=warning]
4141

4242
- repo: https://github.com/astral-sh/ruff-pre-commit/
43-
rev: v0.15.10
43+
rev: v0.15.11
4444
hooks:
4545
- id: ruff-check
4646
args: [--fix]
@@ -64,7 +64,7 @@ repos:
6464
- id: codespell
6565

6666
- repo: https://github.com/George-Ogden/pre-commit-hooks/
67-
rev: v3.1.0
67+
rev: v3.1.1
6868
hooks:
6969
- id: check-merge-conflict
7070
- id: dbg-check

mypy_pytest_plugin/iterable_sequence_checker.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,12 @@ def check_iterable_sequence_arguments(self, call: CallExpr) -> None:
3636
self.check_iterable_sequence_argument(argument, expected_type)
3737

3838
def check_iterable_sequence_argument(self, argument: Expression, expected_type: Type) -> None:
39-
argument_type = self.checker.lookup_type(argument)
40-
if self.is_sequence(argument_type) and self.is_iterable(expected_type):
39+
argument_type = self.checker.lookup_type_or_none(argument)
40+
if (
41+
argument_type is not None
42+
and self.is_sequence(argument_type)
43+
and self.is_iterable(expected_type)
44+
):
4145
self._display_error_message(expected_type, argument_type, argument)
4246

4347
def _display_error_message(

requirements-dev.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
-r requirements.txt
2-
georges-utils
2+
git+https://github.com/George-Ogden/extra-types; python_version >= "3.12"
33
git+https://github.com/George-Ogden/mirror-rorrim; python_version >= "3.12"
44
git+https://github.com/George-Ogden/pytest-dbg; python_version >= "3.11"
5+
git+https://github.com/George-Ogden/utils; python_version >= "3.12"
56
inline-snapshot
67
prek
78
py-spy
89
pytest>=9.0.0
910
pytest-shard
1011
pytest-timeout
1112
pytest-xdist
12-
ruff==0.15.10
13+
ruff==0.15.11

ruff.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ indent-style = "space"
88
exclude = ["test_samples/"]
99
extend-select = ["B", "C4", "COM818", "ERA", "F", "I", "ISC", "N", "PT", "PYI", "RET", "RUF", "SIM", "UP", "W"]
1010
extend-ignore = ["C408", "E501", "F811", "PLC0414", "PT011", "PT012", "PT013", "PYI041", "RET504", "S", "SIM118", "TRY"]
11-
extend-unfixable = ["B905", "B911", "B912"]
11+
extend-unfixable = ["B905", "B911", "B912", "PT006"]
1212
preview = true
1313

1414
[lint.isort]

test_samples/valid_test.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
from collections.abc import Callable, Iterable, Sequence
12
from typing import Literal
2-
from pytest import CaptureFixture, Pytester
33

44
import pytest
5+
from pytest import CaptureFixture, Pytester
56

67

78
@pytest.mark.parametrize("x", range(5))
@@ -42,3 +43,10 @@ def test_use_builtin_fixture(capsys: CaptureFixture[str]) -> None: ...
4243

4344
@pytest.mark.skip
4445
def test_pytester_fixture(pytester: Pytester) -> None: ...
46+
47+
48+
def test_range_argument() -> None:
49+
def cached_iterator[**P, T](fn: Callable[P, Iterable[T]]) -> Callable[P, Sequence[T]]:
50+
raise NotImplementedError()
51+
52+
cached_iterator(range)
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
test_samples/valid_test.py:14: error: Incompatible return value type (got "tuple[Literal[0], Literal[2]]", expected "tuple[Literal[1], Literal[2]]") [return-value]
2-
test_samples/valid_test.py:17: error: Unexpected keyword argument "foo" for "param" [call-arg]
3-
test_samples/valid_test.py:17: note: "param" defined in "mypy_pytest_plugin_types.pytest"
4-
test_samples/valid_test.py:20: error: No return value expected [return-value]
5-
test_samples/valid_test.py:26: error: No return value expected [return-value]
1+
test_samples/valid_test.py:15: error: Incompatible return value type (got "tuple[Literal[0], Literal[2]]", expected "tuple[Literal[1], Literal[2]]") [return-value]
2+
test_samples/valid_test.py:18: error: Unexpected keyword argument "foo" for "param" [call-arg]
3+
test_samples/valid_test.py:18: note: "param" defined in "mypy_pytest_plugin_types.pytest"
4+
test_samples/valid_test.py:21: error: No return value expected [return-value]
5+
test_samples/valid_test.py:27: error: No return value expected [return-value]
66
Found 4 errors in 1 file (checked 1 source file)

version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.3.2
1+
2.3.3

0 commit comments

Comments
 (0)