Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7632716

Browse filesBrowse files
DaraanAlexWaygood
andauthored
_collect_type_vars should not collect Unpack objects itself (#472)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
1 parent 832253d commit 7632716
Copy full SHA for 7632716

File tree

Expand file treeCollapse file tree

3 files changed

+23
-1
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+23
-1
lines changed

‎CHANGELOG.md

Copy file name to clipboardExpand all lines: CHANGELOG.md
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
- Fix bug where a subscripted `TypeAliasType` instance did not have all
1313
attributes of the original `TypeAliasType` instance on older Python versions.
1414
Patch by [Daraan](https://github.com/Daraan) and Alex Waygood.
15+
- Fix bug where subscripted `TypeAliasType` instances (and some other
16+
subscripted objects) had wrong parameters if they were directly
17+
subscripted with an `Unpack` object.
18+
Patch by [Daraan](https://github.com/Daraan).
1519

1620
# Release 4.12.2 (June 7, 2024)
1721

‎src/test_typing_extensions.py

Copy file name to clipboardExpand all lines: src/test_typing_extensions.py
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7247,6 +7247,21 @@ def test_getitem(self):
72477247
self.assertEqual(get_args(fully_subscripted), (Iterable[float],))
72487248
self.assertIs(get_origin(fully_subscripted), ListOrSetT)
72497249

7250+
def test_unpack_parameter_collection(self):
7251+
Ts = TypeVarTuple("Ts")
7252+
7253+
class Foo(Generic[Unpack[Ts]]):
7254+
bar: Tuple[Unpack[Ts]]
7255+
7256+
FooAlias = TypeAliasType("FooAlias", Foo[Unpack[Ts]], type_params=(Ts,))
7257+
self.assertEqual(FooAlias[Unpack[Tuple[str]]].__parameters__, ())
7258+
self.assertEqual(FooAlias[Unpack[Tuple[T]]].__parameters__, (T,))
7259+
7260+
P = ParamSpec("P")
7261+
CallableP = TypeAliasType("CallableP", Callable[P, Any], type_params=(P,))
7262+
call_int_T = CallableP[Unpack[Tuple[int, T]]]
7263+
self.assertEqual(call_int_T.__parameters__, (T,))
7264+
72507265
def test_alias_attributes(self):
72517266
T = TypeVar('T')
72527267
T2 = TypeVar('T2')

‎src/typing_extensions.py

Copy file name to clipboardExpand all lines: src/typing_extensions.py
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3068,7 +3068,10 @@ def _collect_type_vars(types, typevar_types=None):
30683068
for t in types:
30693069
if _is_unpacked_typevartuple(t):
30703070
type_var_tuple_encountered = True
3071-
elif isinstance(t, typevar_types) and t not in tvars:
3071+
elif (
3072+
isinstance(t, typevar_types) and not isinstance(t, _UnpackAlias)
3073+
and t not in tvars
3074+
):
30723075
if enforce_default_ordering:
30733076
has_default = getattr(t, '__default__', NoDefault) is not NoDefault
30743077
if has_default:

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.