Skip to content

Repo hygiene and full type-check enforcement#241

Open
wolph wants to merge 15 commits into
developfrom
fix/type-checks-and-hygiene
Open

Repo hygiene and full type-check enforcement#241
wolph wants to merge 15 commits into
developfrom
fix/type-checks-and-hygiene

Conversation

@wolph

@wolph wolph commented Jul 6, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes every outstanding type-checker finding at the root and enforces all four declared checkers (pyrefly, mypy, basedpyright, ty) in tox and CI. Also removes legacy packaging leftovers superseded by the 4.0.0 modernization.

Spec: docs/superpowers/specs/2026-07-06-repo-hygiene-and-type-checks-design.md (local)

Type fixes (root-cause, no new blanket suppressions)

  • stl/__about__.py: single __version__: Final[str] declaration via intermediate — kills mypy no-redef + basedpyright reportRedeclaration
  • stl/base.py: typing.cast at 5 numpy stub-imprecision sites (TYP: fix shape-type of structured array fields numpy/numpy#30261); inline logger-name computation replacing name-mangled _Logged__get_name access; explicit def __hash__ consistent with identity __eq__
  • stl/stl.py: scoped pyright: ignore where a runtime-defensive isinstance is deliberate (None mesh names) and where newer typeshed genericized BufferedWriter
  • stl/_compat.py: speedups imports via private aliases assigned in try/else — robust with or without speedups installed
  • stl/ply.py: np.dtype[np.void] parameterization
  • Zero # type: ignore comments remain in stl/

CLI: argparse.FileType replaced (deprecated since Python 3.14)

  • Paths parsed as strings, opened after parsing; -/omitted still means stdin/stdout binary buffers; unopenable paths still exit 2 via parser.error
  • Three entry points consolidated into one _convert helper
  • Fixes a latent bug: FileType('wb') truncated the output file at parse time, before the input was validated — in-place conversion (stl f.stl f.stl) destroyed the file
  • New in-process tests cover the std-stream and error paths (subprocess pipe tests don't count toward coverage)

Enforcement

  • New tox envs mypy, basedpyright (hermetic via --pythonpath {envpython}), ty; CI type-check job runs all four
  • Checker versions pinned in tox for CI stability (bump deliberately)
  • Root speedups.pyi stub so checkers resolve the optional speedups package without it installed
  • mypy override for speedups mirroring the existing pyrefly/ty config

Hygiene

  • Legacy build.cmd (MSVC 2010 script for the speedups removed in 4.0.0) deleted; ~16 untracked legacy files cleaned from the working tree
  • .python-version gitignored (was pinning a dead Python 3.7 locally)

Verification

  • 352 tests passing, 23 skipped, 100% branch coverage (enforced)
  • All four checkers: 0 findings in both the locked dev venv and fresh tox envs (basedpyright verified hermetically against a speedups-less interpreter, including an env -i CI simulation)
  • ruff check + format clean; docs + docs-examples green
  • CLI smoke-tested: file→file, file→stdout, stdin→stdout pipes

Follow-ups (out of scope, noted during review)

  • Pre-existing RuntimeWarning (divide) at stl/base.py:716 surfaces as 2 pytest warnings
  • Consider declaring speedups in a dev extra so its presence in dev venvs is explicit

wolph added 15 commits July 6, 2026 17:45
Add mypy and basedpyright tox envs (mirroring the existing pyrefly
env) and wire pyrefly,mypy,basedpyright,ty into CI. Fresh envs expose
three gaps the dev venv masked: mypy has no ignore-missing-imports
override for the optional speedups module, numpy 2.5.1 stubs mistype
an update_areas assignment as float64, and newer bundled typeshed
makes BufferedWriter generic. Fixed with a mypy override, a cast to
the declared alias, and a scoped pyright suppression respectively;
stl/_compat.py also restructured to import speedups under private
aliases to clear a residual mypy no-redef false positive.
Add a root speedups.pyi stub (matching the real package's signatures)
so basedpyright resolves stl/_compat.py without the optional speedups
extension installed, and force basedpyright's tox env to use its own
interpreter (--pythonpath {envpython}) instead of auto-detecting the
root .venv, which happens to have speedups installed and was masking
the failure CI would hit. Also pin mypy/basedpyright/pyrefly/ty tox
env versions to the currently resolved releases so an untouched repo
can't be redenned by an upstream checker release, and tidy two
CHANGELOG entries (wording + line wrap).
Copilot AI review requested due to automatic review settings July 6, 2026 20:08
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors type annotations and suppresses type checker findings across mypy, basedpyright, pyrefly, and ty, while also replacing the deprecated argparse.FileType in the CLI with safe path-based file opening. Additionally, it removes the legacy build.cmd script and adds a local stub for the optional speedups package. The review feedback correctly points out that the refactored logged decorator in stl/base.py incorrectly uses __name__ (resolving to 'stl.base') instead of class_.__module__, which would misname loggers for classes decorated in other modules. A corresponding update to the test assertions in tests/test_mesh.py is also suggested to align with this fix.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread stl/base.py
Comment on lines +146 to 148
logger_name: str = '.'.join(
part.strip() for part in (__name__, class_.__name__) if part.strip()
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The logged decorator currently uses __name__ (which resolves to 'stl.base') to construct the logger name. This causes any class decorated with @logged in another module (or in user code) to have its logger incorrectly placed under the stl.base namespace.

To ensure the logger name matches the class's actual defining module (as described in the test comments), use class_.__module__ instead of __name__.

Suggested change
logger_name: str = '.'.join(
part.strip() for part in (__name__, class_.__name__) if part.strip()
)
logger_name: str = '.'.join(
part.strip() for part in (class_.__module__, class_.__name__) if part.strip()
)
References
  1. Dynamically determine the logger name using the decorated class's defining module (class_.__module__) rather than hardcoding the decorator's own module name (__name__) to preserve correct logger hierarchy.

Comment thread tests/test_mesh.py
class _Sample(Logged):
pass

assert _Sample.logger.name == 'stl.base._Sample'

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Update the assertion to verify that the logger name is constructed using the class's actual defining module (_Sample.__module__), aligning with the fix in stl/base.py and the test's own docstring/comment.

Suggested change
assert _Sample.logger.name == 'stl.base._Sample'
assert _Sample.logger.name == f'{_Sample.__module__}._Sample'
References
  1. Ensure test assertions align with the corrected dynamic module-based logger naming scheme.

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.

2 participants