-
-
Notifications
You must be signed in to change notification settings - Fork 818
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
docs: new for loop range syntax: bound=
#3540
docs: new for loop range syntax: bound=
#3540
Conversation
for i in range(..., bound=...)
Codecov Report
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. @@ Coverage Diff @@
## master #3540 +/- ##
==========================================
- Coverage 89.12% 88.97% -0.16%
==========================================
Files 86 86
Lines 11407 11460 +53
Branches 2595 2606 +11
==========================================
+ Hits 10166 10196 +30
- Misses 819 839 +20
- Partials 422 425 +3
... and 9 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
docs/control-structures.rst
Outdated
|
||
for i in range(min(stop, N), bound=N): | ||
... | ||
``stop`` can be any integer greater than zero. ``N`` must be a compile-time constant. ``i`` begins as zero and increments by one until it is equal to ``stop``. If ``stop`` is larger than ``N``, execution will revert at runtime. In certain cases, you may not have a guarantee that ``stop`` is less than ``N``, but still want to avoid the possibility of runtime reversion. To accomplish this, use the ``bound=`` keyword in combination with ``min()``, like ``range(min(stop, N), bound=N)``. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's zero will it raise? Or avoid the loop?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
``stop`` can be any integer greater than zero. ``N`` must be a compile-time constant. ``i`` begins as zero and increments by one until it is equal to ``stop``. If ``stop`` is larger than ``N``, execution will revert at runtime. In certain cases, you may not have a guarantee that ``stop`` is less than ``N``, but still want to avoid the possibility of runtime reversion. To accomplish this, use the ``bound=`` keyword in combination with ``min()``, like ``range(min(stop, N), bound=N)``. | |
``stop`` can be any integer greater than zero. ``N`` must be a compile-time constant. ``i`` begins as zero and increments by one until it is equal to ``stop``. If ``stop`` is larger than ``N``, execution will revert at runtime. In certain cases, you may not have a guarantee that ``stop`` is less than ``N``, but still want to avoid the possibility of runtime reversion. To accomplish this, use the ``bound=`` keyword in combination with ``min(stop, N)`` as the argument to ``range``, like ``range(min(stop, N), bound=N)``. This is helpful for use cases like chunking up operations on larger arrays across multiple transactions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's zero will it raise? Or avoid the loop?
Sorry @charles-cooper, made two comments at once here lol
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's zero will it raise? Or avoid the loop?
it will skip the loop. again, this is clear in the tests from the implementing PR d48438e#diff-c3f9a43de8dca93393504fef8b3c6bd8c77a6be969ee749f59b49537285e6392R27 but i've updated it to be just a little more clear in b613cb9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can add that note to the docs too?
Co-authored-by: El De-dog-lo <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is how the current docs look like:
IMO the start of the entire block with for i in range(stop, bound=N):
is confusing since there is no introduction but just simply starts with a code block.
We should have something like:
Furthermore, the
range
function allows for thekwarg
bound
in order to use ranges with max bounds:
for i in range(stop, bound=N):
...
[The rest of the text]
bound=
for i in range(..., bound=...)
What I did
How I did it
How to verify it
Commit message
Commit message for the final, squashed PR. (Optional, but reviewers will appreciate it! Please see our commit message style guide for what we would ideally like to see in a commit message.)
Description for the changelog
Cute Animal Picture