Skip to content

Commit e894654

Browse files
authored
[behave] Add stubs for model.Table and model.Row (#16721)
1 parent 1899d65 commit e894654

3 files changed

Lines changed: 84 additions & 2 deletions

File tree

‎stubs/behave/behave/model.pyi‎

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
from _typeshed import Incomplete
2+
from collections import OrderedDict
3+
from collections.abc import Iterable, Iterator, Mapping, Sequence
4+
from typing import ClassVar, TypeAlias, TypeVar, overload
5+
from typing_extensions import Never, Self
6+
7+
from behave.model_core import Replayable
8+
9+
_T = TypeVar("_T")
10+
11+
# A table row, either already parsed or as a plain list of cell values.
12+
_RowData: TypeAlias = Row | list[str]
13+
14+
class Table(Replayable):
15+
type: ClassVar[str]
16+
headings: list[str]
17+
rows: list[Row]
18+
line: int
19+
modified: bool
20+
def __init__(self, headings: list[str], rows: Iterable[_RowData] | None = None, line: int | None = None) -> None: ...
21+
def clear(self, headings: list[str] | None = None, keep_headings: bool = True) -> None: ...
22+
def add_row(self, row: _RowData, line: int | None = None) -> None: ...
23+
def add_column(self, column_name: str, values: Iterable[str] | None = None, default_value: str = "") -> int: ...
24+
def remove_column(self, column_name_or_index: str | int) -> None: ...
25+
def remove_columns(self, column_names: Iterable[str]) -> None: ...
26+
def has_column(self, column_name: str) -> bool: ...
27+
def get_column_index(self, column_name: str) -> int: ...
28+
def require_column(self, column_name: str) -> int: ...
29+
def require_columns(self, column_names: Iterable[str]) -> None: ...
30+
def ensure_column_exists(self, column_name: str) -> int: ...
31+
def __eq__(self, other: object) -> bool: ...
32+
def __ne__(self, other: object) -> bool: ...
33+
def __iter__(self) -> Iterator[Row]: ...
34+
35+
@overload
36+
def __getitem__(self, index: int) -> Row: ...
37+
@overload
38+
def __getitem__(self, index: slice) -> list[Row]: ...
39+
40+
# Always raises: the comparison is asserted and then `NotImplementedError` is raised.
41+
def assert_equals(self, data: object) -> Never: ...
42+
@classmethod
43+
def from_dicts(cls, headings: list[str], table_data: Sequence[dict[str, str]], line: int | None = None) -> Self: ...
44+
@classmethod
45+
def from_data(
46+
cls, headings: list[str], table_data: Sequence[dict[str, str] | _RowData] | None = None, line: int = 0
47+
) -> Table: ...
48+
49+
class Row:
50+
headings: list[str]
51+
cells: list[str]
52+
line: int | None
53+
comments: Incomplete | None
54+
def __init__(self, headings: list[str], cells: list[str], line: int | None = None, comments=None) -> None: ...
55+
def __getitem__(self, name: str | int) -> str: ...
56+
def __contains__(self, item: str) -> bool: ...
57+
def __eq__(self, other: object) -> bool: ...
58+
def __ne__(self, other: object) -> bool: ...
59+
def __len__(self) -> int: ...
60+
def __iter__(self) -> Iterator[str]: ...
61+
def items(self) -> zip[tuple[str, str]]: ...
62+
63+
@overload
64+
def get(self, key: str | int, default: None = None) -> str | None: ...
65+
@overload
66+
def get(self, key: str | int, default: _T) -> str | _T: ...
67+
68+
def as_dict(self) -> OrderedDict[str, str]: ...
69+
@classmethod
70+
def from_dict(cls, headings: list[str], row_data: Mapping[str, str], *, line: int | None = None, comments=None) -> Self: ...
71+
72+
def __getattr__(name: str) -> Incomplete: ...

‎stubs/behave/behave/model_core.pyi‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from _typeshed import Incomplete
2+
from typing import ClassVar
3+
4+
class Replayable:
5+
type: ClassVar[str | None]
6+
def replay(self, formatter) -> None: ...
7+
8+
def __getattr__(name: str) -> Incomplete: ...

‎stubs/behave/behave/runner.pyi‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ from collections.abc import Callable
33
from contextlib import AbstractContextManager
44
from typing import ClassVar, ParamSpec
55

6+
from behave.model import Row, Table
7+
68
_P = ParamSpec("_P")
79

810
class Context:
@@ -14,10 +16,10 @@ class Context:
1416
tags: set[str]
1517
aborted: bool
1618
failed: bool
17-
table: Incomplete | None
19+
table: Table | None
1820
text: str | None
1921
config: Incomplete
20-
active_outline: Incomplete
22+
active_outline: Row | None
2123
fail_on_cleanup_errors: bool
2224

2325
def __init__(self, runner) -> None: ...

0 commit comments

Comments
 (0)