'FunctionSpace' object has no attribute 'super'

Hello,

I am having trouble with a fairly simple task. I want to create a Function based of a mixed element space.
I found a few examples for that, but for some reason all of them result in the same error and I can’t see where I made a mistake. Below is the code that produces the error

import numpy as np
from ufl import *
import dolfinx
from dolfinx import mesh, fem, io, plot
from dolfinx.fem.petsc import LinearProblem
from dolfinx.nls.petsc import NewtonSolver
from mpi4py import MPI
from petsc4py import PETSc

domain = mesh.create_rectangle(MPI.COMM_WORLD, [(0.0, 0.0), (10.0, 1.0)],
                          (50,5), mesh.CellType.quadrilateral)
U = VectorElement("Lagrange", domain.ufl_cell(), degree=2)
P = FiniteElement("Lagrange", domain.ufl_cell(), degree=1)
space = FunctionSpace(domain, U*P)

w0 = fem.Function(space)

The error I get is

AttributeError                            Traceback (most recent call last)
/home/vm/fenics/up-fenicsx.ipynb Cell 2 line 1
     13 P = FiniteElement("Lagrange", domain.ufl_cell(), degree=1)
     14 space = FunctionSpace(domain, U*P)
---> 16 w0 = fem.Function(space)

File ~/anaconda3/envs/fenicsx/lib/python3.11/site-packages/dolfinx/fem/function.py:302, in Function.__init__(self, V, x, name, dtype)
    300     self._cpp_object = functiontype(dtype)(V._cpp_object, x._cpp_object)
    301 else:
--> 302     self._cpp_object = functiontype(dtype)(V._cpp_object)
    304 # Initialize the ufl.FunctionSpace
    305 super().__init__(V.ufl_function_space())

AttributeError: 'FunctionSpace' object has no attribute '_cpp_object'

w0 is supposed to store the initial condition for my problem, if that helps. Not sure if this note helps, but I can create Testfunctions and a Trialfunction from space.

If you are using current main branch, the creation of a function space now happens with functionspace rather than FunctionSpace. If you are not using main, please add more details on how you installed dolfinx.

I’ll leave the answer there in case other people come to this topic in future, but after reading again the code I suspect that the issue is different.

You are using FunctionSpace from ufl. Instead you should be using functionspace (preferred non-deprecated way, if available) or FunctionSpace from dolfinx.fem (or fem, since you imported it from dolfinx).

Changing FunctionSpace to functionspace actually did the trick.
Thank you.