source icon indicating copy to clipboard operation
source copied to clipboard

Add __repr__ to function classes

Open CnlPepper opened this issue 6 years ago • 1 comments

It is currently hard to debug errors in the function classes when they get heavily layered. It would be helpful to show the chain of the functions in the repr:

f = Exp1D(Constant1D(92.1) * Interpolate(x) / Constant1D(2.3)**Gain(x)))

displays as e.g.:

f = e^(92.1 * Interpolate(x) / 2.3**Gain(x))

It may also be useful for users to override the name of classes such as Interpolate, to make the data they are interpolating visible to the user:

f = e^(92.1 * LightIntensity(x) / 2.3**Gain(x))

CnlPepper avatar Oct 16 '19 23:10 CnlPepper

+1 for this, though I would vote for __repr__ looking like your first code block, and having an additional __str__ for your second block. Then you could directly copy and paste the repr into a terminal to reproduce the object, which may also be useful for debugging.

This would mean the special arithmetic method functions (for __add__, __sub__ etc) would have identical __str__ and __repr__ representations, but more special cases such as the cmath functions, interpolators and Arg and Constant would need both methods.

jacklovell avatar Nov 14 '19 17:11 jacklovell