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
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions jupyter_core/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.


def wrapped(*args: Any, **kwargs: Any) -> Any:
name = threading.current_thread().name
Expand Down
Loading