diff --git a/qiskit/utils/__init__.py b/qiskit/utils/__init__.py index a0992fa2745c..3aa70917c1ac 100644 --- a/qiskit/utils/__init__.py +++ b/qiskit/utils/__init__.py @@ -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 diff --git a/qiskit/utils/deprecation.py b/qiskit/utils/deprecation.py index 14938bc88dbf..1a73803ab4f3 100644 --- a/qiskit/utils/deprecation.py +++ b/qiskit/utils/deprecation.py @@ -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.""" @@ -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 diff --git a/releasenotes/notes/remove-manual-warning-filters-028646b73bb86860.yaml b/releasenotes/notes/remove-manual-warning-filters-028646b73bb86860.yaml new file mode 100644 index 000000000000..eb25d1a20336 --- /dev/null +++ b/releasenotes/notes/remove-manual-warning-filters-028646b73bb86860.yaml @@ -0,0 +1,11 @@ +--- +upgrade: + - | + An internal filter override that caused all Qiskit deprecation warnings to be displayed has been removed. + This means that the behaviour will now revert to the standard Python behaviour for deprecations; you should only see a ``DeprecationWarning`` if it was triggered by code in the main script file, interpreter session or Jupyter notebook. + The user will no longer be blamed with a warning if internal Qiskit functions call deprecated behaviour. + If you write libraries, you should occasionally run with the default warning filters disabled, or have tests which always run with them disabled. + - | + Certain warnings used to be only issued once, even if triggered from multiple places. + This behaviour has been removed, so it is possible that if you call deprecated functions, you may see more warnings than you did before. + You should change any deprecated function calls to the suggested versions, because the deprecated forms will be removed in future Qiskit releases.