Python 3.5 type hinting does not result in an error

前端 未结 2 1559
无人共我
无人共我 2020-12-20 16:16

One of the new features in python 3.5 is type hinting inspired from this project.

typing: PEP 484 – Type Hints.

I want to test

2条回答
  •  星月不相逢
    2020-12-20 17:17

    In order to get static checks, consider a project like mypy, on which PEP 484 was based on.

    No checking will be performed on runtime is explicitly declared in the PEP to ease fears of some transition to a static looking Python.


    As Daniel pointed out, you can view the attributes in the __annotations__ attribute in a form of:

    {'return': bool}
    

    for function overdrawn().

    If you want you can create your own small type checking function to perform little runtime checks utilizing this dict. Play around with it. Additionally, if you're up for the read, take a look at my answer on type hints here.

提交回复
热议问题