Note that the demo you are considering is quite outdated, and your should consider the latest version
To estimate the polynomial degree, you can use:
from ufl.algorithms.compute_form_data \
import estimate_total_polynomial_degree
estimate_total_polynomial_degree(form)