OK, I see how this works. This routine is constructing a Poly so the degree method can be used. If the expression is a number, then making the Poly fails. By taking control here of returning a value you are modifying how Poly works and I don't know enough about how it *should* work to know whether your change is correct or not. For example `degree(sqrt(3))` gives 1 because the generator supplied during polification is `sqrt(3)`. Your changes would change that and return a 0. I think the best thing to do is *in the face of ambiguity, refuse the temptation to guess* and always raise an error if no generators are given. The next best thing might be to only single out Integers. The changes would then be only the following:

```
if not gens:
    try:
        from sympy.core.compatibility import as_int  # import at top
        f = f if isinstance(f, Integer) else as_int(f)
        return degree(f, Dummy())
    except ValueError:
        pass
```