3
3
"""
4
4
from __future__ import annotations
5
5
6
- from typing import TypeVar
6
+ from typing import (
7
+ Callable ,
8
+ TypeVar ,
9
+ )
7
10
8
11
import numpy as np
9
12
23
26
from pandas .core .indexes .base import Index
24
27
25
28
_T = TypeVar ("_T" , bound = "NDArrayBackedExtensionIndex" )
29
+ _ExtensionIndexT = TypeVar ("_ExtensionIndexT" , bound = "ExtensionIndex" )
26
30
27
31
28
- def _inherit_from_data (name : str , delegate , cache : bool = False , wrap : bool = False ):
32
+ def _inherit_from_data (
33
+ name : str , delegate : type , cache : bool = False , wrap : bool = False
34
+ ):
29
35
"""
30
36
Make an alias for a method of the underlying ExtensionArray.
31
37
@@ -81,8 +87,9 @@ def fset(self, value):
81
87
method = attr
82
88
83
89
else :
84
-
85
- def method (self , * args , ** kwargs ):
90
+ # error: Incompatible redefinition (redefinition with type "Callable[[Any,
91
+ # VarArg(Any), KwArg(Any)], Any]", original type "property")
92
+ def method (self , * args , ** kwargs ): # type: ignore[misc]
86
93
if "inplace" in kwargs :
87
94
raise ValueError (f"cannot use inplace with { type (self ).__name__ } " )
88
95
result = attr (self ._data , * args , ** kwargs )
@@ -94,12 +101,15 @@ def method(self, *args, **kwargs):
94
101
return Index (result , name = self .name )
95
102
return result
96
103
97
- method .__name__ = name
104
+ # error: "property" has no attribute "__name__"
105
+ method .__name__ = name # type: ignore[attr-defined]
98
106
method .__doc__ = attr .__doc__
99
107
return method
100
108
101
109
102
- def inherit_names (names : list [str ], delegate , cache : bool = False , wrap : bool = False ):
110
+ def inherit_names (
111
+ names : list [str ], delegate : type , cache : bool = False , wrap : bool = False
112
+ ) -> Callable [[type [_ExtensionIndexT ]], type [_ExtensionIndexT ]]:
103
113
"""
104
114
Class decorator to pin attributes from an ExtensionArray to a Index subclass.
105
115
@@ -112,7 +122,7 @@ def inherit_names(names: list[str], delegate, cache: bool = False, wrap: bool =
112
122
Whether to wrap the inherited result in an Index.
113
123
"""
114
124
115
- def wrapper (cls ) :
125
+ def wrapper (cls : type [ _ExtensionIndexT ]) -> type [ _ExtensionIndexT ] :
116
126
for name in names :
117
127
meth = _inherit_from_data (name , delegate , cache = cache , wrap = wrap )
118
128
setattr (cls , name , meth )
0 commit comments