Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Backport PR #29362 on branch v3.10.0-doc (TYP: semantics of enums in stub files changed) #29448

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

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 9 additions & 19 deletions lib/matplotlib/_enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,11 @@
they define.
"""

from enum import Enum, auto
from enum import Enum
from matplotlib import _docstring


class _AutoStringNameEnum(Enum):
"""Automate the ``name = 'name'`` part of making a (str, Enum)."""

def _generate_next_value_(name, start, count, last_values):
return name

def __hash__(self):
return str(self).__hash__()


class JoinStyle(str, _AutoStringNameEnum):
class JoinStyle(str, Enum):
"""
Define how the connection between two line segments is drawn.

Expand Down Expand Up @@ -79,9 +69,9 @@ class JoinStyle(str, _AutoStringNameEnum):

"""

miter = auto()
round = auto()
bevel = auto()
miter = "miter"
round = "round"
bevel = "bevel"

@staticmethod
def demo():
Expand Down Expand Up @@ -116,7 +106,7 @@ def plot_angle(ax, x, y, angle, style):
+ "}"


class CapStyle(str, _AutoStringNameEnum):
class CapStyle(str, Enum):
r"""
Define how the two endpoints (caps) of an unclosed line are drawn.

Expand Down Expand Up @@ -151,9 +141,9 @@ class CapStyle(str, _AutoStringNameEnum):
CapStyle.demo()

"""
butt = auto()
projecting = auto()
round = auto()
butt = "butt"
projecting = "projecting"
round = "round"

@staticmethod
def demo():
Expand Down
21 changes: 11 additions & 10 deletions lib/matplotlib/_enums.pyi
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
from typing import cast
from enum import Enum

class _AutoStringNameEnum(Enum):
def __hash__(self) -> int: ...

class JoinStyle(str, _AutoStringNameEnum):
miter: str
round: str
bevel: str
class JoinStyle(str, Enum):
miter = "miter"
round = "round"
bevel = "bevel"
@staticmethod
def demo() -> None: ...

class CapStyle(str, _AutoStringNameEnum):
butt: str
projecting: str
round: str

class CapStyle(str, Enum):
butt = "butt"
projecting = "projecting"
round = "round"

@staticmethod
def demo() -> None: ...
16 changes: 8 additions & 8 deletions lib/matplotlib/backend_bases.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,11 @@ class LocationEvent(Event):
) -> None: ...

class MouseButton(IntEnum):
LEFT: int
MIDDLE: int
RIGHT: int
BACK: int
FORWARD: int
LEFT = 1
MIDDLE = 2
RIGHT = 3
BACK = 8
FORWARD = 9

class MouseEvent(LocationEvent):
button: MouseButton | Literal["up", "down"] | None
Expand Down Expand Up @@ -398,9 +398,9 @@ class FigureManagerBase:
cursors = Cursors

class _Mode(str, Enum):
NONE: str
PAN: str
ZOOM: str
NONE = ""
PAN = "pan/zoom"
ZOOM = "zoom rect"

class NavigationToolbar2:
toolitems: tuple[tuple[str, ...] | tuple[None, ...], ...]
Expand Down
16 changes: 8 additions & 8 deletions lib/matplotlib/backend_tools.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ from matplotlib.backend_managers import ToolManager, ToolEvent
from matplotlib.figure import Figure
from matplotlib.scale import ScaleBase

from typing import Any
from typing import Any, cast

class Cursors(enum.IntEnum):
POINTER: int
HAND: int
SELECT_REGION: int
MOVE: int
WAIT: int
RESIZE_HORIZONTAL: int
RESIZE_VERTICAL: int
POINTER = cast(int, ...)
HAND = cast(int, ...)
SELECT_REGION = cast(int, ...)
MOVE = cast(int, ...)
WAIT = cast(int, ...)
RESIZE_HORIZONTAL = cast(int, ...)
RESIZE_VERTICAL = cast(int, ...)

cursors = Cursors

Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/backends/registry.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ from types import ModuleType


class BackendFilter(Enum):
INTERACTIVE: int
NON_INTERACTIVE: int
INTERACTIVE = 0
NON_INTERACTIVE = 1


class BackendRegistry:
Expand Down
10 changes: 5 additions & 5 deletions lib/matplotlib/dviread.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ from typing import NamedTuple
from typing_extensions import Self # < Py 3.11

class _dvistate(Enum):
pre: int
outer: int
inpage: int
post_post: int
finale: int
pre = ...
outer = ...
inpage = ...
post_post = ...
finale = ...

class Page(NamedTuple):
text: list[Text]
Expand Down
100 changes: 50 additions & 50 deletions lib/matplotlib/ft2font.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from enum import Enum, Flag
import sys
from typing import BinaryIO, Literal, TypedDict, final, overload
from typing import BinaryIO, Literal, TypedDict, final, overload, cast
from typing_extensions import Buffer # < Py 3.12

import numpy as np
Expand All @@ -10,62 +10,62 @@ __freetype_build_type__: str
__freetype_version__: str

class FaceFlags(Flag):
SCALABLE: int
FIXED_SIZES: int
FIXED_WIDTH: int
SFNT: int
HORIZONTAL: int
VERTICAL: int
KERNING: int
FAST_GLYPHS: int
MULTIPLE_MASTERS: int
GLYPH_NAMES: int
EXTERNAL_STREAM: int
HINTER: int
CID_KEYED: int
TRICKY: int
COLOR: int
# VARIATION: int # FT 2.9
# SVG: int # FT 2.12
# SBIX: int # FT 2.12
# SBIX_OVERLAY: int # FT 2.12
SCALABLE = cast(int, ...)
FIXED_SIZES = cast(int, ...)
FIXED_WIDTH = cast(int, ...)
SFNT = cast(int, ...)
HORIZONTAL = cast(int, ...)
VERTICAL = cast(int, ...)
KERNING = cast(int, ...)
FAST_GLYPHS = cast(int, ...)
MULTIPLE_MASTERS = cast(int, ...)
GLYPH_NAMES = cast(int, ...)
EXTERNAL_STREAM = cast(int, ...)
HINTER = cast(int, ...)
CID_KEYED = cast(int, ...)
TRICKY = cast(int, ...)
COLOR = cast(int, ...)
# VARIATION = cast(int, ...) # FT 2.9
# SVG = cast(int, ...) # FT 2.12
# SBIX = cast(int, ...) # FT 2.12
# SBIX_OVERLAY = cast(int, ...) # FT 2.12

class Kerning(Enum):
DEFAULT: int
UNFITTED: int
UNSCALED: int
DEFAULT = cast(int, ...)
UNFITTED = cast(int, ...)
UNSCALED = cast(int, ...)

class LoadFlags(Flag):
DEFAULT: int
NO_SCALE: int
NO_HINTING: int
RENDER: int
NO_BITMAP: int
VERTICAL_LAYOUT: int
FORCE_AUTOHINT: int
CROP_BITMAP: int
PEDANTIC: int
IGNORE_GLOBAL_ADVANCE_WIDTH: int
NO_RECURSE: int
IGNORE_TRANSFORM: int
MONOCHROME: int
LINEAR_DESIGN: int
NO_AUTOHINT: int
COLOR: int
COMPUTE_METRICS: int # FT 2.6.1
# BITMAP_METRICS_ONLY: int # FT 2.7.1
# NO_SVG: int # FT 2.13.1
DEFAULT = cast(int, ...)
NO_SCALE = cast(int, ...)
NO_HINTING = cast(int, ...)
RENDER = cast(int, ...)
NO_BITMAP = cast(int, ...)
VERTICAL_LAYOUT = cast(int, ...)
FORCE_AUTOHINT = cast(int, ...)
CROP_BITMAP = cast(int, ...)
PEDANTIC = cast(int, ...)
IGNORE_GLOBAL_ADVANCE_WIDTH = cast(int, ...)
NO_RECURSE = cast(int, ...)
IGNORE_TRANSFORM = cast(int, ...)
MONOCHROME = cast(int, ...)
LINEAR_DESIGN = cast(int, ...)
NO_AUTOHINT = cast(int, ...)
COLOR = cast(int, ...)
COMPUTE_METRICS = cast(int, ...) # FT 2.6.1
# BITMAP_METRICS_ONLY = cast(int, ...) # FT 2.7.1
# NO_SVG = cast(int, ...) # FT 2.13.1
# The following should be unique, but the above can be OR'd together.
TARGET_NORMAL: int
TARGET_LIGHT: int
TARGET_MONO: int
TARGET_LCD: int
TARGET_LCD_V: int
TARGET_NORMAL = cast(int, ...)
TARGET_LIGHT = cast(int, ...)
TARGET_MONO = cast(int, ...)
TARGET_LCD = cast(int, ...)
TARGET_LCD_V = cast(int, ...)

class StyleFlags(Flag):
NORMAL: int
ITALIC: int
BOLD: int
NORMAL = cast(int, ...)
ITALIC = cast(int, ...)
BOLD = cast(int, ...)

class _SfntHeadDict(TypedDict):
version: tuple[int, int]
Expand Down
2 changes: 2 additions & 0 deletions lib/matplotlib/stackplot.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ def stackplot(
baseline: Literal["zero", "sym", "wiggle", "weighted_wiggle"] = ...,
**kwargs
) -> list[PolyCollection]: ...

__all__ = ['stackplot']
2 changes: 2 additions & 0 deletions lib/matplotlib/streamplot.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,5 @@ class StreamMask:
class InvalidIndexError(Exception): ...
class TerminateTrajectory(Exception): ...
class OutOfBounds(IndexError): ...

__all__ = ['streamplot']
2 changes: 2 additions & 0 deletions lib/matplotlib/style/core.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ library: dict[str, RcParams]
available: list[str]

def reload_library() -> None: ...

__all__ = ['use', 'context', 'available', 'library', 'reload_library']
11 changes: 11 additions & 0 deletions lib/matplotlib/ticker.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -295,3 +295,14 @@ class AutoLocator(MaxNLocator):
class AutoMinorLocator(Locator):
ndivs: int
def __init__(self, n: int | None = ...) -> None: ...

__all__ = ('TickHelper', 'Formatter', 'FixedFormatter',
'NullFormatter', 'FuncFormatter', 'FormatStrFormatter',
'StrMethodFormatter', 'ScalarFormatter', 'LogFormatter',
'LogFormatterExponent', 'LogFormatterMathtext',
'LogFormatterSciNotation',
'LogitFormatter', 'EngFormatter', 'PercentFormatter',
'Locator', 'IndexLocator', 'FixedLocator', 'NullLocator',
'LinearLocator', 'LogLocator', 'AutoLocator',
'MultipleLocator', 'MaxNLocator', 'AutoMinorLocator',
'SymmetricalLogLocator', 'AsinhLocator', 'LogitLocator')
2 changes: 2 additions & 0 deletions lib/matplotlib/tri/_triinterpolate.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ class CubicTriInterpolator(TriInterpolator):
trifinder: TriFinder | None = ...,
dz: tuple[ArrayLike, ArrayLike] | None = ...,
) -> None: ...

__all__ = ('TriInterpolator', 'LinearTriInterpolator', 'CubicTriInterpolator')
Loading