Skip to content
Closed
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
5 changes: 4 additions & 1 deletion Doc/library/functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1968,7 +1968,7 @@ are always available. They are listed here in alphabetical order.
This is an advanced function that is not needed in everyday Python
programming, unlike :func:`importlib.import_module`.

This function is invoked by the :keyword:`import` statement. It can be
This function is invoked by the :keyword:`import` statement. It can be
replaced (by importing the :mod:`builtins` module and assigning to
``builtins.__import__``) in order to change semantics of the
:keyword:`!import` statement, but doing so is **strongly** discouraged as it
Expand Down Expand Up @@ -2018,6 +2018,9 @@ are always available. They are listed here in alphabetical order.
object, the names to import are retrieved and assigned to their respective
names.

An :exc:`ImportError` exception can be raised if the module cannot be imported
successfully.
Comment on lines +2021 to +2022
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure I like this wording - what do you mean "can be raised", it sounds like it is possible for import to fail and not raise an exception.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note Ronald's comment on arbitrary exceptions being raised from a module body while it's being imported.

It means arbitrary exceptions can also be raised.

Copy link
Member

Choose a reason for hiding this comment

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

I understand the intent, but I don't think that's the only possible interpretation of the current wording.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just found out that #94662 is also doing the same thing. Would you prefer that one?


If you simply want to import a module (potentially within a package) by name,
use :func:`importlib.import_module`.

Expand Down
3 changes: 3 additions & 0 deletions Doc/library/importlib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ Functions
need to call :func:`invalidate_caches` in order for the new module to be
noticed by the import system.

An :exc:`ImportError` exception can be raised if the module cannot be imported
successfully.

.. versionchanged:: 3.3
Parent packages are automatically imported.

Expand Down