mypy, type hint: Union[float, int] -> is there a Number type?

后端 未结 3 1843
醉酒成梦
醉酒成梦 2021-02-01 12:28

mypy is really handy and catches a lot of bugs, but when I write \"scientific\" applications, I often end up doing:

def my_func(number: Union[float, int]):
    #         


        
3条回答
  •  春和景丽
    2021-02-01 13:21

    You can define your own type to address this and keep your code cleaner.

    FloatInt = Union[float, int]
    
    def my_func(number: FloatInt):
        # Do something
    

提交回复
热议问题