Skip to content

Commit a4aaeef

Browse files
authored
Use class-based NamedTuples (#361)
1 parent faa98b5 commit a4aaeef

File tree

4 files changed

+19
-12
lines changed

4 files changed

+19
-12
lines changed

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ ignore = [
5555
"F401",
5656

5757
# TODO: Investigate and fix or configure
58-
"PYI024",
5958
"PYI048",
6059
"PYI051", # Request for autofix: https://github.com/astral-sh/ruff/issues/14185
6160
]

stubs/matplotlib/dviread.pyi

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
1+
from _typeshed import Incomplete
12
from collections import namedtuple
23
from functools import lru_cache
4+
from typing import NamedTuple
35

46
from ._typing import *
57
from .path import Path
68

79
Page = ...
810
Box = ...
911

10-
class Text(namedtuple("Text", "x y font glyph width")):
12+
class Text(NamedTuple):
13+
x: float
14+
y: float
15+
font: Incomplete
16+
glyph: Incomplete
17+
width: int
1118
@property
1219
def font_path(self) -> Path: ...
1320
@property

stubs/sklearn/gaussian_process/kernels.pyi

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import math
22
import warnings
33
from abc import ABCMeta, abstractmethod
4-
from collections import namedtuple
54
from collections.abc import Sequence
65
from inspect import signature as signature
7-
from typing import Callable, Literal
6+
from typing import Callable, Literal, NamedTuple
87
from typing_extensions import Self
98

109
import numpy as np
@@ -17,12 +16,12 @@ from ..base import clone as clone
1716
from ..exceptions import ConvergenceWarning as ConvergenceWarning
1817
from ..metrics.pairwise import pairwise_kernels as pairwise_kernels
1918

20-
class Hyperparameter(namedtuple("Hyperparameter", ("name", "value_type", "bounds", "n_elements", "fixed"))):
21-
fixed: bool = ...
22-
n_elements: int = ...
23-
bounds: tuple[float, float] | str = ...
24-
value_type: str = ...
25-
name: str = ...
19+
class Hyperparameter(NamedTuple):
20+
fixed: bool
21+
n_elements: int
22+
bounds: tuple[float, float] | str
23+
value_type: str
24+
name: str
2625

2726
# A raw namedtuple is very memory efficient as it packs the attributes
2827
# in a struct to get rid of the __dict__ of attributes in particular it

stubs/sympy-stubs/testing/runtests.pyi

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ from collections import namedtuple
33
from collections.abc import Generator
44
from contextlib import contextmanager
55
from doctest import DocTestFinder, DocTestRunner
6-
from typing import Any, Literal
6+
from typing import Any, Literal, NamedTuple
77

88
IS_WINDOWS = ...
99
ON_CI = ...
@@ -32,7 +32,9 @@ sp = ...
3232

3333
def split_list(l, split, density=...): ...
3434

35-
SymPyTestResults = namedtuple("SymPyTestResults", "failed attempted")
35+
class SymPyTestResults(NamedTuple):
36+
failed: int
37+
attempted: int
3638

3739
def sympytestfile(
3840
filename,

0 commit comments

Comments
 (0)