Skip to content

Tag: mypy

Annotate dataclass class variable with type value

We have a number of dataclasses representing various results with common ancestor Result. Each result then provides its data using its own subclass of ResultData. But we have trouble to annotate the case properly. We came up with following solution: but it stopped working lately with mypy error ClassVar canno…

mypy error on same line regardless of code content

I’m getting a mypy syntax error on line 36 in every single one of my files. If the file is shorter than 36 lines it just highlights the last line. The error is invariably the same: invalid syntax mypy(error) Apparently this issue may have happened before, but without a clear solution. Is this a known bu…

Mypy: incompatible type error during set update

Mypy returns an error if the set is updated with new tuple using add() code.py error body As far as I know, it is common practice to add new tuplets to the set. The add() method can add a tuple object as an element in the set Why does mypy think it’s not allowed? Answer adgroups_by_campaign_id is marked…

Type hint for return value in subclass

I am writing a CustomEnum class in which I want to add some helper methods, that would then be available by the classes subclassing my CustomEnum. One of the methods is to return a random enum value, and this is where I am stuck. The function works as expected, but on the type-hinting side, I cannot figure ou…