Skip to content

Commit f016716

Browse files
committed
Iterable for PyGenericAlias
1 parent e7c18f1 commit f016716

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

Lib/test/test_typing.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -680,8 +680,6 @@ def test_typevartuple(self):
680680
class A(Generic[Unpack[Ts]]): ...
681681
Alias = Optional[Unpack[Ts]]
682682

683-
# TODO: RUSTPYTHON
684-
@unittest.expectedFailure
685683
def test_typevartuple_specialization(self):
686684
T = TypeVar("T")
687685
Ts = TypeVarTuple('Ts', default=Unpack[Tuple[str, int]])
@@ -1049,8 +1047,6 @@ class C(Generic[T1, T2]): pass
10491047
eval(expected_str)
10501048
)
10511049

1052-
# TODO: RUSTPYTHON
1053-
@unittest.expectedFailure
10541050
def test_three_parameters(self):
10551051
T1 = TypeVar('T1')
10561052
T2 = TypeVar('T2')

vm/src/builtins/genericalias.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use crate::{
1212
function::{FuncArgs, PyComparisonValue},
1313
protocol::{PyMappingMethods, PyNumberMethods},
1414
types::{
15-
AsMapping, AsNumber, Callable, Comparable, Constructor, GetAttr, Hashable, PyComparisonOp,
16-
Representable,
15+
AsMapping, AsNumber, Callable, Comparable, Constructor, GetAttr, Hashable, Iterable,
16+
PyComparisonOp, Representable,
1717
},
1818
};
1919
use std::fmt;
@@ -78,6 +78,7 @@ impl Constructor for PyGenericAlias {
7878
Constructor,
7979
GetAttr,
8080
Hashable,
81+
Iterable,
8182
Representable
8283
),
8384
flags(BASETYPE)
@@ -490,6 +491,13 @@ impl Representable for PyGenericAlias {
490491
}
491492
}
492493

494+
impl Iterable for PyGenericAlias {
495+
fn iter(zelf: PyRef<Self>, vm: &VirtualMachine) -> PyResult {
496+
// Return an iterator over the args tuple
497+
Ok(zelf.args.clone().to_pyobject(vm).get_iter(vm)?.into())
498+
}
499+
}
500+
493501
pub fn init(context: &Context) {
494502
let generic_alias_type = &context.types.generic_alias_type;
495503
PyGenericAlias::extend_class(context, generic_alias_type);

0 commit comments

Comments
 (0)