I have a Python function that looks like this
def my_function() -> Any:
from optional_dependency import SomeClass
# This will fail if `optional_dependency` is not installed, I'm good with that.
return SomeClass()
I’m not a huge fan of this function, but I’ve inherited it and I can’t break it (just yet). I wonder if there is a better return type than Any
.
Pyright complains whether I write
-> SomeClass
-> "SomeClass"
And Ruff complains if I write
-> "SomeClass": # type: ignore
Is there anything that can keep both Pyright and Ruff (and ideally mypy) happy?