Skip to content

Commit 65f22a0

Browse files
authored
TYP: ExtensionDtype.name/type as ClassVar (#54458)
* TYP:ExtensionDtype.name/type as ClassVar * no code changes; only .name
1 parent a38a583 commit 65f22a0

File tree

5 files changed

+20
-13
lines changed

5 files changed

+20
-13
lines changed

pandas/core/arrays/boolean.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import numbers
44
from typing import (
55
TYPE_CHECKING,
6+
ClassVar,
67
cast,
78
)
89

@@ -60,7 +61,7 @@ class BooleanDtype(BaseMaskedDtype):
6061
BooleanDtype
6162
"""
6263

63-
name = "boolean"
64+
name: ClassVar[str] = "boolean"
6465

6566
# https://github.com/python/mypy/issues/4125
6667
# error: Signature of "type" incompatible with supertype "BaseMaskedDtype"

pandas/core/arrays/floating.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from __future__ import annotations
22

3+
from typing import ClassVar
4+
35
import numpy as np
46

57
from pandas.core.dtypes.base import register_extension_dtype
@@ -156,14 +158,14 @@ class FloatingArray(NumericArray):
156158
@register_extension_dtype
157159
class Float32Dtype(FloatingDtype):
158160
type = np.float32
159-
name = "Float32"
161+
name: ClassVar[str] = "Float32"
160162
__doc__ = _dtype_docstring.format(dtype="float32")
161163

162164

163165
@register_extension_dtype
164166
class Float64Dtype(FloatingDtype):
165167
type = np.float64
166-
name = "Float64"
168+
name: ClassVar[str] = "Float64"
167169
__doc__ = _dtype_docstring.format(dtype="float64")
168170

169171

pandas/core/arrays/integer.py

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from __future__ import annotations
22

3+
from typing import ClassVar
4+
35
import numpy as np
46

57
from pandas.core.dtypes.base import register_extension_dtype
@@ -205,56 +207,56 @@ class IntegerArray(NumericArray):
205207
@register_extension_dtype
206208
class Int8Dtype(IntegerDtype):
207209
type = np.int8
208-
name = "Int8"
210+
name: ClassVar[str] = "Int8"
209211
__doc__ = _dtype_docstring.format(dtype="int8")
210212

211213

212214
@register_extension_dtype
213215
class Int16Dtype(IntegerDtype):
214216
type = np.int16
215-
name = "Int16"
217+
name: ClassVar[str] = "Int16"
216218
__doc__ = _dtype_docstring.format(dtype="int16")
217219

218220

219221
@register_extension_dtype
220222
class Int32Dtype(IntegerDtype):
221223
type = np.int32
222-
name = "Int32"
224+
name: ClassVar[str] = "Int32"
223225
__doc__ = _dtype_docstring.format(dtype="int32")
224226

225227

226228
@register_extension_dtype
227229
class Int64Dtype(IntegerDtype):
228230
type = np.int64
229-
name = "Int64"
231+
name: ClassVar[str] = "Int64"
230232
__doc__ = _dtype_docstring.format(dtype="int64")
231233

232234

233235
@register_extension_dtype
234236
class UInt8Dtype(IntegerDtype):
235237
type = np.uint8
236-
name = "UInt8"
238+
name: ClassVar[str] = "UInt8"
237239
__doc__ = _dtype_docstring.format(dtype="uint8")
238240

239241

240242
@register_extension_dtype
241243
class UInt16Dtype(IntegerDtype):
242244
type = np.uint16
243-
name = "UInt16"
245+
name: ClassVar[str] = "UInt16"
244246
__doc__ = _dtype_docstring.format(dtype="uint16")
245247

246248

247249
@register_extension_dtype
248250
class UInt32Dtype(IntegerDtype):
249251
type = np.uint32
250-
name = "UInt32"
252+
name: ClassVar[str] = "UInt32"
251253
__doc__ = _dtype_docstring.format(dtype="uint32")
252254

253255

254256
@register_extension_dtype
255257
class UInt64Dtype(IntegerDtype):
256258
type = np.uint64
257-
name = "UInt64"
259+
name: ClassVar[str] = "UInt64"
258260
__doc__ = _dtype_docstring.format(dtype="uint64")
259261

260262

pandas/core/arrays/string_.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from typing import (
44
TYPE_CHECKING,
5+
ClassVar,
56
Literal,
67
)
78

@@ -96,7 +97,9 @@ class StringDtype(StorageExtensionDtype):
9697
string[pyarrow]
9798
"""
9899

99-
name = "string"
100+
# error: Cannot override instance variable (previously declared on
101+
# base class "StorageExtensionDtype") with class variable
102+
name: ClassVar[str] = "string" # type: ignore[misc]
100103

101104
#: StringDtype().na_value uses pandas.NA
102105
@property

pandas/core/dtypes/dtypes.py

-1
Original file line numberDiff line numberDiff line change
@@ -1517,7 +1517,6 @@ class BaseMaskedDtype(ExtensionDtype):
15171517
Base class for dtypes for BaseMaskedArray subclasses.
15181518
"""
15191519

1520-
name: str
15211520
base = None
15221521
type: type
15231522

0 commit comments

Comments
 (0)