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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

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.

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