Repository navigation
MAINT: Type ScenarioRunSizeEstimate.unavailable with Self - #3520
Open
Niladri Das (bniladridas) wants to merge 1 commit into
Open
Niladri Das (bniladridas) wants to merge 1 commit into
Niladri Das (bniladridas) wants to merge 1 commit into
Conversation
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>
Author
|
@microsoft-github-policy-service agree |
This branch has not been deployed
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.
Description
Part of #3166 (item P311-01, the
ScenarioRunSizeEstimate.unavailablefocused case).ScenarioRunSizeEstimate.unavailableinpyrit/models/catalog/scenario.pybuilds its return value withcls(...)but annotates the result as the concreteScenarioRunSizeEstimate. 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 atyping.Selfreturn on same-concrete-class factories.The annotation on
unavailablebecomestyping.Self.cls(...)construction, the note default, thedataset_sizeanddataset_limitfallbacks, 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.pyadds_CustomRunSizeEstimateand two tests in the style of MAINT: Type adversarial placeholder factory with Self #3411: a subclass test assertingtype(estimate) is _CustomRunSizeEstimatewithtyping.assert_typeregression coverage, and a dataset passthrough test preserving an explicitdataset_sizeanddataset_limit(withDatasetLimitState.Valueandvalue=3matching the realDatasetLimitInputfield contract), including the factory's unavailable-modedataset_sizeanddataset_limitfallbacks. Existing tests already cover the note and count defaults throughtest_unavailable_run_size_estimate_has_no_countand unavailable-mode validation throughtest_non_exact_run_size_rejects_total[Unavailable],test_non_conditional_run_size_rejects_condition[Unavailable], andtest_unavailable_run_size_rejects_numeric_values.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 checkandruff format --checkclean;ty checkclean, verified meaningful through a deliberately brokenassert_typethattyreported as a diagnostic before being restored.