holoviz / param

Param: Make your Python code clearer and more reliable by declaring Parameters
https://param.holoviz.org
BSD 3-Clause "New" or "Revised" License
427 stars 73 forks source link

Improve Parameter error messages #808

Closed maximlt closed 1 year ago

maximlt commented 1 year ago

The error messages raised by Parameters are pretty inconsistent and often lack context.

For now with this PR I'm just seeking feedback on a utility I've added that builds a message supposed to prefix most of (if not all) the errors raised by Parameters. I've just adapted the type validation performed by Number to show the error messages emitted in various situations:

image

(I'd hope to get this into the 2.0 release.)

maximlt commented 1 year ago

@philippjfr this is ready.

jbednar commented 1 year ago

Thanks. Now seems like a good chance to make the error message a bit cleaner. Instead of ", not type <class 'str'>", can it be either ", not <class 'str'>", or ", not type 'str'", (my preference, I think)? I'm a bit confused why it comes out that way right now, as if I do "type('st')" I get "str", not the confusing version.

maximlt commented 1 year ago

Yes that'd be a good idea! I won't have time to take care of that now though.

jbednar commented 1 year ago

Ah, apparently Python only shows the __name__ of the type when used interactively, so it would be f", not '{type(obj).__name__}'" (yielding , not 'str').

philippjfr commented 1 year ago

Personally I find , not 'str' a little weird, the single quotes throw me off.