refactor(testing): attach filler plugin state via typed StashKeys - #908
Merged
tcoratger merged 1 commit intoJun 10, 2026
Merged
Conversation
The fill plugin smuggled five attributes onto the pytest config object: the fixture collector, the selected fork class, and the per-test fixture path and format. Each assignment needed a type: ignore for setting an undeclared attribute, and each read used a hasattr probe, six ignores in total. Store this state in config.stash keyed by module-level StashKeys instead. The stash is the documented, type-safe place for plugin state, so the collector reads back as a FixtureCollector and the fork class as type[BaseFork] with no ignores, and presence checks use "in" on the stash. Resolve the fork class by membership and direct indexing so it is never optional, since the type checker does not narrow through the NoReturn exit. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
The fill pytest plugin smuggled five attributes onto the
pytest.Configobject — the fixture collector, the selected fork class, and the per-test fixture path (absolute + relative) and format. Each write needed a# type: ignore[attribute-defined](six in total), and each read used ahasattr(...)probe:This is monkey-patching the config with undeclared attributes — untyped, unchecked, and flagged by the type checker.
What this does
Stores the same state in
config.stash, keyed by module-levelStashKeys — the documented, type-safe mechanism for plugin state:Result:
type: ignores removed. The collector reads back asFixtureCollectorand the fork class astype[BaseFork]— fully typed.hasattrprobes replaced withKEY in config.stash.FORKS_BY_NAME[name]) so it is neverOptional— the type checker does not narrow through theNoReturnCLI exit, and this keepsfork_class.name()/<=valid without an assert.No behavior change: same data flow, same fixture output, same fork filtering and CLI error paths.
Testing
just checkpasses (lint, format, ty, codespell, mdformat) — zerotype: ignore, zerohasattr(config...)left in the file.--forkstill exits cleanly with the same message and lists available forks.🤖 Generated with Claude Code