-
Notifications
You must be signed in to change notification settings - Fork 747
MAINT: enable strict mypy checking and fix violations #1515
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
romanlutz
merged 35 commits into
microsoft:main
from
tejas0077:maint/fix-mypy-type-definitions
Apr 22, 2026
Merged
Changes from 10 commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
336fa28
feat: add ISO 42001 aligned harm definitions for AI supply chain, tra…
cbdc28a
feat: register ISO 42001 harm scales in LikertScalePaths enum
f3df706
maint: fix untyped decorator mypy error in net_utility.py
0a2c006
maint: fix remaining strict mypy errors in common and models
7eb7753
maint: fix all remaining strict mypy errors across full pyrit codebase
c76c8e0
maint: enable strict mypy and fix all type errors across codebase
d7362be
maint: remove stray yaml files accidentally included from another branch
429de21
Merge branch 'main' into maint/fix-mypy-type-definitions
romanlutz 6fcada4
maint: address Copilot review comments on strict mypy PR
9bc3c6c
maint: fix all strict mypy errors across entire pyrit codebase
a229059
maint: replace assert guards with explicit if/raise for python -O safety
0d11e3f
Merge remote-tracking branch 'origin/main' into pr-1515-review
romanlutz d9948ba
fix: keep Message return type for send_prompt_async, raise EmptyRespo…
romanlutz 555ed62
fix: address review findings across PR
romanlutz 4808e3b
fix: resolve all 56 strict mypy errors across 21 files
romanlutz fa5c6e3
fix: replace asserts with RuntimeError raises in product code
romanlutz 0a1d990
Merge remote-tracking branch 'origin/main' into pr-1515-review
romanlutz afa8632
fix: move CentralMemory import to top of display_response.py
romanlutz ba4c362
fix: preserve callable api_key in OpenAITextEmbedding
romanlutz 0ea0d7a
fix: eliminate dead-code guards in storage_io.py
romanlutz db3ed0c
fix: handle empty response list for write-only targets like TextTarget
romanlutz b49bd4a
fix: remove unused _client property from OpenAITarget
romanlutz bc5180d
Merge remote-tracking branch 'origin/main' into pr-1515-review
romanlutz 0c47165
fix: restore _client property and fix test failures
romanlutz dcdb7b5
Merge remote-tracking branch 'origin/main' into pr-1515-review
romanlutz fb30bde
fix: add mypy override for hugging_face untyped transformers calls
romanlutz 3079f54
fix: add pragma no cover to mypy type-narrowing guards for diff coverage
romanlutz 551140d
Merge origin/main (removing ui/rpc modules)
romanlutz 29234bf
fix: replace pragma no cover with proper unit tests for type guards
romanlutz 28f7ecd
fix: resolve pre-commit lint errors and add tests for diff coverage
romanlutz f57c2f9
Merge remote-tracking branch 'origin/main' into maint/fix-mypy-type-d…
romanlutz 8a9127f
fix: mock playwright via sys.modules to avoid CI import error
romanlutz eabe488
fix: apply ruff format and fix mypy union-attr in data_url_converter
romanlutz 9a786df
fix: apply ruff format to merge-affected test files
romanlutz eed971c
fix: remove unused FloatScaleScorer import in test
romanlutz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,52 +1,54 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT license. | ||
|
|
||
| import io | ||
| import logging | ||
|
|
||
| from PIL import Image | ||
|
|
||
| from pyrit.common.notebook_utils import is_in_ipython_session | ||
| from pyrit.models import AzureBlobStorageIO, DiskStorageIO, MessagePiece | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| async def display_image_response(response_piece: MessagePiece) -> None: | ||
| """ | ||
| Display response images if running in notebook environment. | ||
|
|
||
| Args: | ||
| response_piece (MessagePiece): The response piece to display. | ||
| """ | ||
| from pyrit.memory import CentralMemory | ||
|
|
||
| memory = CentralMemory.get_memory_instance() | ||
| if ( | ||
| response_piece.response_error == "none" | ||
| and response_piece.converted_value_data_type == "image_path" | ||
| and is_in_ipython_session() | ||
| ): | ||
| image_location = response_piece.converted_value | ||
|
|
||
| try: | ||
| image_bytes = await memory.results_storage_io.read_file(image_location) | ||
| except Exception as e: | ||
| if isinstance(memory.results_storage_io, AzureBlobStorageIO): | ||
| try: | ||
| # Fallback to reading from disk if the storage IO fails | ||
| image_bytes = await DiskStorageIO().read_file(image_location) | ||
| except Exception as exc: | ||
| logger.error(f"Failed to read image from {image_location}. Full exception: {str(exc)}") | ||
| return | ||
| else: | ||
| logger.error(f"Failed to read image from {image_location}. Full exception: {str(e)}") | ||
| return | ||
|
|
||
| image_stream = io.BytesIO(image_bytes) | ||
| image = Image.open(image_stream) | ||
|
|
||
| # Jupyter built-in display function only works in notebooks. | ||
| display(image) # type: ignore[name-defined] # noqa: F821 | ||
| if response_piece.response_error == "blocked": | ||
| logger.info("---\nContent blocked, cannot show a response.\n---") | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT license. | ||
|
|
||
| import io | ||
| import logging | ||
|
|
||
| from PIL import Image | ||
|
|
||
| from pyrit.common.notebook_utils import is_in_ipython_session | ||
| from pyrit.models import AzureBlobStorageIO, DiskStorageIO, MessagePiece | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| async def display_image_response(response_piece: MessagePiece) -> None: | ||
| """ | ||
| Display response images if running in notebook environment. | ||
|
|
||
| Args: | ||
| response_piece (MessagePiece): The response piece to display. | ||
| """ | ||
| from pyrit.memory import CentralMemory | ||
|
|
||
| memory = CentralMemory.get_memory_instance() | ||
| if ( | ||
| response_piece.response_error == "none" | ||
| and response_piece.converted_value_data_type == "image_path" | ||
| and is_in_ipython_session() | ||
| ): | ||
| image_location = response_piece.converted_value | ||
|
|
||
| try: | ||
| if memory.results_storage_io is None: | ||
| raise RuntimeError("Storage IO not initialized") | ||
| image_bytes = await memory.results_storage_io.read_file(image_location) | ||
| except Exception as e: | ||
| if isinstance(memory.results_storage_io, AzureBlobStorageIO): | ||
| try: | ||
| # Fallback to reading from disk if the storage IO fails | ||
| image_bytes = await DiskStorageIO().read_file(image_location) | ||
| except Exception as exc: | ||
| logger.error(f"Failed to read image from {image_location}. Full exception: {str(exc)}") | ||
| return | ||
| else: | ||
| logger.error(f"Failed to read image from {image_location}. Full exception: {str(e)}") | ||
| return | ||
|
|
||
| image_stream = io.BytesIO(image_bytes) | ||
| image = Image.open(image_stream) | ||
|
|
||
| # Jupyter built-in display function only works in notebooks. | ||
| display(image) # type: ignore[name-defined] # noqa: F821 | ||
| if response_piece.response_error == "blocked": | ||
| logger.info("---\nContent blocked, cannot show a response.\n---") |
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.