Skip to content

typing: Fix ty invalid-attribute-override on SPSMapping - #828

Merged
ValerianRey merged 1 commit into
SimplexLab:mainfrom
Muhtasim-Munif-Fahim:fix/ty-sps-mapping-override
Oct 11, 2026
Merged

ValerianRey merged 1 commit into
SimplexLab:mainfrom
Muhtasim-Munif-Fahim:fix/ty-sps-mapping-override

Conversation

@Muhtasim-Munif-Fahim

Copy link
Copy Markdown
Contributor

Fixes #827.

Why ty fails

WithSPSMappingMixin declared a nested abstract class SPSMapping. QuadraticFunction and ElementWiseQuadratic each declared their own nested class 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. So uv run ty check reports two invalid-attribute-override errors in tests/trajectories/_objectives.py.

Fix

I fixed the code rather than ignoring the error. The abstract SPSMapping is now a module-level class, and the two implementations are module-level subclasses (QuadraticSPSMapping and ElementWiseQuadraticSPSMapping). Nothing overrides a nested class anymore. The sps_mapping properties return the same objects as before, so _pareto_utils.py, plot_params.py and plot_values.py don't change. Only tests/trajectories/_objectives.py is touched, so there's no changelog entry.

Checks

  • uv run ty check: 2 diagnostics before, "All checks passed!" after
  • pre-commit run on the file: all hooks pass (ruff check / ruff format included)
  • smoke check: QuadraticFunction(...).sps_mapping(w) and ElementWiseQuadratic(2).sps_mapping(w) give the same values as before, and sample_2d_spss(objective) still runs

AI assistance was used to help find the cause, write the patch, and run tests; I reviewed the change and can answer questions about it.

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
@Muhtasim-Munif-Fahim
Muhtasim-Munif-Fahim requested a review from a team as a code owner October 11, 2026 03:06
@ValerianRey ValerianRey added the cc: typing Conventional commit type for improvements to typing. label Oct 11, 2026
@github-actions github-actions Bot changed the title test(trajectories): Fix ty invalid-attribute-override on SPSMapping typing: Fix ty invalid-attribute-override on SPSMapping Oct 11, 2026
@ValerianRey

Copy link
Copy Markdown
Member

This seems much better! Thanks for the contribution :)

@ValerianRey
ValerianRey merged commit be57b28 into SimplexLab:main Oct 11, 2026
19 of 20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cc: typing Conventional commit type for improvements to typing.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ty checks fail

2 participants