Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 7 commits into from May 23, 2023

Conversation

maximlt
Copy link
Member

@maximlt maximlt commented Apr 5, 2023

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
Copy link
Member Author

maximlt commented Apr 12, 2023

Oh wait, need to resolve conflicts...

@Hoxbro
Copy link
Member

Hoxbro commented May 1, 2023

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
Copy link
Member Author

maximlt commented May 1, 2023

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
Copy link
Member

Hoxbro commented May 1, 2023

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

@maximlt
Copy link
Member Author

maximlt commented May 1, 2023

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
Copy link
Member

Hoxbro commented May 1, 2023

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

I agree.

@maximlt
Copy link
Member Author

maximlt commented May 1, 2023

The error message now mirrors Python more closely.

Pure Python:
image

Param on this branch:
image

@Hoxbro
Copy link
Member

Hoxbro commented May 2, 2023

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.

Copy link
Member

@jbednar jbednar left a comment

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
Copy link
Member Author

maximlt commented May 23, 2023

Great thanks! Merging.

@maximlt maximlt merged commit 7ef9e22 into main May 23, 2023
10 checks passed
@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