mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
Merge pull request #4035 from TwoPair/union-parameters
Fix making union parameters
This commit is contained in:
2 files changed
+6
-19
No files matched your search
Vendored
-2
@@ -815,8 +815,6 @@ class UnionTests(unittest.TestCase):
|
||||
check(x | None, (x, type(None)))
|
||||
check(None | x, (type(None), x))
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
def test_union_parameter_chaining(self):
|
||||
T = typing.TypeVar("T")
|
||||
S = typing.TypeVar("S")
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use super::{genericalias, type_};
|
||||
use crate::{
|
||||
builtins::{PyFrozenSet, PyStr, PyStrRef, PyTuple, PyTupleRef, PyType, PyTypeRef},
|
||||
builtins::{PyFrozenSet, PyStr, PyStrRef, PyTuple, PyTupleRef, PyType},
|
||||
class::PyClassImpl,
|
||||
common::hash,
|
||||
convert::ToPyObject,
|
||||
@@ -163,7 +163,7 @@ fn make_parameters(args: &PyTupleRef, vm: &VirtualMachine) -> PyTupleRef {
|
||||
}
|
||||
parameters.shrink_to_fit();
|
||||
|
||||
PyTuple::new_ref(parameters, &vm.ctx)
|
||||
dedup_and_flatten_args(PyTuple::new_ref(parameters, &vm.ctx), vm)
|
||||
}
|
||||
|
||||
fn flatten_args(args: PyTupleRef, vm: &VirtualMachine) -> PyTupleRef {
|
||||
@@ -196,21 +196,10 @@ fn dedup_and_flatten_args(args: PyTupleRef, vm: &VirtualMachine) -> PyTupleRef {
|
||||
let mut new_args: Vec<PyObjectRef> = Vec::with_capacity(args.len());
|
||||
for arg in &args {
|
||||
if !new_args.iter().any(|param| {
|
||||
match (
|
||||
PyTypeRef::try_from_object(vm, param.clone()),
|
||||
PyTypeRef::try_from_object(vm, arg.clone()),
|
||||
) {
|
||||
(Ok(a), Ok(b))
|
||||
if a.is(vm.ctx.types.generic_alias_type)
|
||||
&& b.is(vm.ctx.types.generic_alias_type) =>
|
||||
{
|
||||
param
|
||||
.rich_compare_bool(arg, PyComparisonOp::Eq, vm)
|
||||
.ok()
|
||||
.unwrap()
|
||||
}
|
||||
_ => param.is(arg),
|
||||
}
|
||||
param
|
||||
.rich_compare_bool(arg, PyComparisonOp::Eq, vm)
|
||||
.ok()
|
||||
.unwrap()
|
||||
}) {
|
||||
new_args.push(arg.clone());
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user