diff --git a/src/sage/combinat/free_module.py b/src/sage/combinat/free_module.py index 639cec54ae4..fc8800ef830 100644 --- a/src/sage/combinat/free_module.py +++ b/src/sage/combinat/free_module.py @@ -1776,6 +1776,25 @@ class CombinatorialFreeModule_CartesianProduct(CombinatorialFreeModule): sage: S = cartesian_product([cartesian_product([F, G]), H]) # todo: not implemented F (+) G (+) H """ + @staticmethod + def __classcall_private__(cls, modules, category, **options): + """ + Dispatch to the appropriate class based on the input. + + EXMAPLES:: + + sage: Q = RootSystem(['A',3]).root_space(GF(3)) + sage: W = WeylGroup(['A',3], prefix='s') + sage: CP = cartesian_product([Q, W]) + sage: type(CP) + + """ + R = modules[0].base_ring() + Cat = ModulesWithBasis(R) + if any(module not in Cat for module in modules): + from sage.sets.cartesian_product import CartesianProduct + return CartesianProduct(modules, category, **options) + return super().__classcall__(cls, modules, category=category, **options) def __init__(self, modules, **options): r""" @@ -1787,9 +1806,9 @@ def __init__(self, modules, **options): Free module generated by {2, 4, 5} over Integer Ring (+) Free module generated by {2, 4, 7} over Integer Ring sage: TestSuite(C).run() """ - assert (len(modules)) # TODO: generalize to a family or tuple + assert len(modules) # TODO: generalize to a family or tuple R = modules[0].base_ring() - assert (all(module in ModulesWithBasis(R)) for module in modules) + assert all(module in ModulesWithBasis(R) for module in modules) # should check the base ring self._sets = modules CombinatorialFreeModule.__init__(self, R,