Skip to content

Commit 8470b85

Browse files
committed
revised info/schema_final type annotations
1 parent e223692 commit 8470b85

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

pcapkit/corekit/infoclass.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@
2626
__all__ = ['Info', 'info_final']
2727

2828
VT = TypeVar('VT')
29+
ST = TypeVar('ST', bound='Type[Info]')
2930

3031

31-
def info_final(cls: 'Type[Info[VT]]') -> 'Type[Info[VT]]':
32+
def info_final(cls: 'ST') -> 'ST':
3233
"""Finalise info class.
3334
3435
Args:
@@ -111,8 +112,8 @@ def info_final(cls: 'Type[Info[VT]]') -> 'Type[Info[VT]]':
111112
ns = {} # type: dict[str, Any]
112113
exec(init_, None, ns) # pylint: disable=exec-used # nosec
113114

114-
cls.__init__ = ns['__create_fn__']()
115-
cls.__init__.__qualname__ = f'{cls.__name__}.__init__'
115+
cls.__init__ = ns['__create_fn__']() # type: ignore[misc]
116+
cls.__init__.__qualname__ = f'{cls.__name__}.__init__' # type: ignore[misc]
116117

117118
cls.__finalised__ = True
118119
return final(cls)
@@ -167,7 +168,7 @@ def __new__(cls, *args: 'VT', **kwargs: 'VT') -> 'Self': # pylint: disable=unus
167168
168169
"""
169170
if not cls.__finalised__:
170-
cls = cast('Type[Self]', info_final(cls))
171+
cls = info_final(cls)
171172
self = super().__new__(cls)
172173

173174
# NOTE: We define the ``__map__`` and ``__map_reverse__`` attributes

pcapkit/protocols/schema/schema.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@
2525
__all__ = ['Schema', 'schema_final']
2626

2727
VT = TypeVar('VT')
28+
ST = TypeVar('ST', bound='Type[Schema]')
2829

2930

30-
def schema_final(cls: 'Type[Schema[VT]]') -> 'Type[Schema[VT]]':
31+
def schema_final(cls: 'ST') -> 'ST':
3132
"""Finalise schema class.
3233
3334
Args:
@@ -130,8 +131,8 @@ def schema_final(cls: 'Type[Schema[VT]]') -> 'Type[Schema[VT]]':
130131
ns = {} # type: dict[str, Any]
131132
exec(init_, None, ns) # pylint: disable=exec-used # nosec
132133

133-
cls.__init__ = ns['__create_fn__']()
134-
cls.__init__.__qualname__ = f'{cls.__name__}.__init__'
134+
cls.__init__ = ns['__create_fn__']() # type: ignore[misc]
135+
cls.__init__.__qualname__ = f'{cls.__name__}.__init__' # type: ignore[misc]
135136

136137
cls.__finalised__ = True
137138
return final(cls)
@@ -179,7 +180,7 @@ def __new__(cls, *args: 'VT', **kwargs: 'VT') -> 'Self': # pylint: disable=unus
179180
180181
"""
181182
if not cls.__finalised__:
182-
cls = cast('Type[Self]', schema_final(cls))
183+
cls = schema_final(cls)
183184
self = super().__new__(cls)
184185

185186
# NOTE: We define the ``__map__`` and ``__map_reverse__`` attributes

0 commit comments

Comments
 (0)