-
-
Notifications
You must be signed in to change notification settings - Fork 74
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
Overriding the name
Parameter is taken into account at the class and instance level
#740
Conversation
I'm very much in support of allowing changes to the name parameter, but I wonder if there is a simpler way now that we have Undefined available. Can we make the name lookup bottom out in something that references the auto-generated name, and otherwise allow the user-specified name to be used (as it won't bottom out in that case)? I may not be understanding all the details involved, of course. |
I've always found the special behavior of the name parameter surprising and I think I like the approach used in this PR. If anything, I would like the default |
I remember that when I implemented this I tried an approach in this vain, and had to give up (which doesn't mean it's not possible!). Line 2751 in aa484c4
And every instance of a Parameterized class gets by default a unique |
I would also like Parameterized classes not to have a default |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's get this merged! The __renamed
attribute is a little bit unfortunate but I don't see a better way.
Fixes #644
Overriding the
name
String Parameter was possible at the class level but it actually had no effect. This PR changes that so it is taken into account. This is the new behavior:Overriding is only allowed when
name
is set to be aString
Parameter, as this is something thatParam
relies on internally for other things. A Parameterized class and its instances will have itsname
overriden if thedefault
value of thename
String Parameter is set to something that is notNone
or not an empty string.I used this branch to run the test suites of Panel and HoloViews (both somewhat partially as I don't have all the dependencies installed locally), which helped me to refine it, as there are indeed a few cases of
name
being overriden by both Panel and HoloViews.Parameterized
, whose value is set toTrue
when that particular class overrides the value ofname
. I am not particularly happy with adding new attributes, even if internal, toParameterized
as there is still a chance they will interact with some user defined attribute. However, I played around with some different implementation and this is the only one I found that worked. I would like this variable name to be as "hidden" as possible, I have called it__renamed
so that it's mangled, and it happens I can always retrieve it later on the class via the attribute name'_ParameterizedMetaclass__renamed'
. I don't find that particularly simple to understand and clean, even if I think it does a pretty good job at making the attribute internal and pretty safe from a user perspective. I'm open to better ideas on naming this internal attribute!To the reviewers. I suggest to have a close look at the tests that have been added and capture the new behavior. Notably a test I added just before opening this PR on main needed to be updated (
test_name_instance_generated_class_name_reset
).