Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Open
timhoffm wants to merge1 commit intomatplotlib:main
base:main
Choose a base branch
Loading
fromtimhoffm:type-legend-loc

Conversation

timhoffm
Copy link
Member

@timhoffmtimhoffm commentedJan 12, 2025
edited
Loading

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.

@@ -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: ...
Copy link
MemberAuthor

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.

Copy link
Member

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.

@tacaswelltacaswell added this to thev3.11.0 milestoneJan 17, 2025
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.
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@QuLogicQuLogicQuLogic left review comments

At least 1 approving review is required to merge this pull request.

Assignees
No one assigned
Projects
None yet
Milestone
v3.11.0
Development

Successfully merging this pull request may close these issues.

3 participants
@timhoffm@QuLogic@tacaswell

[8]ページ先頭

©2009-2025 Movatter.jp