# type: a

Chris Warrick kwpolska at gmail.com
Sun Sep 15 11:22:32 EDT 2019


On Sun, 15 Sep 2019 at 16:53, Hongyi Zhao <hongyi.zhao at gmail.com> wrote:
>
> Hi,
>
> In pycharm, when I commented out the following line:
>
> # type: a
>
> The pycharm still told me that:
>
> Unresolved reference 'a'

PyCharm interprets PEP 484 type annotations and type comments, as well
as PEP 526 variable annotations. The comment you wrote is a type
comment that says 'a' is the expected type of something. The 'type:'
part is special here, `# foo: a` won’t trigger this warning. PyCharm
expects stuff in type comments to exist, because otherwise, there’s no
way to know what type you mean.

Type comments are now best replaced by Python 3.6+ variable
annotations, but the comments are still valid, and can be used in some
contexts where annotations are not supported.

https://www.python.org/dev/peps/pep-0484/#type-comments

-- 
Chris Warrick <https://chriswarrick.com/>
PGP: 5EAAEA16



More information about the Python-list mailing list