You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thanks to the Litellm team for the fast responses and the pace of improvements. It has been great to see issues get triaged and fixed so quickly. Since typing is already enforced in CI through mypy, I wanted to raise a pattern that seems to be slipping past static analysis and causing some of the recent regressions.
The issue in #19486 is a good example. The fix updated the usage field type on ResponsesAPIResponse replacing ResponseAPIUsage with Any. The earlier regression came from using dynamic attribute assignment like this:
setattr(x, "usage", y)
instead of using typed assignment:
x.usage=y
When code uses setattr, mypy cannot validate that y matches the expected type. This makes it easier for type mismatches to land even though mypy is already running in CI. I have also noticed similar patterns in version 1.81.1 that appear to have the same root issue, where typed objects are mutated dynamically rather than through their declared fields.
It would help code quality long term if litellm devs could rely more heavily on typed attribute access and reduce usage of setattr and getattr when the object already has a defined schema. This would let the existing CI typing do more of the work and prevent issues like #19486 before they show up downstream.
If the core team is open to it, I am happy to help with PRs that strengthens types and removes dynamic mutation in places where it is unnecessary.
Thanks again for all the work on this project. It continues to improve quickly, and I think leaning into typing even more will make future refactors safer and easier.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Thanks to the Litellm team for the fast responses and the pace of improvements. It has been great to see issues get triaged and fixed so quickly. Since typing is already enforced in CI through mypy, I wanted to raise a pattern that seems to be slipping past static analysis and causing some of the recent regressions.
The issue in #19486 is a good example. The fix updated the
usagefield type onResponsesAPIResponsereplacingResponseAPIUsagewithAny. The earlier regression came from using dynamic attribute assignment like this:instead of using typed assignment:
When code uses
setattr, mypy cannot validate thatymatches the expected type. This makes it easier for type mismatches to land even though mypy is already running in CI. I have also noticed similar patterns in version 1.81.1 that appear to have the same root issue, where typed objects are mutated dynamically rather than through their declared fields.It would help code quality long term if litellm devs could rely more heavily on typed attribute access and reduce usage of
setattrandgetattrwhen the object already has a defined schema. This would let the existing CI typing do more of the work and prevent issues like #19486 before they show up downstream.If the core team is open to it, I am happy to help with PRs that strengthens types and removes dynamic mutation in places where it is unnecessary.
Thanks again for all the work on this project. It continues to improve quickly, and I think leaning into typing even more will make future refactors safer and easier.
Beta Was this translation helpful? Give feedback.
All reactions