Skip to content

Commit 9ee566b

Browse files
authored
Merge pull request RustPython#3288 from Snowapril/add_getattro_for_ga
Add missing `SlotGetattro` for `GenericAlias`
2 parents c39d143 + f3fc4e4 commit 9ee566b

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

vm/src/builtins/genericalias.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use crate::{
2-
builtins::{PyList, PyStr, PyTuple, PyTupleRef, PyTypeRef},
2+
builtins::{PyList, PyStr, PyStrRef, PyTuple, PyTupleRef, PyTypeRef},
33
common::hash,
44
function::IntoPyObject,
5-
slots::{Hashable, SlotConstructor},
5+
slots::{Hashable, SlotConstructor, SlotGetattro},
66
IdProtocol, PyClassImpl, PyContext, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject,
77
TypeProtocol, VirtualMachine,
88
};
@@ -52,7 +52,7 @@ impl SlotConstructor for PyGenericAlias {
5252
}
5353
}
5454

55-
#[pyimpl(with(Hashable), flags(BASETYPE))]
55+
#[pyimpl(with(Hashable, SlotConstructor, SlotGetattro), flags(BASETYPE))]
5656
impl PyGenericAlias {
5757
pub fn new(origin: PyTypeRef, args: PyObjectRef, vm: &VirtualMachine) -> Self {
5858
let args: PyTupleRef = if let Ok(tuple) = PyTupleRef::try_from_object(vm, args.clone()) {
@@ -169,6 +169,17 @@ impl Hashable for PyGenericAlias {
169169
}
170170
}
171171

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+
172183
pub fn init(context: &PyContext) {
173184
let generic_alias_type = &context.types.generic_alias_type;
174185
PyGenericAlias::extend_class(context, generic_alias_type);

0 commit comments

Comments
 (0)