|
1 | 1 | use super::{genericalias, type_};
|
| 2 | +use crate::class::StaticType; |
2 | 3 | use crate::{
|
3 | 4 | AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine,
|
4 | 5 | atomic_func,
|
5 | 6 | builtins::{PyFrozenSet, PyStr, PyTuple, PyTupleRef, PyType},
|
6 | 7 | class::PyClassImpl,
|
7 | 8 | common::hash,
|
8 |
| - convert::{ToPyObject, ToPyResult}, |
| 9 | + convert::ToPyObject, |
9 | 10 | function::PyComparisonValue,
|
10 | 11 | protocol::{PyMappingMethods, PyNumberMethods},
|
11 | 12 | types::{AsMapping, AsNumber, Comparable, GetAttr, Hashable, PyComparisonOp, Representable},
|
@@ -135,6 +136,9 @@ pub fn is_unionable(obj: PyObjectRef, vm: &VirtualMachine) -> bool {
|
135 | 136 | obj.class().is(vm.ctx.types.none_type)
|
136 | 137 | || obj.payload_if_subclass::<PyType>(vm).is_some()
|
137 | 138 | || obj.class().is(vm.ctx.types.generic_alias_type)
|
| 139 | + || obj |
| 140 | + .class() |
| 141 | + .is(crate::stdlib::typing::_typing::TypeAliasType::static_type()) |
138 | 142 | || obj.class().is(vm.ctx.types.union_type)
|
139 | 143 | }
|
140 | 144 |
|
@@ -229,13 +233,14 @@ impl AsMapping for PyUnion {
|
229 | 233 | }
|
230 | 234 | }
|
231 | 235 |
|
| 236 | +pub static UNION_OR: PyNumberMethods = PyNumberMethods { |
| 237 | + or: Some(|a, b, vm| Ok(type_::or_(a.to_pyobject(vm), b.to_pyobject(vm), vm))), |
| 238 | + ..PyNumberMethods::NOT_IMPLEMENTED |
| 239 | +}; |
| 240 | + |
232 | 241 | impl AsNumber for PyUnion {
|
233 | 242 | fn as_number() -> &'static PyNumberMethods {
|
234 |
| - static AS_NUMBER: PyNumberMethods = PyNumberMethods { |
235 |
| - or: Some(|a, b, vm| PyUnion::or(a.to_owned(), b.to_owned(), vm).to_pyresult(vm)), |
236 |
| - ..PyNumberMethods::NOT_IMPLEMENTED |
237 |
| - }; |
238 |
| - &AS_NUMBER |
| 243 | + &UNION_OR |
239 | 244 | }
|
240 | 245 | }
|
241 | 246 |
|
|
0 commit comments