Skip to content
This repository has been archived by the owner on Feb 24, 2021. It is now read-only.

namedtuple and NamedTuple replacement that takes mixins to prefix #20

Closed
mwchase opened this issue Mar 31, 2019 · 6 comments
Closed

namedtuple and NamedTuple replacement that takes mixins to prefix #20

mwchase opened this issue Mar 31, 2019 · 6 comments

Comments

@mwchase
Copy link
Owner

mwchase commented Mar 31, 2019

Or maybe, some kind of helper metaclass that could be applied to mixins intended to go ahead of NamedTuples/namedtuples.

Motivation:

class PendulumStateImpl(typing.NamedTuple):

    theta: np.double = np.double(np.pi / 3)
    theta_dot: np.double = np.double(0)


class PendulumState(ScalableNamedTuple, PendulumStateImpl):
    pass
@mwchase
Copy link
Owner Author

mwchase commented Mar 31, 2019

Piggyback off the existing implementation by actually constructing the namedtuple, but with an empty ns, then subtype it with the actual bases, substituting the namedtuple (require NamedTuple to be at the end of the bases), but forward the

I suddenly remember why I don't usually do this exact kind of thing.

@mwchase
Copy link
Owner Author

mwchase commented Aug 21, 2019

From inspecting Dennis's use of the data keyword, this is top priority.

Current idea is to investigate making a class decorator that generates a new class. Basically, aim to re-implement namedtuples, but using ADT design principles. May end up renaming the adt function to some derivative of "sum", and this can be "product".

@mwchase
Copy link
Owner Author

mwchase commented Aug 25, 2019

Wait, this is just frozen dataclasses, isn't it.

@mwchase
Copy link
Owner Author

mwchase commented Aug 25, 2019

... But, I can hook into the existing destructurers instead of trying to teach it dataclasses.

Current plan is to try making a base class that pulls in the necessary dependencies and does stuff in a __init_subclass__ function. There should be no final-type trickery.

@mwchase
Copy link
Owner Author

mwchase commented Aug 25, 2019

Possibly, sum types should be made to work by the same mechanism.

@mwchase
Copy link
Owner Author

mwchase commented Aug 31, 2019

Untested, but this stuff is in the current master.

@mwchase mwchase closed this as completed Oct 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant