Basically I have a Base class and a metaclass and a ton of classes that use both
I want to avoid doing class Name(Base, metaclass=Meta) over and over again and instead do this
@deco
class Name:
I already have a decorator like this:
def deco(cls):
return Meta(cls.__name__, (Base, cls), dict(vars(cls)))
and it works, the problem is that its erasing the identity of the original class, for example:
when hovering over a variable of that class, vscode says its a
_class_Metaobject and not aNameobjectprint(Name().__doc__)works as expected but hovering over said objects doesn't show any docstringfunctions and variables of the
Nameand theBaseclasses are not even recognized by vscode at all, only attributes of the metaclass
Im basically looking for something like the functools.wraps decorator
Why this is happening and why you shouldn't do this in the first place:
You are getting no docstrings from vscode since this is quite hacky and thus vscode doesn't understand it, because it's very unpythonic, so it can't show you corect tooltips.
Always remember:
Explicit is better than implicit.- The Zen of Python (read it yourself:import this). And it's not even worth it, it just makes your code more complex and less readable/understandable, and yes, even for yourself.