10000 TYP: Add several missing return type annotations by QuLogic · Pull Request #26451 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

TYP: Add several missing return type annotations #26451

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

Merged
merged 3 commits into from
Aug 7, 2023

Conversation

QuLogic
Copy link
Member
@QuLogic QuLogic commented Aug 4, 2023

PR summary

I'm probably least confident in the backend_bases.pyi types as it's a bit of a complex file.

One that is missing is Affine2DBase.is_separable, because adding the return annotation makes it typed, and then mypy complains that:

lib/matplotlib/transforms.pyi:229: error: Cannot override writeable attribute with read-only property  [override]

PR checklist

@QuLogic QuLogic added this to the v3.8.0 milestone Aug 4, 2023
@QuLogic
Copy link
Member Author
QuLogic commented Aug 4, 2023

Depends on #26450 to fix the subclass method inconsistency.

@ksunden
Copy link
Member
ksunden commented Aug 4, 2023

Cycling to get the mypy runs rebased post merge of #26450

@ksunden ksunden closed this Aug 4, 2023
@ksunden ksunden reopened this Aug 4, 2023
@ksunden
Copy link
Member
ksunden commented Aug 4, 2023

is_separable and a fair number of other things like it fall into the category of things that are really intended to be read-only, but are not wholly implemented as such (but sometimes are?)...

These were problematic for stubtest, in ways that were more trouble than initially worth it, so I ignored the noisy ones:

See

# Property read-write vs read-only weirdness, fix if possible
matplotlib.offsetbox.DraggableBase.canvas
matplotlib.offsetbox.DraggableBase.cids
matplotlib.transforms.BboxTransform.is_separable
matplotlib.transforms.BboxTransformFrom.is_separable
matplotlib.transforms.BboxTransformTo.is_separable
matplotlib.transforms.BlendedAffine2D.is_separable
matplotlib.transforms.CompositeGenericTransform.is_separable
matplotlib.transforms.TransformWrapper.input_dims
matplotlib.transforms.TransformWrapper.is_separable
matplotlib.transforms.TransformWrapper.output_dims

All in all, not a very user-facing (if technically public, and useful in some contexts) set of variables, and setting them would wreak havoc.

@@ -103,9 +103,9 @@ class Text(Artist):
def get_usetex(self) -> bool: ...
def set_parse_math(self, parse_math: bool) -> None: ...
def get_parse_math(self) -> bool: ...
def set_fontname(self, fontname: str | Iterable[str]): ...
def set_fontname(self, fontname: str | Iterable[str]) -> None: ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe should remove the return from the implementation, and maybe call the canonically defined version of set_fontfamily as set_family is not type checkable as an alias.

@@ -63,7 +63,7 @@ class Spine(mpatches.Patch):

class SpinesProxy:
def __init__(self, spine_dict: dict[str, Spine]) -> None: ...
def __getattr__(self, name: str): ...
def __getattr__(self, name: str) -> Callable[[Any], None]: ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def __getattr__(self, name: str) -> Callable[[Any], None]: ...
def __getattr__(self, name: str) -> Callable[[...], None]: ...

May work with Any, but typing docs indicate ... as the "any input signature" syntax

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I originally thought it was only one parameter with any type, as passed to any .set_* method, but now I realize the proxy can be for .set, which allows multiple parameters, so ... is better.

@QuLogic
Copy link
Member Author
QuLogic commented Aug 5, 2023

Fixed all those items, and also added return type to _LazyTickList, which seems to have caused some new errors in test_axes.py, but those are just accessing private attributes.

@QuLogic QuLogic marked this pull request as ready for review August 5, 2023 01:13
@tacaswell tacaswell merged commit f250998 into matplotlib:main Aug 7, 2023
@QuLogic QuLogic deleted the type-return branch August 8, 2023 21:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0