Repository navigation
docs: let autodoc resolve the HTTP/2 frame and engine class annotations (#1857) - #1870
Conversation
…ns (#1857) - Qualify FrameType's `__flags__` as `'FrameType.Flags'`. Autodoc evaluates a class annotation in the module's globals, where the bare nested `Flags` is unbound, so every frame schema fell back to raw annotation strings. - Annotate each third-party engine's `_expkg` as `'ModuleType'`, imported in the module-level guard, and drop the class-level engine import it named. The docs build runs module-level guards only and cannot import pcap or pcapfile; mypy already typed calls through `_expkg` as Any and rejected `scapy.all` as a type. - Drop a dead `dpkt` local in `DPKT.run`, which pylint flags once the class-level import of the same name is gone. - Add a unit test that evaluates class annotations as autodoc does, without Sphinx and without importing an engine package. Closes #1857
|
Verdict: GOOD TO GO at
Non-blocking: |
|
Would MyPy still be able to properly infer and handle the types with the proposed changes? |
|
Yes, and it measures slightly better. mypy could never type the engine package through
With Measured with mypy 2.3.1 and the repo's Real per-engine typing would need a |
|
I would kinda still like to have per-engine real typings. Can we still do that? For untyped packages, we probably just need to create type stubs for those APIs and data types we used. |
|
Yes. Filed as #1878. Scapy already ships |
Please follow the guide below
You will be asked some questions, please read them carefully and answer honestly
Put an
xinto all the boxes [ ] relevant to your pull request (like that [x])Use Preview tab to see how your pull request will actually look like
Searched for similar pull requests
Followed the coding style (
make pylint,make mypy,make isort)make testpasses, and a test case covers the change. Narrow runs only, listed below.Added a changelog entry under
docs/source/changelog/and regeneratedCHANGELOG.md, if the change is user-visible: N/A — centralised in docs(changelog): shared 1.5.0 changelog — long-lived, merges last (#610, #616, #617, #618, #620) #657What is the purpose of your pull request?
Tick the commit type your subject line carries.
fix— corrects a defectfeat— adds a featureperf— changes performance, not behaviourrefactor— changes neither behaviour nor performancetest— tests onlydocs— documentation onlyci— workflows or build toolingrelease— bumps the version or rolls up a distributionchore— anything else__flags__as'FrameType.Flags'. Autodoc evaluates aclass annotation in the module's globals, where the bare nested
Flagsisunbound, so every frame schema fell back to raw annotation strings.
_expkgas'ModuleType', imported in themodule-level guard, and drop the class-level engine import it named. The docs
build runs module-level guards only and cannot import pcap or pcapfile; mypy
already typed calls through
_expkgas Any and rejectedscapy.allas a type.dpktlocal inDPKT.run, which pylint flags once theclass-level import of the same name is gone.
Sphinx and without importing an engine package.
Closes #1857
Known remainder, deferred to the
conf.pybatch after #1856:PCAP_CT._handleandPyPCAPFile._extmpstill fall back to raw strings in the docs build, becausepcapandpcapfileare not installed there.