-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
ENH: Type the possible str legend locs as Literals #29465
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
base: main
Are you sure you want to change the base?
Conversation
f608a46
to
92eba37
Compare
@@ -60,13 +60,16 @@ class Axes(_AxesBase): | ||
@overload | ||
def legend(self) -> Legend: ... | ||
@overload | ||
def legend(self, handles: Iterable[Artist | tuple[Artist, ...]], labels: Iterable[str], **kwargs) -> Legend: ... | ||
def legend(self, handles: Iterable[Artist | tuple[Artist, ...]], labels: Iterable[str], | ||
*, loc: LegendLocType | None = ..., **kwargs) -> Legend: ... |
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.
I hope this works. I've pulled loc
out of kwargs only for the stub; the method signature still does not contain it and handles it via kwargs
instead. At least mypy doesn't complain, but I don't understand typing well enough whether that's guaranteed to work.
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.
It should be fine since we haven't typed kwargs
, I think.
Instead of accepting any str, we only accept as set of predefined literals. For simplicity, we don't distinguish the between allowed positions for Axes legend and figure legend. It's still better to limit the allowed range to the union of both rather than to accept abitrary strings.
92eba37
to
631e38f
Compare
Instead of accepting any str, we only accept as set of predefined literals. For simplicity, we don't distinguish the between allowed positions for Axes legend and figure legend. It's still better to limit the allowed range to the union of both rather than to accept abitrary strings.
This is a bit cumbersome, but since loc names are hard to remember and easy to misspell, I believe it's a real benefit if in-editor type checkers could notify on an invalid loc name.