Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.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 ourterms of service andprivacy 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?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
@@ -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 pulledloc
out of kwargs only for the stub; the method signature still does not contain it and handles it viakwargs
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 typedkwargs
, I think.
Uh oh!
There was an error while loading.Please reload this page.
Instead of accepting any str, we only accept as set of predefinedliterals. For simplicity, we don't distinguish the between allowedpositions for Axes legend and figure legend. It's still better to limitthe allowed range to the union of both rather than to accept abitrarystrings.
Uh oh!
There was an error while loading.Please reload this page.
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.