Python 3 type check not works with use typing module?

后端 未结 5 1170
时光取名叫无心
时光取名叫无心 2021-01-13 11:19

Why does type checking not work in Python 3?

I have done the following code with type checks or hints:

import typing

def hello(message: str):
    pr         


        
5条回答
  •  醉酒成梦
    2021-01-13 11:42

    Python 3 doesn't have the kind of type checking you're looking for.

    def hello(message: str):
    

    This is a function annotation.

    https://www.python.org/dev/peps/pep-3107/

    All it does is associate a bit of extra data with the function object. This can be inspected later on the func_annotations attribute of the function.

    It has no built-in behavior beyond this. The intent is for third-parties to build behavior on top of this.

提交回复
热议问题