We could easily de-structure and assign variables using Python's builtin classes like list or tuples as seen below.
a, b = 1, 2
However, in cases where we do not wish to inherit those classes, and want our container to have a similar behaviour as seen in the snippet below, how would we do so? Is there a magic method?
class MyClass:
...
instance = MyClass()
# assuming there are some properties in the class for this
a, b = instance
An example that comes to mind would be dataclasses (although we could already do it with NamedTuple)
from dataclasses import dataclass
@dataclass
class MyClass:
name: str
age: int
instance = MyClass("John", 10)
name, age = instance