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

PYTHON-4781 Handle errors on Async PyMongo import #1873

Merged
merged 2 commits into from
Sep 20, 2024

Conversation

blink1073
Copy link
Member

No description provided.

# PYTHON-4781: Importing asyncio can fail on Windows.
import warnings

warnings.warn(f"Failed to import Async PyMongo: {e}", RuntimeWarning, stacklevel=2)
Copy link
Member

Choose a reason for hiding this comment

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

  1. Should we use ImportWarning instead?

ImportWarning: Base category for warnings triggered during the process of importing a module (ignored by default).

  1. Suggest {e!r} to provide the repr which will include the exception class instead of just the message.

  2. Suggest import warnings as _warnings to avoid polluting the pymongo namespace.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@ShaneHarvey
Copy link
Member

Will this cause type errors now that AsyncMongoClient is not always defined?

@blink1073
Copy link
Member Author

Will this cause type errors now that AsyncMongoClient is not always defined?

Perhaps on a system where importing asyncio is broken, but that system would have more concerning problems.

@blink1073 blink1073 merged commit e03f8f2 into mongodb:master Sep 20, 2024
33 checks passed
@blink1073 blink1073 deleted the PYTHON-4781 branch September 20, 2024 21:51
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