Skip to content

mypy: TransportProtocol.undefined types as int, so four base-template defaults disagree with their annotations #770

Description

@JarryShaw

Describe the bug

Four [assignment] errors in pcapkit/const/reg/apptype/apptype.py's base-template code, every one
about TransportProtocol.undefined used as a default where a TransportProtocol is annotated. They
were masked by a file-wide # mypy: disable-error-code=assignment pragma until #769 removed it.

Reproduction

$ mypy --follow-imports=silent --ignore-missing-imports --show-column-numbers --show-error-codes \
       pcapkit/const/reg/apptype/apptype.py          # with the pragma
Success: no issues found in 1 source file

$ # same command, pragma removed
:2258:42: error: Incompatible types in assignment (expression has type "int", variable has type "TransportProtocol")  [assignment]
:2282:46: error: Incompatible default for parameter "proto" (default has type "int", parameter has type "TransportProtocol")  [assignment]
:2371:48: error: Incompatible default for parameter "proto" (default has type "int", parameter has type "TransportProtocol | str")  [assignment]
:2429:52: error: Incompatible default for parameter "proto" (default has type "int", parameter has type "TransportProtocol | str")  [assignment]
Found 4 errors in 1 file (checked 1 source file)

Whole-package: 112 errors in 38 files → 116 in 39.

Expected behavior

TransportProtocol.undefined should type as TransportProtocol, so the four defaults agree with
their annotations and no suppression is needed.

Additional context

Root cause isolated: undefined = 0 is a bare int literal, so mypy infers its attribute type as
int, while tcp/udp/sctp/dccp are auto()-valued and infer as Any — which is why only
undefined trips it. mypy has no aenum plugin, so the class is treated as a plain class rather
than an enum. Pre-existing and independent of #769: stripping only the pragma on unmodified
main reproduces all four, and none of the ~12,391 per-member lines contributes one.

The four sites are __new__, _dispatch, get and get_all; the fix belongs in the BASE
template in pcapkit/vendor/reg/apptype/apptype.py, not in the generated file. Whether it is
achievable without an aenum stub is not established.

Not urgent — mypy is advisory in CI (continue-on-error: true in lint.yml).

One follow-up this creates. lint.yml's header pins mypy at 112 errors / 38 files measured at
932cb48d1 (#753, #761). That pin stays honest because it names its commit, but once #769 merges
the current figure is 116/39. Either re-pin it or note the delta here, whichever the maintainer
prefers — flagging it so the two PRs do not quietly leave each other stale.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions