add SlotGetattro on GenericAlias
use crate::{
- builtins::{PyList, PyStr, PyTuple, PyTupleRef, PyTypeRef},
+ builtins::{PyList, PyStr, PyStrRef, PyTuple, PyTupleRef, PyTypeRef},
common::hash,
function::IntoPyObject,
- slots::{Hashable, SlotConstructor},
+ slots::{Hashable, SlotConstructor, SlotGetattro},
IdProtocol, PyClassImpl, PyContext, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject,
TypeProtocol, VirtualMachine,
};
@@ -52,7 +52,7 @@ impl SlotConstructor for PyGenericAlias {
}
}
-#[pyimpl(with(Hashable), flags(BASETYPE))]
+#[pyimpl(with(Hashable, SlotGetattro), flags(BASETYPE))]
impl PyGenericAlias {
pub fn new(origin: PyTypeRef, args: PyObjectRef, vm: &VirtualMachine) -> Self {
let args: PyTupleRef = if let Ok(tuple) = PyTupleRef::try_from_object(vm, args.clone()) {
@@ -169,6 +169,17 @@ impl Hashable for PyGenericAlias {
}
}
+impl SlotGetattro for PyGenericAlias {
+ fn getattro(zelf: PyRef<Self>, attr: PyStrRef, vm: &VirtualMachine) -> PyResult {
+ for exc in ATTR_EXCEPTIONS.iter() {
+ if *(*exc) == attr.to_string() {
+ return vm.generic_getattribute(zelf.as_object().clone(), attr);
+ }
+ }
+ vm.get_attribute(zelf.origin(), attr)
+ }
+}
+
pub fn init(context: &PyContext) {
let generic_alias_type = &context.types.generic_alias_type;
PyGenericAlias::extend_class(context, generic_alias_type);
