Skip to content
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

Remove cocotb.coroutine and yield syntax #3509

Merged
merged 3 commits into from Nov 20, 2023

Conversation

ktbarrett
Copy link
Member

Closes #1967.

Copy link

codecov bot commented Nov 14, 2023

Codecov Report

Attention: 6 lines in your changes are missing coverage. Please review.

Comparison is base (32b8581) 66.89% compared to head (64f0f43) 66.53%.
Report is 2 commits behind head on master.

Files Patch % Lines
src/cocotb/task.py 42.85% 2 Missing and 2 partials ⚠️
src/cocotb/decorators.py 83.33% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3509      +/-   ##
==========================================
- Coverage   66.89%   66.53%   -0.36%     
==========================================
  Files          49       49              
  Lines        8457     8429      -28     
  Branches     2384     2378       -6     
==========================================
- Hits         5657     5608      -49     
- Misses       1689     1705      +16     
- Partials     1111     1116       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ktbarrett ktbarrett requested a review from a team November 14, 2023 04:15
@ktbarrett ktbarrett marked this pull request as ready for review November 14, 2023 04:15
@ktbarrett
Copy link
Member Author

#3461 will remove the two lines that aren't covered.

@marlonjames
Copy link
Contributor

Task.__init__() should remove this and let the TypeError be raised, right? The error message on that needs to be cleaned up as well, it still references yield.

elif inspect.isgenerator(inst):
self._natively_awaitable = False

I think it's safe to remove the generator support from walk_coro_stack() with this change:

cocotb/src/cocotb/utils.py

Lines 288 to 305 in 32b8581

def walk_coro_stack(coro):
"""Walk down the coroutine stack, starting at *coro*.
Supports coroutines and generators.
"""
while coro is not None:
try:
f = getattr(coro, "cr_frame")
coro = coro.cr_await
except AttributeError:
try:
f = getattr(coro, "gi_frame")
coro = coro.gi_yieldfrom
except AttributeError:
f = None
coro = None
if f is not None:
yield (f, f.f_lineno)

And I think a newsfragment is needed for this as well, similar to #3425

Copy link
Contributor

@marlonjames marlonjames left a comment

Choose a reason for hiding this comment

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

The only thing left is the TypeError message in Task.__init__(). Now is a good time to update it but it could be left for later cleanup.

        else:
            raise TypeError(
                f"{inst} isn't a valid coroutine! Did you forget to use the yield keyword?"
            )

src/cocotb/task.py Outdated Show resolved Hide resolved
@ktbarrett ktbarrett merged commit 3519c83 into cocotb:master Nov 20, 2023
23 checks passed
@ktbarrett ktbarrett deleted the remove-cocotb.coroutine branch November 20, 2023 16:35
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.

Deprecate cocotb.coroutine and generator-based coroutine support
3 participants