@
monetto 虽然手边没有 pycharme, 但是我猜它的 suppress warning type hint 是这样实现的
https://www.python.org/dev/peps/pep-0484Compatibility with other uses of function annotations
A number of existing or potential use cases for function annotations exist, which are incompatible with type hinting. These may confuse a static type checker. However, since type hinting annotations have no runtime behavior (other than evaluation of the annotation expression and storing annotations in the __annotations__ attribute of the function object), this does not make the program incorrect -- it just may cause a type checker to emit spurious warnings or errors.
To mark portions of the program that should not be covered by type hinting, you can use one or more of the following:
a # type: ignore comment;
a @
no_type_check decorator on a class or function;
a custom class or function decorator marked with @
no_type_check_decorator.
For more details see later sections.
In order for maximal compatibility with offline type checking it may eventually be a good idea to change interfaces that rely on annotations to switch to a different mechanism, for example a decorator. In Python 3.5 there is no pressure to do this, however. See also the longer discussion under Rejected alternatives below.