Skip to content

[MNT] [TYPING]: Use of Literal #30257

Open
@ZPyrolink

Description

@ZPyrolink

Summary

While checking pyplot and corresponding matplotlib methods, I noticed that there are several functions where we could use typing.Literal to explicitly indicate the possible values and have them suggested by IDEs.
We also can create the corresponding TypeAlias on matplotlib.typing when necessary.

Proposed fix

Function Parameter Literal replacing str
mpl.set_loglevel level "notset", "debug", "info", "warning", "error", "critical"
plt.connect s "button_press_event", "button_release_event", ...
plt.Axes.scatter marker See MarkerType behind
mpl.rc group "animation", "axes", axes3d, "axes3d", "boxplot", ...
mpl.RcParams.get_item / set_item key --
Type Literal replacing str
MarkerType ".", ",", "o"

On MarkerType we can also add litterals for the tuple version that is not indicated for now:

tuple[int, Literal[1, 2, 3], int]

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy