8000 ENH: Add a typing protocol for representing nested sequences by BvB93 · Pull Request #19894 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

ENH: Add a typing protocol for representing nested sequences #19894

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

Merged
merged 3 commits into from
Sep 20, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
TST: Added tests for NestedSequence
  • Loading branch information
Bas van Beek committed Sep 19, 2021
commit 0ae66c201f5cbd1cd391701f1eeb1c78d92f4e1e
17 changes: 17 additions & 0 deletions numpy/typing/tests/data/fail/nested_sequence.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from typing import Sequence, Tuple, List
import numpy.typing as npt

a: Sequence[float]
b: List[complex]
c: Tuple[str, ...]
d: int
e: str

def func(a: npt._NestedSequence[int]) -> None:
...

reveal_type(func(a)) # E: incompatible type
reveal_type(func(b)) # E: incompatible type
reveal_type(func(c)) # E: incompatible type
reveal_type(func(d)) # E: incompatible type
reveal_type(func(e)) # E: incompatible type
23 changes: 23 additions & 0 deletions numpy/typing/tests/data/reveal/nested_sequence.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from typing import Sequence, Tuple, List, Any
import numpy.typing as npt

a: Sequence[int]
b: Sequence[Sequence[int]]
c: Sequence[Sequence[Sequence[int]]]
d: Sequence[Sequence[Sequence[Sequence[int]]]]
e: Sequence[bool]
f: Tuple[int, ...]
g: List[int]
h: Sequence[Any]

def func(a: npt._NestedSequence[int]) -> None:
...

reveal_type(func(a)) # E: None
reveal_type(func(b)) # E: None
reveal_type(func(c)) # E: None
reveal_type(func(d)) # E: None
reveal_type(func(e)) # E: None
reveal_type(func(f)) # E: None
reveal_type(func(g)) # E: None
reveal_type(func(h)) # E: None
0