Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Creation of the Norm Protocol#30149
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Conversation
lib/matplotlib/colors.pyi Outdated
class Norm(Protocol): | ||
callbacks: cbook.CallbackRegistry | ||
@property | ||
def vmin(self) -> float | None: ... |
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.
Wouldn't we need something like this to support MultiNorm?
defvmin(self)->float|None: ... | |
defvmin(self)->float|ArrayLike|None: ... |
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.
Yes,
My logic was to get this into main first, and then change this with the MultiNorm PR, but I guess it is easier if I do it here. I will try to find the time early next week.
Is this PR otherwise as you would expect?
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.
This should be updated now, I set it to:
@propertydefvmin(self)->float|tuple[float]|None: ...@propertydefvmax(self)->float|tuple[float]|None: ...@propertydefclip(self)->bool|tuple[bool]: ...
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Considering this again, I'm leaning slightly towards an abstract base class. To be clear, both variants are acceptable solutions for the use case and would do the job. The relevant arguments for me are:
Since I missed the discussion: What were the reasons to suggest unsung Protocols? |
The main reasoning to avoid ABCs was to avoid having to deal with metaclasses, since that is often more painful than helpful. Protocols get us to essentially the same place without having to worry about that aspect. |
@trygvrad Thanks for taking the effort to write out both alternatives! I still like the ABC approach a bit more. Could you please add @ksunden I think ABC is much simpler than a generic metaclass. The only complication I see is that one would have to watch out in case of multiple inheritance - But I don't see a case where norms would need multiple inheritance. They are quite straight forward. |
@timhoffm I'm not able to work on this now, but I will try to get to it at the end of the week. @tacaswell If i recall you had a preference for a Protocol at the weekly meeting. What is your opinion now, in light of@timhoffm arguments here#30149 (comment) ? |
Closing in favor of#30178 (see#30178 (comment)) Thank you@trygvrad for working up both versions! |
This PR is a response to a discussion in the past weeks weekly developer meeting regarding the creation of a Norm protocol before the introduction of MultiNorm#29876 (comment)
Prior to this PR there are no Protocols in matplotlib.
This implementation uses
@runtime_checkable
so thatColorizer.set_norm()
can check_api.check_isinstance((colors.Norm, str, None), norm=norm)
Note that the error message if the class one attempts to use is missing a member, is just the standard wrong-type message, and does not tell you what member of the protocol is missing.
@timhoffm@tacaswell@ksunden@story645
The implementation looks like this:
and some of the docstrings will need to be updated to also allow for MultiNorm, but this can happen in the next PR.
This requires a lot more than the bare minimum. I tested, and I can do a
plt.imshow()
with just__call__
andautoscale_None
, but I get the feeling that it is desirable to lock it down more.