Skip to content

Commit abf3ae6

Browse files
author
Matthias Koeppe
committed
src/doc/en/developer/coding_basics.rst: Use sys.version_info instead of try..except
1 parent cee723e commit abf3ae6

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

src/doc/en/developer/coding_basics.rst

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,12 @@ included in one of the following places:
166166
It should be imported as follows
167167
(see :ref:`section-python-language-standard`)::
168168

169-
try:
169+
import sys
170+
171+
if sys.version_info < (3, 11):
170172
# Use backport package providing Python 3.11 features
171173
from importlib_resources import files
172-
except ImportError:
174+
else:
173175
from importlib.resources import files
174176

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

184186
If the file needs to be used outside of Python, then the
185187
preferred way is using the context manager
186-
:func:`importlib.resources.as_file`. It should be imported as
187-
follows::
188-
189-
try:
190-
# Use backport package providing Python 3.11 features
191-
from importlib_resources import as_file
192-
except ImportError:
193-
from importlib.resources import as_file
188+
:func:`importlib.resources.as_file`. It should be imported in the
189+
same way as shown above.
194190

195191
.. NOTE::
196192

0 commit comments

Comments
 (0)