Skip to content

cleder/type-ignore

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

type-ignore

Add # type: ignore [error_code] and remove unused #type: ignores

When you refactor code to use type annotations you cannot fix every violations at once you can add # type: ignore [error-code] comments to let mypy pass. When you further refine your annotations some of these lines may become valid and the # type: ignore comments have to be removed. With type-ignore it is possible to automate this process.

Usage

Either pipe the output of mypy directly into type-ignore

mypy type_ignore | type-ignore remove --dry-run

or you can use a file to read the error information from

mypy type_ignore > errors.txt
type_ignore add --error-file=mypy_error_report.txt --dry-run

The --dry-run flag lets you see what would be changed without modifying your code. Files are modified in place, it is strongly recommended to git commit before running this tool.

Mypy configuration

Add this to your mypy configuration:

[tool.mypy]
...
warn_unused_ignores = true
show_error_codes = true
enable_error_code = [
    "ignore-without-code"
]

Alternatives

At the time I wrote this I could not find a tool to add and remove type ignore comments, only after I published this on GitHub :octocat: I found out that I reinvented the wheel 🤦️.

  • mypy-silent - Automatically add or remove # type: ignore comments to silence mypy. Inspired by pylint-silent.
  • mypy_clean_slate - CLI tool for providing a clean slate for mypy usage within a project.

Another tool that tries solve the same problem, but with a different approach and many more features is:

  • mypy-baseline - A CLI tool for painless integration of mypy with an existing Python project. When you run it for the first time, it will remember all type errors that you already have in the project (generate "baseline"). All consecutive runs will ignore these errors and report only ones that you introduced after that.

Check out the Awesome Python Typing Awesome list.

About

A tool to add # type: ignore [error_code] and remove unused #type: ignore

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages