Skip to content

MAINT: Type ScenarioRunSizeEstimate.unavailable with Self - #3520

Open
Niladri Das (bniladridas) wants to merge 1 commit into
microsoft:mainfrom
bniladridas:bniladridas/p311-01-run-size-self
Open

Niladri Das (bniladridas) wants to merge 1 commit into
microsoft:mainfrom
bniladridas:bniladridas/p311-01-run-size-self

Conversation

@bniladridas

Copy link
Copy Markdown

Description

Part of #3166 (item P311-01, the ScenarioRunSizeEstimate.unavailable focused case).

ScenarioRunSizeEstimate.unavailable in pyrit/models/catalog/scenario.py builds its return value with cls(...) but annotates the result as the concrete ScenarioRunSizeEstimate. A subclass calling the factory gets an object of its own class while the checker sees the base type, and the factory family convention established in #3194, #3201, #3266, #3383, #3411, and #3470 is a typing.Self return on same-concrete-class factories.

The annotation on unavailable becomes typing.Self. cls(...) construction, the note default, the dataset_size and dataset_limit fallbacks, and both validators are unchanged. A subclass now sees its own type where it saw the concrete base type before.

Tests and Documentation

  • tests/unit/models/test_scenario_catalog.py adds _CustomRunSizeEstimate and two tests in the style of MAINT: Type adversarial placeholder factory with Self #3411: a subclass test asserting type(estimate) is _CustomRunSizeEstimate with typing.assert_type regression coverage, and a dataset passthrough test preserving an explicit dataset_size and dataset_limit (with DatasetLimitState.Value and value=3 matching the real DatasetLimitInput field contract), including the factory's unavailable-mode dataset_size and dataset_limit fallbacks. Existing tests already cover the note and count defaults through test_unavailable_run_size_estimate_has_no_count and unavailable-mode validation through test_non_exact_run_size_rejects_total[Unavailable], test_non_conditional_run_size_rejects_condition[Unavailable], and test_unavailable_run_size_rejects_numeric_values.
  • Validation on macOS arm64, CPU only: uv sync --group dev; pytest tests/unit/models/test_scenario_catalog.py tests/unit/backend/test_scenario_preset_service.py (61 passed) plus 260 passed across five other test modules exercising these models; ruff check and ruff format --check clean; ty check clean, verified meaningful through a deliberately broken assert_type that ty reported as a diagnostic before being restored.
  • JupyText: not applicable. No documentation notebooks or code samples changed; the docstring is untouched.
  • Documentation: none needed. Annotation-level change with no behavioral difference; the docstring already describes the result.

The unavailable factory of ScenarioRunSizeEstimate builds its return value
with cls(...) but annotates the result as the concrete
ScenarioRunSizeEstimate. Annotate the return with typing.Self so a caller
that subclasses the estimate sees its own type in the checker, instead of a
checker-proven reference to the base class. cls(...) construction, the note
default, the dataset_size and dataset_limit fallbacks, and both validators
are unchanged.

Add a subclass regression test with typing.assert_type coverage, and
preserve the factory's dataset size and limit passthrough plus its
unavailable-mode fallbacks in test coverage.

Signed-off-by: Niladri Das <125604915+bniladridas@users.noreply.github.com>
@bniladridas

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

This branch has not been deployed

No deployments
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.

1 participant