How can I type-check variables in Python?

后端 未结 9 1617
南旧
南旧 2020-12-15 03:59

I have a Python function that takes a numeric argument that must be an integer in order for it behave correctly. What is the preferred way of verifying this

9条回答
  •  太阳男子
    2020-12-15 04:34

    Don't type check. The whole point of duck typing is that you shouldn't have to. For instance, what if someone did something like this:

    class MyInt(int):
        # ... extra stuff ...
    

提交回复
热议问题