Thanks for this. I really had no idea how to get this annotation to work. In hindsight it’s more obvious. I wonder how many other typeshed classes don’t do this for methods that return self.
It was only after seeing the solution that I could find docs describing it on mypy.readthedocs. There is a note claiming that a generic self is still experimental but maybe a convention should be added to the typeshed contributing guide about using it, just like Sequence is recommended over list.