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 warning on __qiskit_version__ (backport #10686) #10688

Merged
merged 1 commit into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
16 changes: 9 additions & 7 deletions qiskit/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,23 @@ class QiskitVersion(Mapping):
__slots__ = ["_version_dict", "_loaded"]

def __init__(self):
self._version_dict = {
"qiskit-terra": __version__,
"qiskit": None,
}
self._loaded = False

def _load_versions(self):
warnings.warn(
"qiskit.__qiskit_version__ is deprecated since "
"Qiskit Terra 0.25.0, and will be removed 3 months or more later. "
"Instead, you should use qiskit.__version__. The other packages listed in "
"Instead, you should use qiskit.__version__. The other packages listed in the"
"former qiskit.__qiskit_version__ have their own __version__ module level dunder, "
"as standard in PEP 8.",
category=DeprecationWarning,
stacklevel=3,
)
self._version_dict = {
"qiskit-terra": __version__,
"qiskit": None,
}
self._loaded = False

def _load_versions(self):
from importlib.metadata import version

try:
Expand Down
3 changes: 2 additions & 1 deletion test/python/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ class TestVersion(QiskitTestCase):

def test_qiskit_version(self):
"""Test qiskit-version sets the correct version for terra."""
self.assertEqual(__version__, __qiskit_version__["qiskit-terra"])
with self.assertWarnsRegex(DeprecationWarning, "__qiskit_version__"):
self.assertEqual(__version__, __qiskit_version__["qiskit-terra"])