Skip to content

Commit ca9b5ae

Browse files
julien-langCopilotmchesnay
authored
SG-40994 Update deprecation warning message about end of compat with Py 3.7 (#1069)
* Update deprecation warning message about end of compat with Py 3.7 * Address review * Update python/tank/__init__.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Better for review * Apply suggestions from code review Co-authored-by: Martin Chesnay <104032692+mchesnay@users.noreply.github.com> * Apply suggestion from review * Unify variable name with tk-core --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Martin Chesnay <104032692+mchesnay@users.noreply.github.com>
1 parent 60630cf commit ca9b5ae

2 files changed

Lines changed: 36 additions & 4 deletions

File tree

docs/environment_variables.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,20 @@ Controls debug logging.
4545

4646
.. _environment_variables_authentication:
4747

48+
``SHOTGUN_ALLOW_OLD_PYTHON``
49+
----------------------------
50+
51+
When set to ``1``, Toolkit will allow being imported from Python versions that are no longer supported.
52+
Otherwise, when unset (or set to any other value), attempting to import Toolkit from old unsupported Python version will
53+
raise an exception.
54+
55+
This is not recommended and should only be used for testing purposes.
56+
57+
.. important::
58+
The ability to import the module does not guarantee that Toolkit will work properly on the unsupported Python
59+
version. In fact, it is very likely that it will not work properly.
60+
61+
4862
Authentication
4963
==============
5064

python/tank/__init__.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,30 @@
3636
import warnings
3737

3838
if sys.version_info < (3, 7):
39-
raise Exception("This module requires Python version 3.7 or higher.")
39+
if os.environ.get("SHOTGUN_ALLOW_OLD_PYTHON", "0") != "1":
40+
# This is our preferred default behavior when using an old
41+
# unsupported Python version.
42+
# This way, we can control where the exception is raised, and it provides a
43+
# comprehensive error message rather than having users facing a random
44+
# Python traceback and trying to understand this is due to using an
45+
# unsupported Python version.
46+
47+
raise RuntimeError("This module requires Python version 3.7 or higher.")
48+
49+
warnings.warn(
50+
"Python versions older than 3.7 are no longer supported as of January "
51+
"2023. Since the SHOTGUN_ALLOW_OLD_PYTHON variable is enabled, this "
52+
"module is raising a warning instead of an exception. "
53+
"However, it is very likely that this module will not be able to work "
54+
"on this Python version.",
55+
RuntimeWarning,
56+
stacklevel=2,
57+
)
4058
elif sys.version_info < (3, 9):
4159
warnings.warn(
42-
"Python versions older than 3.9 are no longer supported since 2025-03 "
43-
"and compatibility will be removed at any time after 2026-01. "
44-
"Please update to Python 3.9 or a newer supported version.",
60+
"Python versions older than 3.9 are no longer supported as of March "
61+
"2025 and compatibility will be discontinued after March 2026. "
62+
"Please update to Python 3.11 or any other supported version.",
4563
DeprecationWarning,
4664
stacklevel=2
4765
)

0 commit comments

Comments
 (0)