Skip to content

Fix CapacityLimiter(math.inf) raising TypeError outside an event loop - #1189

Merged
agronholm merged 4 commits into
agronholm:masterfrom
mahirhir:fix/capacity-limiter-adapter-accept-float-inf
Jun 26, 2026
Merged

agronholm merged 4 commits into
agronholm:masterfrom
mahirhir:fix/capacity-limiter-adapter-accept-float-inf

Conversation

@mahirhir

@mahirhir mahirhir commented Jun 26, 2026 •

Copy link
Copy Markdown
Contributor

Changes

Constructing CapacityLimiter(float('inf')) raises TypeError because the constructor validates with value is not math.inf (identity), while the backend setter correctly uses math.isinf. The two checks were aligned in #1183 for the setter path; the constructor path was the remaining gap.

The fix makes the constructor use the same isinf check. One line, and the full suite (183 tests) passes.

Checklist

If this is a user-facing code change, like a bugfix or a new feature, please ensure that
you've fulfilled the following conditions (where applicable):

  • You've added tests (in tests/) which would fail without your patch
  • You've updated the documentation (in docs/), in case of behavior changes or new
    features
  • You've added a new changelog entry (in docs/versionhistory.rst).

If this is a trivial change, like a typo fix or a code reformatting, then you can ignore
these instructions.

The adapter's total_tokens setter checked for infinity by identity
(value is not math.inf), so only the exact math.inf singleton passed;
float('inf') -- a distinct equal object and the idiomatic way to express
infinity -- raised TypeError outside a running event loop, while every
backend setter (math.isinf) accepts it. Align the adapter with the
backend by using math.isinf, mirroring _asyncio.py exactly.

@agronholm agronholm left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the PR link to the changelog entry. Otherwise this looks good.

@agronholm

Copy link
Copy Markdown
Owner

I also seems like you erased the checkboxes from PR template which you were explicitly told NOT to do.

@mahirhir

Copy link
Copy Markdown
Contributor Author

Sorry about the template, I've restored it with the checklist filled in. The PR link is now added to the changelog entry as well.

@agronholm agronholm left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

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