|
1 | 1 | use crate::{
|
2 |
| - builtins::{PyList, PyStr, PyTuple, PyTupleRef, PyTypeRef}, |
| 2 | + builtins::{PyList, PyStr, PyStrRef, PyTuple, PyTupleRef, PyTypeRef}, |
3 | 3 | common::hash,
|
4 | 4 | function::IntoPyObject,
|
5 |
| - slots::{Hashable, SlotConstructor}, |
| 5 | + slots::{Hashable, SlotConstructor, SlotGetattro}, |
6 | 6 | IdProtocol, PyClassImpl, PyContext, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject,
|
7 | 7 | TypeProtocol, VirtualMachine,
|
8 | 8 | };
|
@@ -52,7 +52,7 @@ impl SlotConstructor for PyGenericAlias {
|
52 | 52 | }
|
53 | 53 | }
|
54 | 54 |
|
55 |
| -#[pyimpl(with(Hashable), flags(BASETYPE))] |
| 55 | +#[pyimpl(with(Hashable, SlotConstructor, SlotGetattro), flags(BASETYPE))] |
56 | 56 | impl PyGenericAlias {
|
57 | 57 | pub fn new(origin: PyTypeRef, args: PyObjectRef, vm: &VirtualMachine) -> Self {
|
58 | 58 | let args: PyTupleRef = if let Ok(tuple) = PyTupleRef::try_from_object(vm, args.clone()) {
|
@@ -169,6 +169,17 @@ impl Hashable for PyGenericAlias {
|
169 | 169 | }
|
170 | 170 | }
|
171 | 171 |
|
| 172 | +impl SlotGetattro for PyGenericAlias { |
| 173 | + fn getattro(zelf: PyRef<Self>, attr: PyStrRef, vm: &VirtualMachine) -> PyResult { |
| 174 | + for exc in ATTR_EXCEPTIONS.iter() { |
| 175 | + if *(*exc) == attr.to_string() { |
| 176 | + return vm.generic_getattribute(zelf.as_object().clone(), attr); |
| 177 | + } |
| 178 | + } |
| 179 | + vm.get_attribute(zelf.origin(), attr) |
| 180 | + } |
| 181 | +} |
| 182 | + |
172 | 183 | pub fn init(context: &PyContext) {
|
173 | 184 | let generic_alias_type = &context.types.generic_alias_type;
|
174 | 185 | PyGenericAlias::extend_class(context, generic_alias_type);
|
|
0 commit comments