-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
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
Conversation
Depends on #26450 to fix the subclass method inconsistency. |
Cycling to get the mypy runs rebased post merge of #26450 |
These were problematic for stubtest, in ways that were more trouble than initially worth it, so I ignored the noisy ones: See matplotlib/ci/mypy-stubtest-allowlist.txt Lines 35 to 45 in 7484a86
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: ... |
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.
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.
lib/matplotlib/spines.pyi
Outdated
@@ -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]: ... |
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.
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
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 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.
Fixed all those items, and also added return type to |
Also, tweak tests to use canonical (and thus typed) getters.
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 thenmypy
complains that:PR checklist