1

I put these on the top of a module:

# mypy: disable-error-code=misc
# mypy: disable-error-code=attr-defined

but only the last line is honoured, the first one is ignored. The same with reversed order or with three lines. In each case all lines except the last one are ignored. I was also trying to aggregate it into one line but failed.

What is the correct syntax to suppress multiple mypy errors in the whole module?

VPfB
  • 14,927
  • 6
  • 41
  • 75
  • I'm not sure,but could you try with comma? `# mypy: disable-error-code=misc,attr-defined` – STerliakov Feb 19 '23 at 11:58
  • @SUTerliakov I tried with a comma, with a space and many other variations. Can't find any documentation regarding the syntax. I put the lines there because `mypy` itself told me so: `type ignore with error code is not supported for modules; use '# mypy: disable-error-code=...'` – VPfB Feb 19 '23 at 14:27
  • 1
    `# mypy: disable-error-code="operator,attr-defined"` finally worked for me (comma and quotes). Also, are you sure you need to disable the code for the whole file? – STerliakov Feb 19 '23 at 16:21
  • Please open a documentation issue on [`mypy` issue tracker](https://github.com/python/mypy), and feel free to submit the PR explaining the syntax - this seems to be really not documented sufficiently. – STerliakov Feb 19 '23 at 16:22
  • @SUTerliakov Thank you, it really works, please consider writing that as an answer. The reason I want to disable both is that I'm defining "add-on" classes in that file to a "main" class defined elsewhere. The "add-ons" are not usable standalone. They frequently access methods and attributes from the main class and mypy cannot know that. – VPfB Feb 19 '23 at 16:46
  • If you're talking about mixins, consider defining main class protocol and inheriting mixins from it - it may help reveal subtle bugs. – STerliakov Feb 19 '23 at 18:48
  • @SUTerliakov Could you please add some link(s) where I could learn more about that mixins stuff? Thanks. – VPfB Feb 20 '23 at 10:54
  • For mixins typing, have a look at this question: https://stackoverflow.com/questions/51930339/how-do-i-correctly-add-type-hints-to-mixin-classes. For mixins as a concept - probably this one: https://stackoverflow.com/questions/533631/what-is-a-mixin-and-why-is-it-useful – STerliakov Feb 20 '23 at 21:35

0 Answers0