Skip to content

[FIX]: Fixup pyright Errors - #16

Merged
Spencer Schoenberg (spencrr) merged 11 commits into
mainfrom
spencrr/pyright-fixups
Apr 21, 2026
Merged

[FIX]: Fixup pyright Errors#16
Spencer Schoenberg (spencrr) merged 11 commits into
mainfrom
spencrr/pyright-fixups

Conversation

@spencrr

@spencrr Spencer Schoenberg (spencrr) commented Apr 17, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes all the changes introduced by adding pyright in #9.

Breaking changes

None

Checklist

  • pre-commit run --all-files passes
  • Tests added or updated for changes
  • Documentation updated

Spencer Schoenberg (spencrr) added a commit that referenced this pull request Apr 17, 2026
…nfig (#9)

## Description

Add project metadata, pyright, coverage config, and editorconfig

## Breaking changes
<!-- Does this PR introduce breaking changes? If so, describe the impact
and migration path. -->

None

## Checklist

- [ ] `pre-commit run --all-files` passes **No, see #16**
- [ ] Tests added or updated for changes <!-- Please describe what tests
were added or updated -->
- [ ] Documentation updated
Base automatically changed from spencrr/project-metadata to main April 17, 2026 08:53
@spencrr
Spencer Schoenberg (spencrr) requested a review from a team April 17, 2026 08:53
Comment thread tests/fixtures.py Dismissed
Comment thread rampart/_pyrit/llm_bridge.py Dismissed
Comment thread rampart/drivers/__init__.py
Comment thread rampart/_pyrit/llm_bridge.py Outdated
Comment thread rampart/drivers/__init__.py Outdated
Fix 13 pyright strict-mode errors across 7 files:

reportUnnecessaryIsInstance (3):
- response_contains.py: remove dead `not isinstance(target, Pattern)`
  guard — re.Pattern is not callable, so the branch is unreachable.
  Reorder to check callable() first.
- drivers/__init__.py: remove redundant isinstance(value, PromptDriver)
  — type narrowing already exhausts the union after str/Request/list.
- _session.py: suppress on ReportSink isinstance — intentional runtime
  guard at public API boundary for user-provided sinks.

reportPrivateUsage (2):
- Rename _coerce_driver to coerce_driver, extract to drivers/_utils.py.
  Update imports in attacks/__init__, probes/__init__.

reportMissingTypeArgument (1):
- response_contains.py: re.Pattern -> re.Pattern[str].

Also annotate tool_lines and source_lines as list[str] in manifest.py
(reportUnknownVariableType).
Replace bare field(default_factory=dict) and field(default_factory=list)
with typed lambdas (e.g. lambda: dict[str, Any]()) so pyright strict
can infer generic type parameters. Fixes all reportUnknownVariableType
errors in core data types.
Change **detail_predicates and **param_predicates from Any to
Any | Callable[[Any], bool] in SideEffectOccurred and ToolCalled.
Gives pyright visibility into the predicate union without breaking
existing call sites.
- plugin.py: validate rampart_sinks fixture with cast(list[object]) +
  per-element isinstance narrowing; annotate user_sinks_raw as object
- _session.py: remove redundant isinstance guard (caller now validates)
- llm_bridge.py: cast PyRIT untyped return to Message, suppress
  remaining untyped member access at PyRIT boundary
Include tests/ in pyright analysis with a separate executionEnvironment
that disables reportPrivateUsage, reportUnknownParameterType,
reportUnknownMemberType, reportUnknownArgumentType, and
reportUnknownVariableType. Uses extraPaths=["."] so tests can
resolve rampart imports.
Replace mypy-style type: ignore codes (e.g. [arg-type], [misc]) with
pyright-style pyright: ignore codes (e.g. [reportArgumentType],
[reportCallIssue]) across all test files. Ensures suppressions are
recognized by both pyright CLI and Pylance.
Comment thread rampart/drivers/_utils.py
Comment thread rampart/drivers/_utils.py

@nina-msft Nina Chikanov (nina-msft) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Some final comments on the utils func but the other changes look standard :)

Ran via `ruff check --preview --select CPY001`
@spencrr
Spencer Schoenberg (spencrr) merged commit 9f27b90 into main Apr 21, 2026
4 checks passed
@spencrr
Spencer Schoenberg (spencrr) deleted the spencrr/pyright-fixups branch April 22, 2026 04:48
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