Typing: TypeNames is too dynamic

Having a look at the output of mypy src/sardana in the !1924 (merged) branch, it's clear that one thing is causing the majority of the errors:

$ grep -c TypeNames mypy.txt 
733

This accounts for 733 of the 1128 current errors. These errors all are on the same form, e.g.:

src/sardana/macroserver/macros/lists.py:261: error: "TypeNames" has no attribute "Controller"  [attr-defined]

It appears that TypeNames contains the types used for defining macro arguments, e.g. "Movable", etc.

Looking in the definition of TypeNames this is just some kind of registry, where "types" are then registered here. This means the "type" attributes on this object are defined at runtime, and it's clearly a problem for mypy as there's no way to know what attribute exist in advance.

However, lots of places in the codebase assume that various types are defined anyway (as the 733 errors above testify). As far as I can tell that means there is little point to defining things in this dynamic way, it's just confusing. I don't know if the idea is that user code can register new types, but I think we should consider refactoring this so that the standard sardana types are statically defined. The stuff going on in basetypes.py, creating classes dynamically from a bunch of definitions seems overcomplicated, when the classes could just be defined directly, but I could be missing something. Perhaps it's from older python days?

As far as I can tell the attributes just contain the name of the type so Type.Motor could be replaced with "Motor" and mypy will stop complaining. However that wouldn't gain us much else in terms of static typing 😄

Not an urgent issue by any means, just something to consider. But I do think if we're going to get good mileage out of typing annotations there will have to be some refactoring of the internals. And it could be seen as an opportunity!