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

Skip to content

Commit 996cb9a

Browse files
authored
Merge pull request #32291 from QuLogic/dataclass-slots
Reduce API surface of internal dataclasses
2 parents ef5ac81 + 97bb360 commit 996cb9a

7 files changed

Lines changed: 14 additions & 14 deletions

File tree

galleries/examples/widgets/menu.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from matplotlib.typing import ColorType
1616

1717

18-
@dataclass
18+
@dataclass(frozen=True, kw_only=True, slots=True)
1919
class ItemProperties:
2020
fontsize: float = 14
2121
labelcolor: ColorType = 'black'

lib/matplotlib/dviread.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,7 @@ def _mul1220(num1, num2):
953953
return (num1*num2) >> 20
954954

955955

956-
@dataclasses.dataclass(frozen=True, kw_only=True)
956+
@dataclasses.dataclass(frozen=True, kw_only=True, slots=True)
957957
class TexMetrics:
958958
"""
959959
Metrics of a glyph, with TeX semantics.

lib/matplotlib/dviread.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class Vf(Dvi):
8989
def __init__(self, filename: str | os.PathLike) -> None: ...
9090
def __getitem__(self, code: int) -> Page: ...
9191

92-
@dataclasses.dataclass(frozen=True, kw_only=True)
92+
@dataclasses.dataclass(frozen=True, kw_only=True, slots=True)
9393
class TexMetrics:
9494
tex_width: int
9595
tex_height: int

lib/matplotlib/font_manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ def __repr__(self):
386386
return f'FontPath{self._as_tuple()}'
387387

388388

389-
@dataclasses.dataclass(frozen=True)
389+
@dataclasses.dataclass(frozen=True, slots=True)
390390
class FontEntry:
391391
"""
392392
A class for storing Font properties.
@@ -1076,7 +1076,7 @@ def default(self, o):
10761076
if isinstance(o, FontManager):
10771077
return dict(o.__dict__, __class__='FontManager')
10781078
elif isinstance(o, FontEntry):
1079-
d = dict(o.__dict__, __class__='FontEntry')
1079+
d = dict(dataclasses.asdict(o), __class__='FontEntry')
10801080
try:
10811081
# Cache paths of fonts shipped with Matplotlib relative to the
10821082
# Matplotlib data path, which helps in the presence of venvs.

lib/matplotlib/font_manager.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class FontPath(str):
4646
def __hash__(self) -> int: ...
4747
def __repr__(self) -> str: ...
4848

49-
@dataclass
49+
@dataclass(frozen=True, slots=True)
5050
class FontEntry:
5151
fname: str = ...
5252
index: int = ...

lib/matplotlib/rcsetup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1519,7 +1519,7 @@ def _convert_validator_spec(key, conv):
15191519
type _MarkerType = int | str
15201520

15211521

1522-
@dataclass
1522+
@dataclass(eq=False, frozen=True, slots=True)
15231523
class _Param:
15241524
name: str
15251525
default: Any
@@ -1535,13 +1535,13 @@ class _Param:
15351535
description: str | None = None
15361536

15371537

1538-
@dataclass
1538+
@dataclass(eq=False, frozen=True, slots=True)
15391539
class _Section:
15401540
title: str
15411541
description: str | None = None
15421542

15431543

1544-
@dataclass
1544+
@dataclass(eq=False, frozen=True, slots=True)
15451545
class _Subsection:
15461546
title: str
15471547
description: str | None = None

lib/mpl_toolkits/mplot3d/axis3d.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,18 @@ def _tick_update_position(tick, tickxs, tickys, labelpos):
3636
tick.gridline.set_data([0], [0])
3737

3838

39-
@dataclass
39+
@dataclass(eq=False, frozen=True, slots=True)
4040
class _UpdatedArtists:
4141
"""
4242
Class to supply artists that have been updated ready to draw.
4343
4444
We track the types of artists individually, because they need
4545
different handling in the tightbox calculation.
4646
"""
47-
line: mlines.Line2D = None
48-
ticks: list = None
49-
offset_text: mtext.Text = None
50-
label: mtext.Text = None
47+
line: mlines.Line2D | None = None
48+
ticks: list | None = None
49+
offset_text: mtext.Text | None = None
50+
label: mtext.Text | None = None
5151

5252
def __iter__(self):
5353
"""Yield all updated artists in the correct order for drawing"""

0 commit comments

Comments
 (0)