Skip to content
Merged
Show file tree
Hide file tree
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
Next Next commit
genericalias.__unpack__
  • Loading branch information
youknowone committed Jun 26, 2025
commit bdee951eb88fe559db4498df9c060d9a6e8a6590
2 changes: 2 additions & 0 deletions Lib/test/test_exception_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ def test_exception_is_not_generic_type(self):
with self.assertRaisesRegex(TypeError, 'Exception'):
Exception[OSError]

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_exception_group_is_generic_type(self):
E = OSError
self.assertIsInstance(ExceptionGroup[E], types.GenericAlias)
Expand Down
15 changes: 0 additions & 15 deletions Lib/test/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2446,7 +2446,6 @@ def test_repr(self):
ct3 = Callable[[str, float], list[int]]
self.assertEqual(repr(ct3), f'{fullname}[[str, float], list[int]]')

@unittest.skip("TODO: RUSTPYTHON")
def test_callable_with_ellipsis(self):
Callable = self.Callable
def foo(a: Callable[..., T]):
Expand Down Expand Up @@ -3889,8 +3888,6 @@ def test_extended_generic_rules_repr(self):
self.assertEqual(repr(Callable[[], List[T]][int]).replace('typing.', ''),
'Callable[[], List[int]]')

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_generic_forward_ref(self):
def foobar(x: List[List['CC']]): ...
def foobar2(x: list[list[ForwardRef('CC')]]): ...
Expand Down Expand Up @@ -5195,8 +5192,6 @@ def test_forward_repr(self):
self.assertEqual(repr(List[ForwardRef('int', module='mod')]),
"typing.List[ForwardRef('int', module='mod')]")

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_union_forward(self):

def foo(a: Union['T']):
Expand All @@ -5211,8 +5206,6 @@ def foo(a: tuple[ForwardRef('T')] | int):
self.assertEqual(get_type_hints(foo, globals(), locals()),
{'a': tuple[T] | int})

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_tuple_forward(self):

def foo(a: Tuple['T']):
Expand Down Expand Up @@ -5550,8 +5543,6 @@ def test_or(self):


class InternalsTests(BaseTestCase):
# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_deprecation_for_no_type_params_passed_to__evaluate(self):
with self.assertWarnsRegex(
DeprecationWarning,
Expand Down Expand Up @@ -5967,8 +5958,6 @@ def test_get_type_hints_wrapped_decoratored_func(self):
self.assertEqual(gth(ForRefExample.func), expects)
self.assertEqual(gth(ForRefExample.nested), expects)

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_get_type_hints_annotated(self):
def foobar(x: List['X']): ...
X = Annotated[int, (1, 10)]
Expand Down Expand Up @@ -6032,8 +6021,6 @@ def barfoo4(x: BA3): ...
{"x": typing.Annotated[int | float, "const"]}
)

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_get_type_hints_annotated_in_union(self): # bpo-46603
def with_union(x: int | list[Annotated[str, 'meta']]): ...

Expand Down Expand Up @@ -6172,8 +6159,6 @@ def test_get_type_hints_typeddict(self):
"year": NotRequired[Annotated[int, 2000]]
})

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_get_type_hints_collections_abc_callable(self):
# https://github.com/python/cpython/issues/91621
P = ParamSpec('P')
Expand Down
7 changes: 7 additions & 0 deletions vm/src/builtins/genericalias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub struct PyGenericAlias {
origin: PyTypeRef,
args: PyTupleRef,
parameters: PyTupleRef,
starred: bool, // for __unpacked__ attribute
}

impl fmt::Debug for PyGenericAlias {
Expand Down Expand Up @@ -92,6 +93,7 @@ impl PyGenericAlias {
origin,
args,
parameters,
starred: false, // default to false, will be set to true for Unpack[...]
}
}

Expand Down Expand Up @@ -156,6 +158,11 @@ impl PyGenericAlias {
self.origin.clone().into()
}

#[pygetset(magic)]
fn unpacked(&self) -> bool {
self.starred
}

#[pymethod(magic)]
fn getitem(&self, needle: PyObjectRef, vm: &VirtualMachine) -> PyResult {
let new_args = subs_parameters(
Expand Down
Loading