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

assert_deprecated improvements #3919

Merged
merged 1 commit into from
Mar 16, 2021

Conversation

balopat
Copy link
Contributor

@balopat balopat commented Mar 15, 2021

Deprecates the allow_multiple_warnings parameter for explicit count.

Context: this is split out from #3917.

===== Release note ======

  • cirq.testing.assert_deprecate parameter allow_multiple_warnings is now deprecated and will be removed in Cirq v0.12. Please use instead count. For allow_multiple_warnings True, you can just use count=None, for False, count=1 which is the default value.

======================

@balopat balopat requested review from cduck, vtomole and a team as code owners March 15, 2021 22:36
@google-cla google-cla bot added the cla: yes Makes googlebot stop complaining. label Mar 15, 2021
@balopat balopat added kind/deprecation and removed cla: yes Makes googlebot stop complaining. labels Mar 15, 2021
@google-cla google-cla bot added the cla: yes Makes googlebot stop complaining. label Mar 15, 2021
@balopat balopat mentioned this pull request Mar 15, 2021
3 tasks
@balopat balopat added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Mar 16, 2021
@CirqBot CirqBot added the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label Mar 16, 2021
@CirqBot CirqBot merged commit 504d467 into quantumlib:master Mar 16, 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 16, 2021
CirqBot pushed a commit that referenced this pull request Mar 19, 2021
Introduces deprecated module reference. 

We are coming up to a couple of module refactors, e.g. `cirq.experiments` -> `cirq.qcvv` and `cirq.google` -> `cirq_google`.

With the functionality introduced here, we can achieve backwards compatible reference by adding a similar snippet to the one below to the original parent module's `__init__.py` file: 

```
from cirq import _compat 
_compat.deprecated_submodule(
    new_module_name="cirq.experiments",
    old_parent="cirq",
    old_child="qcvv",
    deadline="v0.20",
    create_attribute=True,
)
```

Callers of all types will get a single deprecation warning. 

Design doc: https://tinyurl.com/cirq-deep-aliasing

Extensive testing was done on the full `cirq.google` extraction - all the interesting edge cases  were captured as unit tests here.

Disclaimers: 
  - the tests need to run in a separate subprocess to ensure that the import system is unaffected (I tried resetting sys.modules, and all the other entry points as a pytest fixture, but it didn't really work due to some side-effects I couldn't figure out) - thus I rolled a mechanism that plays nicely within pytest, using multiprocessing.
  - there is a g3 specific problem with par files as there is a specific Loader used internally for which the wrapping had to be adjusted (see _compat.py:358) - testing this proved to be hard as one would have to create a legacy module loader which provenly works - but I couldn't. So here, the testing is internal only...
  - while user code will still execute, PyCharm and other IDEs will likely not recognize the deprecated module references - the deprecated submodules won't show up in code completion and will look like they don't exist. 
 
Beyond maintainer review, I will also get some python experts to look at this PR and provide feedback to get a bit more confidence that this is not completely unrecommended.

TODO: 
 - [x] fix CI (coverage needs to be worked out with the subprocess separation)
 - [x] split out improvements to the `cirq.testing.assert_deprecated` and `_warn_or_error` method to a separate PR (done #3919)
 - [x] get python expert review
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. kind/deprecation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants