Skip to content

Refactor(Optimizer): improve typing coverage of optimizer modules#7446

Merged
georgesittas merged 21 commits intotobymao:mainfrom
OutSquareCapital:optimizer-annotations
Apr 6, 2026
Merged

Refactor(Optimizer): improve typing coverage of optimizer modules#7446
georgesittas merged 21 commits intotobymao:mainfrom
OutSquareCapital:optimizer-annotations

Conversation

@OutSquareCapital
Copy link
Copy Markdown
Contributor

Details

WIP

This is a work in progress. But since those files are very untyped ATM, it's better to split up in various passes. This is the first one, focusing on public level and simplify module.

datetime import

I changed the import datetime to from datetime import x, y, z. It's more concise when the datetime object are needed, but most importantly it's much less confusing.
Fault is on Python for sure for the API design, but since datetime is both a module and an object, and datetime.date can represent both a method and an object, IMO it's preferrable.

Partial typing

I skipped various methods/functions (or partially typed them like simplify_literals).
This is intentionnal. ATM there's various untypable behaviors, like "unsafe" non-none checks on Expr properties/args.
This would require changing the actual runtime behavior, which is out-of-scope here.

@OutSquareCapital
Copy link
Copy Markdown
Contributor Author

OutSquareCapital commented Apr 3, 2026

To clarify: the goal is to gradually add types, since optimizers as a whole is a lot more untyped than the rest of the codebase.
As such, this PR scope is:

  • fully type the public API (exported via __init__)
  • Fully type "easy" functions in the simplify module
  • Partially annotate complex blocks with hard-to-type structure like _simplify_comparison in the simplify module

The latter will be revisited in the future, hopefully with the help of more context.
This is precisely why object is a good fit most of the time: mypy don't check the body of untyped functions, and as such we can expect to be more precise as the typing coverage progress and mypy flag object has no attribute "x" problems

@georgesittas georgesittas merged commit c31e2e3 into tobymao:main Apr 6, 2026
8 checks passed
@OutSquareCapital OutSquareCapital deleted the optimizer-annotations branch April 6, 2026 11:53
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.

2 participants