Mypy: Flag for only allowing PEP 526 type annotations

Created on 3 Jun 2018  路  3Comments  路  Source: python/mypy

Hello, in a given codebase I wanted to only allow PEP 526 type annotations. I'm currently linting for it with this pre-commit hook:

- repo: local
  hooks:
  - id: use-type-annotations
    name: type annotations not comments
    entry: '# type.*(?<!: ignore)$'
    language: pygrep
    types: [python]

The advantage (for me) is the code is more standardized and lines are slightly shorter, however with the trade-off that you can't wrap typing imports in if TYPE_CHECKING. I was wondering what mypy maintainers think of a flag to achieve what the lint configuration is doing? (I couldn't find past discussion on this 馃槄)

feature needs discussion

Most helpful comment

I personally don't think this is worth it. Mypy already has a lot of flags, so I'd want to avoid making it even more complicated. And it's already easy to find # type: with a simple grep, so we wouldn't be adding that much value.

All 3 comments

I personally don't think this is worth it. Mypy already has a lot of flags, so I'd want to avoid making it even more complicated. And it's already easy to find # type: with a simple grep, so we wouldn't be adding that much value.

I think we can leave this for a day or two, but unless someone has a compelling argument why mypy should support this, I think we can agree it isn't worth it and close this.

Thanks for the context!

Was this page helpful?
0 / 5 - 0 ratings