Skip to content

Revert "Revert "Allow asyncio API to be imported as grpc.aio""#24341

Merged
lidizheng merged 4 commits intomasterfrom
revert-24337-revert-24289-aio-import-dot
Oct 7, 2020
Merged

Revert "Revert "Allow asyncio API to be imported as grpc.aio""#24341
lidizheng merged 4 commits intomasterfrom
revert-24337-revert-24289-aio-import-dot

Conversation

@lidizheng
Copy link
Copy Markdown
Contributor

@lidizheng lidizheng commented Oct 6, 2020

Reverts #24337
Original #24289
Fixes #24281

  • Applied the fix suggested by Richard to prevent the import order issue if the gRPC module is in a cyclic import and the import path is renamed.
  • Also, removed the test case that executes "from grpc import aio", so the unit tests should cover the importing name "grpc.aio" correctly.

Internally, the OSS gRPC module is renamed to "_open_source_grpc", and will be imported in 2 steps: the import hack, the actual import. Checking package name works in this case.

If we use open source mode internally, the OSS gRPC module name stays "grpc", but still it will be imported in 2 steps: a no-op import, the actual import. The tests failed because the "aio" module tried to initiate itself after the "no-op" import and found "grpc" module to be empty.

So, the (brutal-force) solution is to check the file name to ensure when the import hack happened, don't import "aio" module in this file. The import of "aio" module will happen in the magical __init__.py (cl/335754366).

@lidizheng lidizheng added lang/Python release notes: no Indicates if PR should not be in release notes labels Oct 6, 2020
@lidizheng lidizheng marked this pull request as ready for review October 7, 2020 19:04
@lidizheng lidizheng requested a review from gnossen October 7, 2020 19:13
Copy link
Copy Markdown
Contributor

@gnossen gnossen left a comment

Choose a reason for hiding this comment

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

👍

@lidizheng lidizheng merged commit 89b3444 into master Oct 7, 2020
@stanley-cheung stanley-cheung deleted the revert-24337-revert-24289-aio-import-dot branch December 2, 2020 23:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lang/Python release notes: no Indicates if PR should not be in release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[python aio] AttributeError: module 'grpc' has no attribute 'aio'

2 participants