Repository navigation
typing: Fix ty invalid-attribute-override on SPSMapping - #828
Merged
ValerianRey merged 1 commit intoOct 11, 2026
Merged
ValerianRey merged 1 commit into
ValerianRey merged 1 commit into
Conversation
Recent ty versions (0.0.86 here) reject a nested class that overrides a nested class of a base class: the nested `SPSMapping` of `QuadraticFunction` and `ElementWiseQuadratic` is a new class object, and ty checks it against the class object declared on `WithSPSMappingMixin`, so `uv run ty check` fails with two invalid-attribute-override errors. Move the abstract `SPSMapping` to module level and make the two implementations module-level subclasses (`QuadraticSPSMapping` and `ElementWiseQuadraticSPSMapping`). The `sps_mapping` properties keep returning the same objects, so callers are unchanged. Fixes SimplexLab#827
ValerianRey
approved these changes
Oct 11, 2026
Member
|
This seems much better! Thanks for the contribution :) |
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.
Fixes #827.
Why ty fails
WithSPSMappingMixindeclared a nested abstract classSPSMapping.QuadraticFunctionandElementWiseQuadraticeach declared their own nestedclass SPSMapping(WithSPSMappingMixin.SPSMapping). A nested class is a class attribute whose type is that exact class object. Recent ty versions (0.0.86 here) check attribute overrides, and the subclass's class object isn't assignable to the parent's class-literal type. Souv run ty checkreports twoinvalid-attribute-overrideerrors intests/trajectories/_objectives.py.Fix
I fixed the code rather than ignoring the error. The abstract
SPSMappingis now a module-level class, and the two implementations are module-level subclasses (QuadraticSPSMappingandElementWiseQuadraticSPSMapping). Nothing overrides a nested class anymore. Thesps_mappingproperties return the same objects as before, so_pareto_utils.py,plot_params.pyandplot_values.pydon't change. Onlytests/trajectories/_objectives.pyis touched, so there's no changelog entry.Checks
uv run ty check: 2 diagnostics before, "All checks passed!" afterpre-commit runon the file: all hooks pass (ruff check / ruff format included)QuadraticFunction(...).sps_mapping(w)andElementWiseQuadratic(2).sps_mapping(w)give the same values as before, andsample_2d_spss(objective)still runsAI assistance was used to help find the cause, write the patch, and run tests; I reviewed the change and can answer questions about it.