Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 0 additions & 4 deletions Lib/test/test_genericalias.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ class BaseTest(unittest.TestCase):
if ctypes is not None:
generic_types.extend((ctypes.Array, ctypes.LibraryLoader))

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_subscriptable(self):
for t in self.generic_types:
if t is None:
Expand Down Expand Up @@ -314,8 +312,6 @@ def test_dir(self):
for generic_alias_property in ("__origin__", "__args__", "__parameters__"):
self.assertIn(generic_alias_property, dir_of_gen_alias)

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_weakref(self):
for t in self.generic_types:
if t is None:
Expand Down
11 changes: 9 additions & 2 deletions stdlib/src/contextvars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ thread_local! {

#[pymodule]
mod _contextvars {
use rustpython_vm::builtins::PyGenericAlias;

use crate::vm::{
AsObject, Py, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, atomic_func,
builtins::{PyStrRef, PyTypeRef},
Expand Down Expand Up @@ -471,8 +473,8 @@ mod _contextvars {
}

#[pyclassmethod(magic)]
fn class_getitem(_cls: PyTypeRef, _key: PyStrRef, _vm: &VirtualMachine) -> PyResult<()> {
unimplemented!("ContextVar.__class_getitem__() is currently under construction")
fn class_getitem(cls: PyTypeRef, args: PyObjectRef, vm: &VirtualMachine) -> PyGenericAlias {
PyGenericAlias::new(cls, args, vm)
}
}

Expand Down Expand Up @@ -561,6 +563,11 @@ mod _contextvars {
None => ContextTokenMissing::static_type().to_owned().into(),
}
}

#[pyclassmethod(magic)]
fn class_getitem(cls: PyTypeRef, args: PyObjectRef, vm: &VirtualMachine) -> PyGenericAlias {
PyGenericAlias::new(cls, args, vm)
}
}

impl Constructor for ContextToken {
Expand Down
Loading