Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 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
21 changes: 20 additions & 1 deletion qiskit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import pkgutil
import sys
import warnings
import os

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

is this imported by mistake?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We used to check some environment variables here about suppressing packaging warnings - looks like import os got left after those were removed in #5619. Pylint won't moan about unused imports in __init__ by default I think, because most names in an initialiser won't be used.


# qiskit errors operator
from qiskit.exceptions import QiskitError, MissingOptionalLibraryError
Expand Down Expand Up @@ -127,3 +126,23 @@ def __getattr__(self, attr):

Aer = AerWrapper()
IBMQ = IBMQWrapper()

__all__ = [
"Aer",
"AncillaRegister",
"BasicAer",
"ClassicalRegister",
"_config",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
"_config",

We probably don't want to be exporting a private name by default, unless there's a really good reason to.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I added because _config = _user_config.get_config() and I assumed that intentional. However, checking in the history it seems that was added by #3362 and ended up being leftovers. So I removed all the related lines in 76370cc

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It's still usable, but at the very least I'd think something like that ought to be through qualified access, so we're fine not to include it in __all__.

"IBMQ",
"MissingOptionalLibraryError",
"QiskitError",
"__qiskit_version__",
"__version__",
Comment thread
1ucian0 marked this conversation as resolved.
Outdated
"QuantumCircuit",
"QuantumRegister",
"assemble",
"execute",
"schedule",
"sequence",
"transpile",
]
Comment thread
1ucian0 marked this conversation as resolved.
8 changes: 8 additions & 0 deletions releasenotes/notes/7274-6f57628a7995a461.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
upgrade:
- |
In this version, ``from qiskit import *`` wont import submodules, but only a selected list of objects.
This might break existing code using ``from qiskit import *`` and refering to objctes that are not part of the current namespace.
As a reminder, ``import *`` is considered bad practice and it should not be used in production code.
Qiskit sets ``__all__`` in ``qiskit/__init__.py`` as a way to mitigate the effects of said bad practice.
If your code raises ``name '<something>' is not defined``, add ``from qiskit import <something>`` and try again.
Comment thread
1ucian0 marked this conversation as resolved.
Outdated