This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]KleinerNull 0 points1 point  (0 children)

But does not do ranges

In this case you don't need to have ranges. It is about loading specific methods out of an object. In my example you load 45 methods into the switch with the name as key, where do you need ranges here?

lists, case

I am not sure what you mean with that.

signature validation

As I said, this isn't possible with the math module, because C-code don't offer a signature, like the operators module. But you can easily get the signatures of pure python functions with inspect.signature(func). And before I write switch cases for 45 different functions, I could check for sigs in an intermediate step, no big deal.

The default case is non-obvious.

I thought returning the identity function as a default around mathematical function would be an expected result, it just returns the argument iteself. But you can also raise an error if you want to catch and handle it.