Skip to content

Commit

Permalink
src/doc/en/developer/coding_basics.rst: Use sys.version_info instead …
Browse files Browse the repository at this point in the history
…of try..except
  • Loading branch information
Matthias Koeppe committed Feb 20, 2024
1 parent cee723e commit abf3ae6
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/doc/en/developer/coding_basics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,12 @@ included in one of the following places:
It should be imported as follows
(see :ref:`section-python-language-standard`)::

try:
import sys

if sys.version_info < (3, 11):
# Use backport package providing Python 3.11 features
from importlib_resources import files
except ImportError:
else:
from importlib.resources import files

After this import, you can:
Expand All @@ -183,14 +185,8 @@ included in one of the following places:

If the file needs to be used outside of Python, then the
preferred way is using the context manager
:func:`importlib.resources.as_file`. It should be imported as
follows::

try:
# Use backport package providing Python 3.11 features
from importlib_resources import as_file
except ImportError:
from importlib.resources import as_file
:func:`importlib.resources.as_file`. It should be imported in the
same way as shown above.

.. NOTE::

Expand Down

0 comments on commit abf3ae6

Please sign in to comment.