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

Skip to content

Commit 1bc4ab6

Browse files
committed
TYP: Use pipes for Union types
1 parent bcfecca commit 1bc4ab6

File tree

3 files changed

+34
-33
lines changed

3 files changed

+34
-33
lines changed

lib/matplotlib/_mathtext.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2645,7 +2645,7 @@ def _genfrac(self, ldelim: str, rdelim: str, rule: float | None, style: _MathSty
26452645
if rdelim == '':
26462646
rdelim = '.'
26472647
return self._auto_sized_delimiter(ldelim,
2648-
T.cast(list[T.Union[Box, Char, str]],
2648+
T.cast(list[Box | Char | str],
26492649
result),
26502650
rdelim)
26512651
return result
@@ -2786,7 +2786,7 @@ def _auto_sized_delimiter(self, front: str,
27862786
del middle[idx]
27872787
# There should only be \middle and its delimiter as str, which have
27882788
# just been removed.
2789-
middle_part = T.cast(list[T.Union[Box, Char]], middle)
2789+
middle_part = T.cast(list[Box | Char], middle)
27902790
else:
27912791
height = 0
27922792
depth = 0

lib/matplotlib/_mathtext_data.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"""
44

55
from __future__ import annotations
6-
from typing import overload, Union
6+
from typing import overload
77

88
latex_to_bakoma = {
99
'\\__sqrt__' : ('cmex10', 0x70),
@@ -1113,11 +1113,10 @@
11131113
# Each element is a 4-tuple of the form:
11141114
# src_start, src_end, dst_font, dst_start
11151115

1116-
_EntryTypeIn = tuple[str, str, str, Union[str, int]]
1116+
_EntryTypeIn = tuple[str, str, str, str | int]
11171117
_EntryTypeOut = tuple[int, int, str, int]
11181118

1119-
_stix_virtual_fonts: dict[str, Union[dict[
1120-
str, list[_EntryTypeIn]], list[_EntryTypeIn]]] = {
1119+
_stix_virtual_fonts: dict[str, dict[str, list[_EntryTypeIn]] | list[_EntryTypeIn]] = {
11211120
'bb': {
11221121
"rm": [
11231122
("\N{DIGIT ZERO}",
@@ -1729,8 +1728,7 @@ def _normalize_stix_fontcodes(d):
17291728
return {k: _normalize_stix_fontcodes(v) for k, v in d.items()}
17301729

17311730

1732-
stix_virtual_fonts: dict[str, Union[dict[str, list[_EntryTypeOut]],
1733-
list[_EntryTypeOut]]]
1731+
stix_virtual_fonts: dict[str, dict[str, list[_EntryTypeOut]] | list[_EntryTypeOut]]
17341732
stix_virtual_fonts = _normalize_stix_fontcodes(_stix_virtual_fonts)
17351733

17361734
# Free redundant list now that it has been normalized

lib/matplotlib/typing.py

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,50 +11,53 @@
1111
"""
1212
from collections.abc import Hashable, Sequence
1313
import pathlib
14-
from typing import Any, Literal, TypeVar, Union
14+
from typing import Any, Literal, TypeVar
1515

1616
from . import path
1717
from ._enums import JoinStyle, CapStyle
1818
from .markers import MarkerStyle
1919

2020
# The following are type aliases. Once python 3.9 is dropped, they should be annotated
21-
# using ``typing.TypeAlias`` and Unions should be converted to using ``|`` syntax.
21+
# using ``typing.TypeAlias``.
2222

23-
RGBColorType = Union[tuple[float, float, float], str]
24-
RGBAColorType = Union[
25-
str, # "none" or "#RRGGBBAA"/"#RGBA" hex strings
26-
tuple[float, float, float, float],
23+
RGBColorType = tuple[float, float, float] | str
24+
RGBAColorType = (
25+
str | # "none" or "#RRGGBBAA"/"#RGBA" hex strings
26+
tuple[float, float, float, float] |
2727
# 2 tuple (color, alpha) representations, not infinitely recursive
2828
# RGBColorType includes the (str, float) tuple, even for RGBA strings
29-
tuple[RGBColorType, float],
29+
tuple[RGBColorType, float] |
3030
# (4-tuple, float) is odd, but accepted as the outer float overriding A of 4-tuple
31-
tuple[tuple[float, float, float, float], float],
32-
]
31+
tuple[tuple[float, float, float, float], float]
32+
)
3333

34-
ColorType = Union[RGBColorType, RGBAColorType]
34+
ColorType = RGBColorType | RGBAColorType
3535

3636
RGBColourType = RGBColorType
3737
RGBAColourType = RGBAColorType
3838
ColourType = ColorType
3939

40-
LineStyleType = Union[str, tuple[float, Sequence[float]]]
40+
LineStyleType = str | tuple[float, Sequence[float]]
4141
DrawStyleType = Literal["default", "steps", "steps-pre", "steps-mid", "steps-post"]
42-
MarkEveryType = Union[
43-
None, int, tuple[int, int], slice, list[int], float, tuple[float, float], list[bool]
44-
]
45-
46-
MarkerType = Union[str, path.Path, MarkerStyle]
42+
MarkEveryType = (
43+
None |
44+
int | tuple[int, int] | slice | list[int] |
45+
float | tuple[float, float] |
46+
list[bool]
47+
)
48+
49+
MarkerType = str | path.Path | MarkerStyle
4750
FillStyleType = Literal["full", "left", "right", "bottom", "top", "none"]
48-
JoinStyleType = Union[JoinStyle, Literal["miter", "round", "bevel"]]
49-
CapStyleType = Union[CapStyle, Literal["butt", "projecting", "round"]]
51+
JoinStyleType = JoinStyle | Literal["miter", "round", "bevel"]
52+
CapStyleType = CapStyle | Literal["butt", "projecting", "round"]
5053

51-
RcStyleType = Union[
52-
str,
53-
dict[str, Any],
54-
pathlib.Path,
55-
Sequence[Union[str, pathlib.Path, dict[str, Any]]],
56-
]
54+
RcStyleType = (
55+
str |
56+
dict[str, Any] |
57+
pathlib.Path |
58+
Sequence[str | pathlib.Path | dict[str, Any]]
59+
)
5760

5861
_HT = TypeVar("_HT", bound=Hashable)
59-
HashableList = list[Union[_HT, "HashableList[_HT]"]]
62+
HashableList = list[_HT | "HashableList[_HT]"]
6063
"""A nested list of Hashable values."""

0 commit comments

Comments
 (0)