You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
frommatplotlib.scaleimportscale_factoryscale_factory("linear", None)
# pyright:# error: Argument of type "None" cannot be assigned to parameter "axis" of type "Axis" in function "scale_factory"# "None" is not assignable to "Axis" (reportArgumentType)# mypy:# error: Argument 2 to "scale_factory" has incompatible type "None"; expected "Axis" [arg-type]
Actual outcome
# pyright:# error: Argument of type "None" cannot be assigned to parameter "axis" of type "Axis" in function "scale_factory"# "None" is not assignable to "Axis" (reportArgumentType)# mypy:# error: Argument 2 to "scale_factory" has incompatible type "None"; expected "Axis" [arg-type]
Expected outcome
mypy and pyright passing
Additional information
Using the same type hints as ScaleBase should solve this.
Operating system
No response
Matplotlib Version
3.9.2
Matplotlib Backend
No response
Python version
No response
Jupyter version
No response
Installation
None
The text was updated successfully, but these errors were encountered:
Thanks for the report. The type hint is correct for now. An axis parameter must still be passed to all Scales by the caller for backwards compatibility. Maybe the note is not clear. The recommendation is that the scale does not make use of the parameter.
There’s a plan to remove the parameter, but that’ll take a while to make the transition smooth. See #29349.
While discouraged, and not used in Matplotlibs own scales anymore, 3rd party libs can still register scales that make use of this parameter. This would fail if somebody would pass None. It's a judgement call whether we allow None and let this error path slip through the type checker, or whether we still always require the Axis.
Bug summary
scale_factory requires Axis according to the type hints:
matplotlib/lib/matplotlib/scale.pyi
Line 177 in 8d64f03
But ax is even discouraged in the code:
matplotlib/lib/matplotlib/scale.py
Lines 51 to 63 in 8d64f03
matplotlib/lib/matplotlib/scale.pyi
Lines 8 to 9 in 8d64f03
Code for reproduction
Actual outcome
Expected outcome
mypy and pyright passing
Additional information
Using the same type hints as ScaleBase should solve this.
Operating system
No response
Matplotlib Version
3.9.2
Matplotlib Backend
No response
Python version
No response
Jupyter version
No response
Installation
None
The text was updated successfully, but these errors were encountered: