5
5
Dict ,
6
6
Iterator ,
7
7
List ,
8
+ NamedTuple ,
8
9
Optional ,
9
10
Tuple ,
10
11
Type ,
@@ -82,56 +83,28 @@ def _resolve_argspec(
82
83
return tuple (paramflags ), tuple (argtypes )
83
84
84
85
85
- class _MemberSpec (object ):
86
- """Specifier of a slot of method or property."""
87
-
88
- __slots__ = ("name" , "idlflags" , "restype" )
86
+ class _ComMemberSpec (NamedTuple ):
87
+ """Specifier for a slot of COM method or property."""
89
88
90
- def __init__ (self , name , idlflags , restype ):
91
- self .name : str = name
92
- self .idlflags : Tuple [_UnionT [str , int ], ...] = idlflags
93
- self .restype : Optional [Type [_CData ]] = restype
89
+ restype : Optional [Type [_CData ]]
90
+ name : str
91
+ argtypes : Tuple [Type [_CData ], ...]
92
+ paramflags : Optional [Tuple [_ParamFlagType , ...]]
93
+ idlflags : Tuple [_UnionT [str , int ], ...]
94
+ doc : Optional [str ]
94
95
95
96
def is_prop (self ) -> bool :
96
- propflags = ("propget" , "propput" , "propputref" )
97
- return any (f in propflags for f in self .idlflags )
97
+ return _is_spec_prop (self )
98
98
99
99
100
- class _ComMemberSpec (_MemberSpec ):
101
- """Specifier for a slot of COM method or property."""
102
-
103
- __slots__ = ("argtypes" , "paramflags" , "doc" )
104
-
105
- def __init__ (self , restype , name , argtypes , paramflags , idlflags , doc ):
106
- self .argtypes : Tuple [Type [_CData ], ...] = argtypes
107
- self .paramflags : Optional [Tuple [_ParamFlagType , ...]] = paramflags
108
- self .doc : Optional [str ] = doc
109
- super (_ComMemberSpec , self ).__init__ (name , idlflags , restype )
110
-
111
- def __iter__ (self ):
112
- # for backward compatibility:
113
- # A function that returns this object used to return a `tuple`.
114
- # So it is implemented as unpackable as well.
115
- for item in (
116
- self .restype ,
117
- self .name ,
118
- self .argtypes ,
119
- self .paramflags ,
120
- self .idlflags ,
121
- self .doc ,
122
- ):
123
- yield item
124
-
125
-
126
- class _DispMemberSpec (_MemberSpec ):
100
+ class _DispMemberSpec (NamedTuple ):
127
101
"""Specifier for a slot of dispinterface method or property."""
128
102
129
- __slots__ = ("what" , "argspec" )
130
-
131
- def __init__ (self , what , name , idlflags , restype , argspec ):
132
- self .what : str = what
133
- self .argspec : Tuple [_ArgSpecElmType , ...] = argspec
134
- super (_DispMemberSpec , self ).__init__ (name , idlflags , restype )
103
+ what : str
104
+ name : str
105
+ idlflags : Tuple [_UnionT [str , int ], ...]
106
+ restype : Optional [Type [_CData ]]
107
+ argspec : Tuple [_ArgSpecElmType , ...]
135
108
136
109
@property
137
110
def memid (self ) -> int :
@@ -140,12 +113,17 @@ def memid(self) -> int:
140
113
except IndexError :
141
114
raise TypeError ("no dispid found in idlflags" )
142
115
143
- def __iter__ (self ):
144
- # for backward compatibility:
145
- # A function that returns this object used to return a `tuple`.
146
- # So it is implemented as unpackable as well.
147
- for item in (self .what , self .name , self .idlflags , self .restype , self .argspec ):
148
- yield item
116
+ def is_prop (self ) -> bool :
117
+ return _is_spec_prop (self )
118
+
119
+
120
+ # Specifier of a slot of method or property.
121
+ # This should be `typing.Protocol` if supporting Py3.8+ only.
122
+ _MemberSpec = _UnionT [_ComMemberSpec , _DispMemberSpec ]
123
+
124
+
125
+ def _is_spec_prop (m : _MemberSpec ):
126
+ return any (f in ("propget" , "propput" , "propputref" ) for f in m .idlflags )
149
127
150
128
151
129
_PropFunc = Optional [Callable [..., Any ]]
0 commit comments