Skip to content
Closed
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
Add test for multiple arbitrary-length unpacked tuples in args list
  • Loading branch information
mrahtz committed May 28, 2022
commit 6b0780b5e1f14d4c00f47126e3877f2c7b5e5ccc
27 changes: 26 additions & 1 deletion Lib/test/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,15 @@ def template_replace(templates: list[str], replacements: dict[str, list[str]]) -
("Huskies are cute but also tiring")
]

Example 3: Suppose that:
templates = ["Huskies are word1. I said word!"]
replacements = {"word1": ["cool", "awesome"]}
Then we would return:
[
("Huskies are cool. I said cool!"),
("Huskies are awesome. I said awesome!"),
]

Note that if any of the replacements do not occur in any template:
templates = ["Huskies are word1", "Beagles!"]
replacements = {"word1": ["playful", "cute"],
Expand Down Expand Up @@ -563,6 +572,19 @@ def test_two_templates_two_replacements_yields_correct_renders(self):
]
self.assertEqual(actual, expected)

def test_two_instances_of_replacement_word_yields_correct_renders(self):
actual = template_replace(
templates=["Cats are word1. That's word1!"],
replacements={
"word1": ["smol", "cute"],
},
)
expected = [
("Cats are smol. That's smol!",),
("Cats are cute. That's cute!",),
]
self.assertEqual(actual, expected)

def test_no_duplicates_if_replacement_not_in_templates(self):
actual = template_replace(
templates=["Cats are word1", "Dogs!"],
Expand Down Expand Up @@ -774,9 +796,12 @@ class C(Generic[*Ts]): pass
# Should be tuple[int, *tuple[int, ...]]
('tuple[T, *Ts]', '[*tuple_type[int, ...]]', 'TypeError'),

('generic[T, *Ts]', '[*tuple_type[int, ...], *tuple_type[str, ...]]', 'TypeError'),
('generic[*Ts, T]', '[*tuple_type[int, ...], *tuple_type[str, ...]]', 'TypeError'),

('generic[*Ts, T]', '[int]', 'generic[int]'),
('generic[*Ts, T]', '[int, str]', 'generic[int, str]'),
('generic[*Ts, T]', '[int, str, bool]', 'generic[int, str, bool]'),
('generic[*Ts, T]', '[int, str, bool]', 'generic[int, str, bool]'),

('generic[T, *tuple_type[int, ...]]', '[str]', 'generic[str, *tuple_type[int, ...]]'),
('generic[T1, T2, *tuple_type[int, ...]]', '[str, bool]', 'generic[str, bool, *tuple_type[int, ...]]'),
Expand Down