Skip to content

Commit 0de96b4

Browse files
authored
docs: let autodoc resolve the HTTP/2 frame and engine class annotations (#1857) (#1870)
1 parent 06e16db commit 0de96b4

8 files changed

Lines changed: 403 additions & 26 deletions

File tree

‎pcapkit/foundation/engines/dpkt.py‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
__all__ = ['DPKT', 'PCAPNGReader']
3030

3131
if TYPE_CHECKING:
32+
from types import ModuleType
3233
from typing import IO, Iterator, Literal, Optional, Type, Union
3334

3435
from dpkt.dpkt import Packet as DPKTPacket
@@ -380,10 +381,8 @@ class DPKT(EngineBase['DPKTPacket']):
380381
381382
"""
382383
if TYPE_CHECKING:
383-
import dpkt
384-
385-
#: Engine extraction package.
386-
_expkg: 'dpkt'
384+
#: Engine extraction package, i.e. :mod:`dpkt`.
385+
_expkg: 'ModuleType'
387386
#: Engine extraction temporary storage.
388387
_extmp: 'Reader'
389388

@@ -441,7 +440,6 @@ def run(self) -> 'None':
441440
from pcapkit.foundation.engines.pcapng import PCAPNG
442441

443442
ext = self._extractor
444-
dpkt = self._expkg
445443

446444
if ext._exlyr != 'none' or ext._exptl != 'null':
447445
warn("'Extractor(engine=dpkt)' does not support protocol and layer threshold; "

‎pcapkit/foundation/engines/pcap_ct.py‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
__all__ = ['PCAP_CT']
2525

2626
if TYPE_CHECKING:
27+
from types import ModuleType
2728
from typing import Iterator, Optional
2829

2930
from pcap import pcap as Handle
@@ -111,10 +112,8 @@ class PCAP_CT(EngineBase['RawFrame']):
111112
112113
"""
113114
if TYPE_CHECKING:
114-
import pcap
115-
116-
#: Engine extraction package.
117-
_expkg: 'pcap'
115+
#: Engine extraction package, i.e. :mod:`pcap`.
116+
_expkg: 'ModuleType'
118117
#: Capture handle, kept separately from the iterator it is read through
119118
#: so that :meth:`close` does not depend on ``iter(handle) is handle``.
120119
_handle: 'Handle'

‎pcapkit/foundation/engines/pypcap.py‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
__all__ = ['PyPCAP']
3232

3333
if TYPE_CHECKING:
34+
from types import ModuleType
3435
from typing import Iterator, Optional
3536

3637
from pcap import pcap as Handle
@@ -86,10 +87,8 @@ class PyPCAP(EngineBase['RawFrame']):
8687
8788
"""
8889
if TYPE_CHECKING:
89-
import pcap
90-
91-
#: Engine extraction package.
92-
_expkg: 'pcap'
90+
#: Engine extraction package, i.e. :mod:`pcap`.
91+
_expkg: 'ModuleType'
9392
#: Engine extraction temporary storage.
9493
_extmp: 'Iterator[RawFrame]'
9594
#: Data link layer protocol, from the capture handle.

‎pcapkit/foundation/engines/pypcapfile.py‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
__all__ = ['PyPCAPFile']
2828

2929
if TYPE_CHECKING:
30+
from types import ModuleType
3031
from typing import Any, Callable, Iterator, Optional
3132

3233
from pcapfile.structs import __pcap_header__ as PCAPFileHeader
@@ -68,10 +69,8 @@ class PyPCAPFile(EngineBase['PCAPFilePacket']):
6869
6970
"""
7071
if TYPE_CHECKING:
71-
import pcapfile
72-
73-
#: Engine extraction package.
74-
_expkg: 'pcapfile'
72+
#: Engine extraction package, i.e. :mod:`pcapfile`.
73+
_expkg: 'ModuleType'
7574
#: Engine extraction temporary storage.
7675
_extmp: 'Iterator[PCAPFilePacket]'
7776
#: Data link layer protocol, from the savefile header.

‎pcapkit/foundation/engines/pyshark.py‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
__all__ = ['PyShark']
2323

2424
if TYPE_CHECKING:
25+
from types import ModuleType
2526
from typing import Optional
2627

2728
from pyshark.capture.file_capture import FileCapture
@@ -82,10 +83,8 @@ class PyShark(EngineBase['PySharkPacket']):
8283
8384
"""
8485
if TYPE_CHECKING:
85-
import pyshark
86-
87-
#: Engine extraction package.
88-
_expkg: 'pyshark'
86+
#: Engine extraction package, i.e. :mod:`pyshark`.
87+
_expkg: 'ModuleType'
8988
#: Engine extraction temporary storage.
9089
_extmp: 'FileCapture'
9190

‎pcapkit/foundation/engines/scapy.py‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
__all__ = ['Scapy']
5252

5353
if TYPE_CHECKING:
54+
from types import ModuleType
5455
from typing import Any, Iterator, Type
5556

5657
from scapy.packet import Packet as ScapyPacket
@@ -282,10 +283,8 @@ class Scapy(EngineBase['ScapyPacket']):
282283
283284
"""
284285
if TYPE_CHECKING:
285-
import scapy.all
286-
287-
#: Engine extraction package.
288-
_expkg: 'scapy.all'
286+
#: Engine extraction package, i.e. :mod:`scapy.all`.
287+
_expkg: 'ModuleType'
289288
#: Engine extraction temporary storage.
290289
_extmp: 'Iterator[ScapyPacket]'
291290

‎pcapkit/protocols/schema/application/httpv2.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,10 @@ class FrameType(EnumSchema[Enum_Frame]):
133133
"""Header schema for HTTP/2 frame payload."""
134134

135135
if TYPE_CHECKING:
136-
__flags__: 'Flags'
136+
# Qualified rather than ``'Flags'``: documentation tools evaluate a class
137+
# annotation against the module's globals, not the class body, so the
138+
# bare nested name cannot be found there (#1857).
139+
__flags__: 'FrameType.Flags'
137140

138141
__enum__ = collections.defaultdict(lambda: UnassignedFrame)
139142

0 commit comments

Comments
 (0)