I recently started using dataclasses and they will be a nice addition to 3.7. I'm curious if or how it is possible to recreate the same functionality of this class using dataclasses.
class Nav(object):
def __init__(self, name:str, menu, page, *submenus):
self.name = name
self.menu = menu
self.page = page
self.submenus = submenus
foo = Nav("name", "menu", "page")
This doesn't work. Raises Exception TypeError: __init__() missing 1 required positional argument: 'submenus'
@dataclass
class Nav(object):
name:str
menu: Any
page: Any
submenus: tuple
foo = Nav("name", "menu", "page")
I assume this is because the class doesn't have the instructions to do the unpacking of the arguments. Is there some way to instruct the dataclass decorator that submenus needs to be unpacked?
Iterable
instead. I'd use that instead ofList
too.