forked from coqui-ai/coqpit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: manually address remaining ruff issues for python 3.10
- Loading branch information
Showing
3 changed files
with
22 additions
and
40 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,39 @@ | ||
from typing import Union | ||
|
||
from coqpit.coqpit import _is_optional_field, _is_union, _is_union_and_not_simple_optional | ||
|
||
# TODO: `type: ignore` can probably be removed when switching to Python 3.10 | ||
# Union syntax (e.g. str | int) | ||
|
||
|
||
def test_is_union() -> None: | ||
cases = ( | ||
(Union[str, int], True), | ||
(Union[str, None], True), | ||
(str | int, True), | ||
(str | None, True), | ||
(int, False), | ||
(list[int], False), | ||
(list[str | int], False), | ||
) | ||
for item, expected in cases: | ||
assert _is_union(item) == expected # type: ignore[arg-type] | ||
assert _is_union(item) == expected | ||
|
||
|
||
def test_is_union_and_not_simple_optional() -> None: | ||
cases = ( | ||
(Union[str, int], True), | ||
(Union[str, None], False), | ||
(Union[list[int], None], False), | ||
(str | int, True), | ||
(str | None, False), | ||
(list[int] | None, False), | ||
(int, False), | ||
(list[int], False), | ||
(list[str | int], False), | ||
) | ||
for item, expected in cases: | ||
assert _is_union_and_not_simple_optional(item) == expected # type: ignore[arg-type] | ||
assert _is_union_and_not_simple_optional(item) == expected | ||
|
||
|
||
def test_is_optional_field() -> None: | ||
cases = ( | ||
(Union[str, int], False), | ||
(Union[str, None], True), | ||
(Union[list[int], None], True), | ||
(str | int, False), | ||
(str | None, True), | ||
(list[int] | None, True), | ||
(int, False), | ||
(list[int], False), | ||
(list[str | int], False), | ||
) | ||
for item, expected in cases: | ||
assert _is_optional_field(item) == expected # type: ignore[arg-type] | ||
assert _is_optional_field(item) == expected |