How can mypy ignore a single line in a source file?

后端 未结 3 604
故里飘歌
故里飘歌 2021-02-04 23:28

I\'m using mypy in my python project for type checking. I\'m also using PyYAML for reading and writing the project configuration files. Unfortunately, when using the recommended

相关标签:
3条回答
  • 2021-02-04 23:39

    I would rather config it in mypy.ini

    For example, to ignore Django migrations:

    [mypy-*.migrations.*]
    ignore_errors = True
    
    0 讨论(0)
  • 2021-02-04 23:44

    You can ignore type errors with # type: ignore as of version 0.2 (see issue #500, Ignore specific lines):

    PEP 484 uses # type: ignore for ignoring type errors on particular lines ...

    Also, using # type: ignore close to the top of a file [skips] checking that file altogether.

    Source: mypy#500

    0 讨论(0)
  • 2021-02-04 23:55

    Also # mypy: ignore-errors at the top of the file you want to ignore all works, if you are using shebang and coding lines should be like this:

    #!/usr/bin/env python 
    #-*- coding: utf-8 -*-
    # mypy: ignore-errors
    

    Gvanrossum comment

    0 讨论(0)
提交回复
热议问题