Skip to content

Add type stubs for core analysis modules - #288

Open
heejaechang wants to merge 2 commits into
rubik:masterfrom
heejaechang:heejaechang-complete-bundled-stubs
Open

Add type stubs for core analysis modules#288
heejaechang wants to merge 2 commits into
rubik:masterfrom
heejaechang:heejaechang-complete-bundled-stubs

Conversation

@heejaechang

@heejaechang heejaechang commented Jul 28, 2026

Copy link
Copy Markdown

Summary

  • bundle complete sidecar stubs for radon.visitors, radon.raw, radon.complexity, and radon.metrics
  • add the PEP 561 marker and explicit package data for legacy Setuptools builds
  • preserve the complete runtime surface of each touched module, including result records and runtime reexports
  • leave production Python modules unchanged

This is intentionally a partial typing contribution. The Mando-decorated CLI, harvesters, contrib plugin, and bundled tests remain untyped rather than being weakened or padded for a score.

Type completeness

Installed-wheel, unfiltered pyright --verifytypes radon --outputjson (no --ignoreexternal):

  • score: 16.89% -> 53.23%
  • known exports: 64 -> 247
  • ambiguous exports: 19 -> 8
  • unknown exports: 296 -> 209
  • public modules: 28 -> 28

The two touched exports that remain unknown are the faithfully exposed stdlib operator module reexports in radon.raw and radon.visitors; they are not authored Any escape hatches.

Validation

  • exact touched-module names, signatures, defaults, members, records, inheritance, mutability, and reexports match runtime introspection
  • Python 3.7 grammar and Pyright target checks pass
  • installed-wheel scoped mypy.stubtest passes without allowlists or exclusions
  • strict positive consumers pass in Pyright and mypy; negative consumers reject invalid records, inputs, constructors, visitor calls, and member access
  • 404 repository tests pass; available tox environments pass on Python 3.9 (400 tests) and 3.12 (404 tests); coverage remains 82%
  • docs build succeeds with the same four existing warnings
  • Poetry and Setuptools 67.8 wheel/sdist builds each contain exactly the four .pyi files plus py.typed
  • representative analysis, result, deepcopy, and pickle behavior is identical on Python 3.9, 3.12, 3.13, 3.14, and 3.15
  • added typing artifacts contain no Any, casts, ignores, noqa, checker disables, or allowlists

Follow-up contract audit

  • distinguish Halstead dispatch results as string operator names and AST operands
  • model values stored in operands_seen as Hashable and descriptor ownership as type[HalsteadVisitor]
  • retain get_name(object) because runtime only reads obj.__class__.__name__
  • retain broad keyword typing for from_code/from_ast: ParamSpec can follow subclass constructors only by falsely adding positional arguments that the runtime factories reject
  • keep exported VerifyTypes metrics unchanged while improving referenced types from 1990 known / 58 ambiguous / 83 unknown to 1991 known / 56 ambiguous / 83 unknown

Existing boundaries

Full-package stubtest still stops before checking because untouched CLI/tests contain the existing untyped Mando import, tomllib/tomli redefinition, and bundled-test annotation errors. Twine still reports the existing README raw directive error. Existing repository-wide flake8/pep8/pylint failures and the obsolete make format tool arguments are unchanged; the added stubs pass targeted isort and Black checks.

heejaechang and others added 2 commits July 28, 2026 04:21
Bundle complete sidecar stubs for visitors, raw metrics, complexity, and maintainability metrics, and include them in legacy package builds.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Distinguish operator names from AST operands, model hashable stored operand values, and narrow dispatch descriptor ownership to HalsteadVisitor subclasses.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant