66from typing import (
77 TYPE_CHECKING ,
88 Any ,
9+ Self ,
910 cast ,
1011 final ,
1112)
1718
1819
1920def TypedEnumerationType (_type : type ["SimpleCData" ]): # noqa: ANN201
20- class EnumerationType (type (_type )): # type: ignore # pyright: ignore[reportGeneralTypeIssues, reportUntypedBaseClass] #noqa: ANN201
21- def __new__ (cls , name : str , bases : tuple [type , ...], data : dict [str , Any ]): # pyright: ignore[reportExplicitAny, reportUnknownParameterType] # noqa: ANN204
21+ class EnumerationType (type (_type )): # type: ignore # pyright: ignore[reportGeneralTypeIssues, reportUntypedBaseClass]
22+ def __new__ (
23+ cls ,
24+ name : str ,
25+ bases : tuple [type , ...],
26+ data : dict [str , Any ], # pyright: ignore[reportExplicitAny]
27+ ) -> Self :
2228 _members_ : dict [str , Any ] # pyright: ignore[reportExplicitAny]
2329 if "_members_" not in data :
2430 _members_ = {}
@@ -32,11 +38,7 @@ def __new__(cls, name: str, bases: tuple[type, ...], data: dict[str, Any]): # p
3238 _members_ = cast (dict [str , Any ], data ["_members_" ]) # pyright: ignore[reportExplicitAny]
3339
3440 data ["_reverse_map_" ] = {v : k for k , v in _members_ .items ()} # pyright: ignore[reportAny]
35- cls = type (_type ).__new__ (cls , name , bases , data ) # pyright: ignore[reportCallIssue, reportUnknownVariableType] # noqa: PLW0642
36- for key , value in cast (dict [str , Any ], cls ._members_ ).items (): # pyright: ignore[reportExplicitAny, reportAny]
37- globals ()[key ] = value
38-
39- return cls # pyright: ignore[reportUnknownVariableType]
41+ return type (_type ).__new__ (cls , name , bases , data ) # pyright: ignore[reportCallIssue, reportUnknownVariableType]
4042
4143 @override
4244 def __repr__ (self ) -> str :
@@ -46,8 +48,8 @@ def __repr__(self) -> str:
4648
4749
4850def TypedCEnumeration (_type : type ["SimpleCData" ]): # noqa: ANN201
49- class CEnumeration (_type , metaclass = TypedEnumerationType (_type )): # pyright: ignore[reportGeneralTypeIssues, reportUntypedBaseClass] # noqa: ANN201,PLW1641, PLW1641
50- _members_ : dict [str , Any ] = {} # pyright: ignore[reportExplicitAny]
51+ class CEnumeration (_type , metaclass = TypedEnumerationType (_type )): # pyright: ignore[reportGeneralTypeIssues, reportUntypedBaseClass] # noqa: PLW1641
52+ _members_ : dict [str , Any ] = {} # pyright: ignore[reportExplicitAny] # noqa: RUF012
5153 basetype : type ["SimpleCData" ] = _type
5254
5355 @override
@@ -56,18 +58,18 @@ def __repr__(self) -> str:
5658 return f"<{ self .__class__ .__name__ } .{ self ._reverse_map_ .get (value , '(unknown)' )} : { value } >" # pyright: ignore[reportUnknownMemberType]
5759
5860 @override
59- def __eq__ (self , other : Any ) -> bool : # pyright: ignore[reportExplicitAny, reportAny]
61+ def __eq__ (self , other : object ) -> bool :
6062 if isinstance (other , int ):
6163 return self .value == other # pyright: ignore[reportUnknownMemberType, reportUnknownVariableType]
6264
63- return isinstance (self , type (other )) and self .value == other .value # pyright: ignore[reportUnknownVariableType, reportAny, reportUnknownMemberType ]
65+ return isinstance (self , type (other )) and self .value == other .value # pyright: ignore[reportUnknownVariableType, reportUnknownMemberType, reportAttributeAccessIssue ]
6466
6567 @override
66- def __ne__ (self , other : Any ) -> bool : # pyright: ignore[reportExplicitAny, reportAny]
68+ def __ne__ (self , other : object ) -> bool :
6769 if isinstance (other , int ):
6870 return self .value != other # pyright: ignore[reportUnknownMemberType, reportUnknownVariableType]
6971
70- return isinstance (self , type (other )) and self .value != other .value # pyright: ignore[reportUnknownVariableType, reportAny, reportUnknownMemberType ]
72+ return isinstance (self , type (other )) and self .value != other .value # pyright: ignore[reportUnknownVariableType, reportUnknownMemberType, reportAttributeAccessIssue ]
7173
7274 @override
7375 def __and__ (self , other : Any ) -> int | bool : # pyright: ignore[reportExplicitAny, reportAny, reportGeneralTypeIssues]
0 commit comments