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

Fix load_module wrapping #3948

Merged
merged 4 commits into from
Mar 23, 2021
Merged

Conversation

balopat
Copy link
Contributor

@balopat balopat commented Mar 21, 2021

For old type (g3) module loaders, the resolution wasn't working, breaking internal par tests.

This makes DeprecatedModuleLoader.load_module work similarly to exec_module that it ensures that when the old module is loaded, both the new and old names are pointing to the same module in the module cache.

cc @cduck - this should be straightforward. The reason it didn't come up earlier, as I haven't tested on g3 since my change in #3917 (comment) - I think that more principled rewiring surfaced this bug :)

@balopat balopat requested review from cduck, vtomole and a team as code owners March 21, 2021 19:09
@google-cla google-cla bot added the cla: yes Makes googlebot stop complaining. label Mar 21, 2021
@balopat
Copy link
Contributor Author

balopat commented Mar 22, 2021

@cduck I hope this might be the last of these - if you have the chance I'd appreciate your input!

Copy link
Collaborator

@cduck cduck left a comment

Choose a reason for hiding this comment

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

LGTM with comments. What's the current style guide on single vs. double quote strings?

cirq/_compat.py Outdated
sys.modules[self.old_module_name] = sys.modules[self.new_module_name]
return sys.modules[self.old_module_name]
method(self.new_module_name)
assert self.new_module_name in sys.modules
Copy link
Collaborator

Choose a reason for hiding this comment

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

Needs an error message.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added, with a link to the specs where the expectation is coming from

@@ -679,19 +680,69 @@ def exec_module(self, module: ModuleType) -> None:
assert 'new' not in sys.modules


def test_loader_wrappers():
def test_loader_create_module():
class EmptyLoader:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add comment why this purposefully does not subclass importlib.abc.Loader.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh, good catch, actually, it can be a subclass of Loader, I added that in.

@balopat balopat added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Mar 23, 2021
@CirqBot CirqBot added the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label Mar 23, 2021
@CirqBot CirqBot merged commit 51dc096 into quantumlib:master Mar 23, 2021
@CirqBot CirqBot removed automerge Tells CirqBot to sync and merge this PR. (If it's running.) front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. labels Mar 23, 2021
@balopat
Copy link
Contributor Author

balopat commented Mar 23, 2021

What's the current style guide on single vs. double quote strings?

Hmmm sorry I didn't catch this before merging.

We don't have explicit guidance, so probably the Google Style Guide applies here: https://google.github.io/styleguide/pyguide.html#310-strings

Be consistent with your choice of string quote character within a file. Pick ' or " and stick with it. It is okay to use the other quote character on a string to avoid the need to \ escape within the string.

Yes:

  Python('Why are you hiding your eyes?')
  Gollum("I'm scared of lint errors.")
  Narrator('"Good!" thought a happy Python reviewer.')

No:

  Python("Why are you hiding your eyes?")
  Gollum('The lint. It burns. It burns us.')
  Gollum("Always the great lint. Watching. Watching.")

Prefer """ for multi-line strings rather than '''. Projects may choose to use ''' for all non-docstring multi-line strings if and only if they also use ' for regular strings. Docstrings must use """ regardless.

I guess it would be useful to add this to our style guide explicitly and maybe also do a check across the codebase.

@95-martin-orion
Copy link
Collaborator

I guess it would be useful to add this to our style guide explicitly and maybe also do a check across the codebase.

black auto-formats to double-quotes unless explictly told not to: docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Makes googlebot stop complaining.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants