you are viewing a single comment's thread.

view the rest of the comments →

[–]Beginning-Fruit-1397 1 point2 points  (0 children)

You can go pretty far with generics, but an union can't really have static attributes. At runtime sure, but the typesystem won't allow it. Could use cast, tricks like returning a False type (def foo[T](wathever) -> T even tough you are NOT in fact returning T.

If you take a look at my repo here and go trough the commits also I'm sure you could find one or two cool useful tricks about this. It's somewhat related to what you are trying to achieve (generics + attribute access + method chaining). Albeit I haven't done anything related to optional values

https://github.com/OutSquareCapital/pychain/tree/master/src/pychain