Skip to content

Don't set class attributes during initialization and don't warn when setting non-Param class attributes - #729

Merged
maximlt merged 7 commits into
mainfrom
class_attrs_handling
May 23, 2023
Merged

maximlt merged 7 commits into
mainfrom
class_attrs_handling

Conversation

@maximlt

@maximlt maximlt commented Apr 5, 2023

Copy link
Copy Markdown
Member

Fixes #174

  • Setting a non-Parameter class attribute no longer raises a warning
  • Setting a non-Parameter in the constructor raises a TypeError (breaking change)

image

@maximlt
maximlt requested a review from jlstevens April 12, 2023 15:51
@maximlt

maximlt commented Apr 12, 2023

Copy link
Copy Markdown
Member Author

Oh wait, need to resolve conflicts...

@hoxbro

hoxbro commented May 1, 2023

Copy link
Copy Markdown
Member

Is TypeError the best type of error to raise? Maybe AttributeError? I could be wrong, though, or there could be an even better error.

@maximlt

maximlt commented May 1, 2023

Copy link
Copy Markdown
Member Author

TypeError is the error raised by Python when you pass a non expected keyword argument in a function call. That's why I chose it.

image

Do you have suggestions for a better error?

@hoxbro

hoxbro commented May 1, 2023

Copy link
Copy Markdown
Member

Maybe a custom one? That sets it apart from normal Python behavior? ParametrizedError

@maximlt

maximlt commented May 1, 2023

Copy link
Copy Markdown
Member Author

It seems to be this is a general Python behavior, you shouldn't be able to pass kwargs to a callable that don't expect them. I don't really see a reason to raise a different error here. One could actually argue that Param should raise the exact same error message.

image

@hoxbro

hoxbro commented May 1, 2023

Copy link
Copy Markdown
Member

One could actually argue that Param should raise the exact same error message.

I agree.

@maximlt

maximlt commented May 1, 2023

Copy link
Copy Markdown
Member Author

The error message now mirrors Python more closely.

Pure Python:
image

Param on this branch:
image

@hoxbro

hoxbro commented May 2, 2023

Copy link
Copy Markdown
Member

I like it. I just ran this PR across the holoviz ecosystem and got two failing tests related to this change:

FAILED panel/tests/pane/test_holoviews.py::test_holoviews_with_widgets_not_shown - TypeError: HoloViews.__init__() got an unexpected keyword argument 'show_widgets'
---
FAILED hvplot/tests/testinteractive.py::test_interactive_pandas_frame_bind_operator_out_widgets - TypeError: Select.__init__() got an unexpected keyword argument 'default'

This does not necessarily mean these changes are wrong, but some tests need to be updated.

@jbednar jbednar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is the correct change, thanks!

@maximlt

maximlt commented May 23, 2023

Copy link
Copy Markdown
Member Author

Great thanks! Merging.

@maximlt
maximlt merged commit 7ef9e22 into main May 23, 2023
@maximlt
maximlt deleted the class_attrs_handling branch May 23, 2023 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stop setting class attributes during initialization

3 participants