Skip to content

Fix: Clarify random_number function docstring for inclusive range #1475

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 14, 2025

Conversation

Abbas-Asad
Copy link
Contributor

Summary

Fixed an ambiguous docstring in the random_number function (in lifecycle_example.py) that could lead to confusion about whether the range is inclusive or exclusive of the maximum value.

Problem

The random_number function docstring was ambiguous, using "up to the provided maximum" which could be interpreted as either inclusive or exclusive of the maximum value.

The implementation correctly uses random.randint(0, max) which generates numbers from 0 to max inclusive, matching the expected behavior based on usage in the example.

Changes Made

Changed the docstring from:

"Generate a random number up to the provided maximum."

To:

"Generate a random number from 0 to max (inclusive)."

This makes the behavior explicit and eliminates potential confusion for developers using this function.

… lifecycle_example.py)

## Summary

Fixed an ambiguous docstring in the `random_number` function that could lead to confusion about whether the range is inclusive or exclusive of the maximum value.

## Problem

The random_number function docstring was ambiguous, using "up to the provided maximum" which could be interpreted as either inclusive or exclusive of the maximum value.

The implementation correctly uses `random.randint(0, max)` which generates numbers from 0 to max inclusive, matching the expected behavior based on usage in the example.

## Changes Made

Changed the docstring from:
```python
"Generate a random number up to the provided maximum."
```

To:
```python
"Generate a random number from 0 to max (inclusive)."
```

This makes the behavior explicit and eliminates potential confusion for developers using this function.
@bruce-lakin
Copy link

A vital improvement. Ambiguity in docstrings, especially in helper functions like this, can have far-reaching consequences. It's good to see this kind of issue being addressed with the seriousness it deserves.

@seratch seratch added the documentation Improvements or additions to documentation label Aug 14, 2025
@seratch seratch merged commit cec3a9a into openai:main Aug 14, 2025
6 checks passed
vcshih pushed a commit to veris-ai/openai-agents-python that referenced this pull request Aug 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants