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

Remove overrides of standard warning behaviour #7204

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 0 additions & 1 deletion qiskit/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
"""

from .quantum_instance import QuantumInstance
from .deprecation import _filter_deprecation_warnings
from .deprecation import deprecate_arguments
from .deprecation import deprecate_function
from .multiprocessing import local_hardware_info
Expand Down
41 changes: 1 addition & 40 deletions qiskit/utils/deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,44 +13,9 @@
"""Deprecation utilities"""

import functools
import re
import warnings


def _filter_deprecation_warnings():
"""Apply filters to deprecation warnings.

Force the `DeprecationWarning` warnings to be displayed for the qiskit
module, overriding the system configuration as they are ignored by default
[1] for end-users. Additionally, silence the `ChangedInMarshmallow3Warning`
messages.

TODO: on Python 3.7, this might not be needed due to PEP-0565 [2].

[1] https://docs.python.org/3/library/warnings.html#default-warning-filters
[2] https://www.python.org/dev/peps/pep-0565/
"""
deprecation_filter = (
"default",
None,
DeprecationWarning,
re.compile(r"^qiskit\.*", re.UNICODE),
0,
)

# Instead of using warnings.simple_filter() directly, the internal
# _add_filter() function is used for being able to match against the
# module.
try:
warnings._add_filter(*deprecation_filter, append=False)
except AttributeError:
# ._add_filter is internal and not available in some Python versions.
pass


_filter_deprecation_warnings()


def deprecate_arguments(kwarg_map):
"""Decorator to automatically alias deprecated argument names and warn upon use."""

Expand Down Expand Up @@ -80,13 +45,9 @@ def deprecate_function(msg, stacklevel=2):
def decorator(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
# warn only once
if not wrapper._warned:
warnings.warn(msg, DeprecationWarning, stacklevel=stacklevel)
wrapper._warned = True
warnings.warn(msg, DeprecationWarning, stacklevel=stacklevel)
return func(*args, **kwargs)

wrapper._warned = False
return wrapper

return decorator
Expand Down