test: type-check testing/src/scenario and fix uncovered errors#2615
Open
tonyandrewmeyer wants to merge 4 commits into
Open
test: type-check testing/src/scenario and fix uncovered errors#2615tonyandrewmeyer wants to merge 4 commits into
tonyandrewmeyer wants to merge 4 commits into
Conversation
Since ops 3.8.0, Secret.remote_grants values are frozensets, but secret_grant and secret_revoke still called .add() and .remove() on them, raising AttributeError when a charm revoked a pre-existing grant. Replace the in-place mutations with reassignment using set operators. Fixes canonical#2613 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
The pyright \`include\` glob \`testing/src/*.py\` did not match the
subdirectory where the scenario source actually lives, so all of
testing/src/scenario/*.py was silently unchecked. Add the correct
glob and fix the errors that surfaced.
Notable fixes:
- mocking.py: use dict(x) instead of .copy() on Mapping-typed state
fields; cast where the runtime is a dict but the annotation is
intentionally Mapping (relation databags, remote_grants).
- context.py: raise on missing app_name derivation is deferred (via ''
fallback) so existing tests can assert the downstream error path;
drop dead type: ignore comments now that annotations are correct.
- state.py: widen internal helper params to Mapping to match callers,
split from_context()'s **kwargs TypedDict so it no longer overlaps
with named parameters, annotate default_factory=dict fields with
their element types, replace the bare '' assigned to change_id (a
ChangeID | None) with pebble.ChangeID('').
- _runtime.py: replace deprecated Iterator return type with Generator,
parameterize TemporaryDirectory, normalise Optional unit_id.
- _consistency_checker.py: cast action spec lookups through Any so
pyright can resolve get()/items() types.
- _ops_main_mock.py: initialise loop variable before the try block so
the except branch never sees an unbound name.
Refs canonical#2613
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Follow-up to the TypedDict rename in from_context(): update the nitpick_ignore entry so the docs build stays clean. Refs canonical#2613 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
The type annotation was simplified to Sequence[Address], and Sphinx correctly resolves it to ops.testing.Address, so the comment about prefixing is no longer accurate. Refs canonical#2613 Co-Authored-By: Claude Opus 4.7 <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.
The pyright
includeglobtesting/src/*.pydid not match the subdirectory where the scenario source actually lives (testing/src/scenario/*.py), so that tree was silently unchecked 😞 😢. Add the correct glob and fix the 122 (!) errors that surfaced.Highlights of the fixes:
dict(x)instead of.copy()onMapping-typed state fields;castwhere the runtime is adictbut the annotation is intentionallyMapping(relation databags,remote_grants).type: ignorecomments and default the derivedapp_nameto''so the existing bad-metadata tests still exercise the downstream failure path.Mapping, splitfrom_context()'s**kwargsTypedDict so it no longer overlaps with named parameters, annotatedefault_factory=dictfields with their element types, and replace the bare''assigned toCheckInfo.change_id(ChangeID | None) withpebble.ChangeID('').Iteratorreturn type withGenerator, parameteriseTemporaryDirectory, normalise Optionalunit_id.Anyso pyright can resolveget()/items()types.tryso theexceptbranch never sees an unbound name.Refs #2613