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

Use proper assertion. #391

Closed
wants to merge 1 commit into from
Closed

Conversation

Carreau
Copy link
Member

@Carreau Carreau commented Jan 30, 2024

An "AssertionError" message is not that useful, at least here you will see that this is because the object passed in is not a coroutine...

An "AssertionError" message is not that useful, at least here you will
see that this is because the object passed in is not a coroutine...
@@ -144,8 +144,7 @@ def run_sync(coro: Callable[..., Awaitable[T]]) -> Callable[..., T]:
Whatever the coroutine-function returns.
"""

if not inspect.iscoroutinefunction(coro):
raise AssertionError
assert inspect.iscoroutinefunction(coro)
Copy link
Member

Choose a reason for hiding this comment

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

Python's optimize mode will ignore assert statements.

Suggested change
assert inspect.iscoroutinefunction(coro)
if not inspect.iscoroutinefunction(coro):
raise AssertionError(f"Not a coroutine function: {coro}")

Copy link
Member Author

Choose a reason for hiding this comment

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

👎 This should never happen anyway, if someone pass invalid values while in optimized mode they likely do not want to pay the cost of assert.

Plus below it's also doing wrapped.__doc__ = coro.__doc__ which also make no sens in optimized mode.

If you want to raise something in an if like that, then it should be a TypeError or ValueError, not an assertion.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ping on this. Failure seem unrelated.

@Carreau Carreau closed this Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants