Repository navigation
[behave] Add stubs for model.Table and model.Row
#16721
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
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
239eb9b
[behave] Add stubs for model.Table and model.Row
Dhairya-007 577dc60
Use =None for the incomplete comments parameters
Dhairya-007 a2f1e41
[behave] Table.from_dicts/from_data take dicts, not any Mapping
Dhairya-007 b7eb5c6
[behave] Use Never instead of the deprecated NoReturn
Dhairya-007 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,72 @@ | ||
| from _typeshed import Incomplete | ||
| from collections import OrderedDict | ||
| from collections.abc import Iterable, Iterator, Mapping, Sequence | ||
| from typing import ClassVar, TypeAlias, TypeVar, overload | ||
| from typing_extensions import Never, Self | ||
|
|
||
| from behave.model_core import Replayable | ||
|
|
||
| _T = TypeVar("_T") | ||
|
|
||
| # A table row, either already parsed or as a plain list of cell values. | ||
| _RowData: TypeAlias = Row | list[str] | ||
|
|
||
| class Table(Replayable): | ||
| type: ClassVar[str] | ||
| headings: list[str] | ||
| rows: list[Row] | ||
| line: int | ||
| modified: bool | ||
| def __init__(self, headings: list[str], rows: Iterable[_RowData] | None = None, line: int | None = None) -> None: ... | ||
| def clear(self, headings: list[str] | None = None, keep_headings: bool = True) -> None: ... | ||
| def add_row(self, row: _RowData, line: int | None = None) -> None: ... | ||
| def add_column(self, column_name: str, values: Iterable[str] | None = None, default_value: str = "") -> int: ... | ||
| def remove_column(self, column_name_or_index: str | int) -> None: ... | ||
| def remove_columns(self, column_names: Iterable[str]) -> None: ... | ||
| def has_column(self, column_name: str) -> bool: ... | ||
| def get_column_index(self, column_name: str) -> int: ... | ||
| def require_column(self, column_name: str) -> int: ... | ||
| def require_columns(self, column_names: Iterable[str]) -> None: ... | ||
| def ensure_column_exists(self, column_name: str) -> int: ... | ||
| def __eq__(self, other: object) -> bool: ... | ||
| def __ne__(self, other: object) -> bool: ... | ||
| def __iter__(self) -> Iterator[Row]: ... | ||
|
|
||
| @overload | ||
| def __getitem__(self, index: int) -> Row: ... | ||
| @overload | ||
| def __getitem__(self, index: slice) -> list[Row]: ... | ||
|
|
||
| # Always raises: the comparison is asserted and then `NotImplementedError` is raised. | ||
| def assert_equals(self, data: object) -> Never: ... | ||
| @classmethod | ||
| def from_dicts(cls, headings: list[str], table_data: Sequence[dict[str, str]], line: int | None = None) -> Self: ... | ||
| @classmethod | ||
| def from_data( | ||
| cls, headings: list[str], table_data: Sequence[dict[str, str] | _RowData] | None = None, line: int = 0 | ||
| ) -> Table: ... | ||
|
|
||
| class Row: | ||
| headings: list[str] | ||
| cells: list[str] | ||
| line: int | None | ||
| comments: Incomplete | None | ||
| def __init__(self, headings: list[str], cells: list[str], line: int | None = None, comments=None) -> None: ... | ||
| def __getitem__(self, name: str | int) -> str: ... | ||
| def __contains__(self, item: str) -> bool: ... | ||
| def __eq__(self, other: object) -> bool: ... | ||
| def __ne__(self, other: object) -> bool: ... | ||
| def __len__(self) -> int: ... | ||
| def __iter__(self) -> Iterator[str]: ... | ||
| def items(self) -> zip[tuple[str, str]]: ... | ||
|
|
||
| @overload | ||
| def get(self, key: str | int, default: None = None) -> str | None: ... | ||
| @overload | ||
| def get(self, key: str | int, default: _T) -> str | _T: ... | ||
|
|
||
| def as_dict(self) -> OrderedDict[str, str]: ... | ||
| @classmethod | ||
| def from_dict(cls, headings: list[str], row_data: Mapping[str, str], *, line: int | None = None, comments=None) -> Self: ... | ||
|
|
||
| def __getattr__(name: str) -> Incomplete: ... | ||
This file contains hidden or 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,8 @@ | ||
| from _typeshed import Incomplete | ||
| from typing import ClassVar | ||
|
|
||
| class Replayable: | ||
| type: ClassVar[str | None] | ||
| def replay(self, formatter) -> None: ... | ||
|
|
||
| def __getattr__(name: str) -> Incomplete: ... |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mappingtoo narrow (there is an explicitisinstancecheck):There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in a2f1e41 — both now take
Sequence[dict[str, str]]/Sequence[dict[str, str] | _RowData].from_dictsraisesTypeError("%r (expected: List[dict]")whentable_data[0]is not adict, andfrom_datatakes its else-branch and passes the data straight toTable(headings, rows=table_data), so a non-dictMappingis rejected by one and silently mishandled by the other.Left
Row.from_dictonMapping: it only doesrow_data.get(name), no isinstance check.