Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 35.2k
gh-127405: Emit a deprecation warning about a future change of sys.abiflags availability on Windows#131717
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
gh-127405: Emit a deprecation warning about a future change of sys.abiflags availability on Windows
#131717
Changes from all commits
55c1c16198ee264a1ed1b2ebe4986bc3d7385a8bae5172fdae2c032650a37fb2236ed634670285b4f0eb143145f0fd098fabc16380a69992d49abc98aa5556299c0d36c4bb074503529437ba52f20232a540197055160bf2eeac04ac8005ccfeaa3c65297cdba015a34148d8c78c0cab7e8411849f8d8956c7d917884a62a5739ba21ae49d74454ab45be11d08644411b8439bbec62dc66c7b900d30914659e573458ef7d2ff70822e7934536efb7225b299ad23ab00c8ec513a4c575b96b224d81ef28e1b634c42381107958dd065ad63059b7d586File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -24,6 +24,22 @@ always available. Unless explicitly noted otherwise, all variables are read-only | ||
| .. availability:: Unix. | ||
| .. versionchanged:: next | ||
| A :exc:`DeprecationWarning` will be emitted if the :data:`sys.abiflags` | ||
| member is accessed on Windows before Python 3.16. The :data:`!sys.abiflags` | ||
| member will be set to a meaningful value on Windows in Python 3.16. This | ||
| means the :data:`!sys.abiflags` member will always be available on all | ||
| platforms starting from Python 3.16. | ||
| See the notes for :ref:`incoming change to sys.abiflags | ||
| <whatsnew314-sys-abiflags-change>` on the *What's New in 3.14* | ||
| page for more details. | ||
Comment on lines
+34
to
+36
ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The first beta version of Python 3.14 is out. Any comment on this? | ||
| .. TODO: When we're in Python 3.16: | ||
| - Add a **CAUTION** section about the differences of :data:`sys.abiflags` | ||
| between prior-3.14, 3.14-3.15, and 3.16+ on Windows. | ||
| - Move porting recommendations from whatsnew/3.14.rst. | ||
XuehaiPan marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| .. function:: addaudithook(hook) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1693,6 +1693,66 @@ sys | ||
| * Raise :exc:`DeprecationWarning` for :func:`sys._clear_type_cache`. This | ||
| function was deprecated in Python 3.13 but it didn't raise a runtime warning. | ||
| * Schedule a change for availability of :data:`sys.abiflags` on Windows. A | ||
| :exc:`DeprecationWarning` will be emitted if the :data:`!sys.abiflags` member | ||
| is accessed on Windows before Python 3.16. | ||
| (Contributed by Xuehai Pan in :gh:`131717`.) | ||
| .. _whatsnew314-sys-abiflags-change: | ||
| sys.abiflags | ||
| ------------ | ||
XuehaiPan marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| A :exc:`DeprecationWarning` will be emitted if the :data:`sys.abiflags` member | ||
| is accessed on Windows before Python 3.16. | ||
| For example: | ||
| .. code-block:: python | ||
| >>> import sys | ||
| >>> getattr(sys, 'abiflags', None) # on Windows | ||
| <python-input-1>:1: DeprecationWarning: sys.abiflags will be set to a meaningful value on all platforms ... | ||
| >>> hasattr(sys, 'abiflags') # on Windows | ||
| <python-input-2>:1: DeprecationWarning: sys.abiflags will be set to a meaningful value on all platforms ... | ||
| False | ||
| To suppress this warning, use the :mod:`warnings` module: | ||
| .. code-block:: python | ||
| import warnings | ||
| with warnings.catch_warnings(): | ||
| # ignore DeprecationWarning on incoming sys.abiflags change on Windows before 3.16 | ||
| warnings.simplefilter('ignore', DeprecationWarning) | ||
| abiflags = getattr(sys, 'abiflags', '') | ||
| Due to historical reasons, :data:`sys.abiflags` is not covered by | ||
| :pep:`3149` on Windows. Now we have multiple builds, such as the | ||
| :term:`free-threaded <free threading>` build, that provide different ABIs. | ||
| :data:`!sys.abiflags` is now required under many circumstances to determine | ||
| the ABI of the Python interpreter. | ||
| The :data:`!sys.abiflags` member will be set to a meaningful value on | ||
| Windows in Python 3.16. This means the :data:`!sys.abiflags` member will | ||
| always be available on all platforms starting from Python 3.16. | ||
| Before this incoming change is made, :func:`sysconfig.get_config_vars` would be | ||
| useful. See also :ref:`Changes of **sysconfig** <whatsnew314-sysconfig-abiflags>`. | ||
| The following table shows how to migrate from the old code to the new code | ||
| without changing the behavior: | ||
| +---------------------------------------+---------------------------------------------------------------------+ | ||
| | Code prior to Python 3.14 | Code prior to Python 3.16 with the same behavior | | ||
| +=======================================+=====================================================================+ | ||
| | ``sys.abiflags`` | ``sys.abiflags`` | | ||
| +---------------------------------------+---------------------------------------------------------------------+ | ||
| | ``getattr(sys, 'abiflags', default)`` | ``sys.abiflags if not sys.platform.startswith('win') else default`` | | ||
| +---------------------------------------+---------------------------------------------------------------------+ | ||
| | ``hasattr(sys, 'abiflags')`` | ``not sys.platform.startswith('win')`` | | ||
| +---------------------------------------+---------------------------------------------------------------------+ | ||
XuehaiPan marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| sys.monitoring | ||
| -------------- | ||
| @@ -1701,6 +1761,8 @@ sys.monitoring | ||
| :monitoring-event:`BRANCH_RIGHT`. The ``BRANCH`` event is deprecated. | ||
| .. _whatsnew314-sysconfig-abiflags: | ||
| sysconfig | ||
| --------- | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -314,6 +314,7 @@ def get_default_scheme(): | ||
| def get_makefile_filename(): | ||
| """Return the path of the Makefile.""" | ||
| import warnings | ||
| # GH-127429: When cross-compiling, use the Makefile from the target, instead of the host Python. | ||
| if cross_base := os.environ.get('_PYTHON_PROJECT_BASE'): | ||
| @@ -322,7 +323,14 @@ def get_makefile_filename(): | ||
| if _PYTHON_BUILD: | ||
| return os.path.join(_PROJECT_BASE, "Makefile") | ||
| if hasattr(sys, 'abiflags'): | ||
ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are there any details about the existence of hasattr(sys, 'abiflags')
os.name=='nt'# os.name != 'posix'notsys.platform.startswith('win') | ||
| # TODO: Remove this in Python 3.16. | ||
| # This flag will always be True since Python 3.16. | ||
| with warnings.catch_warnings(): | ||
| # ignore DeprecationWarning on sys.abiflags change on Windows | ||
| warnings.filterwarnings('ignore', r'sys\.abiflags', category=DeprecationWarning) | ||
| has_abiflags = hasattr(sys, 'abiflags') | ||
| if has_abiflags: | ||
| config_dir_name = f'config-{_PY_VERSION_SHORT}{sys.abiflags}' | ||
| else: | ||
| config_dir_name = 'config' | ||
| @@ -496,6 +504,8 @@ def get_path(name, scheme=get_default_scheme(), vars=None, expand=True): | ||
| def _init_config_vars(): | ||
| import warnings | ||
| global _CONFIG_VARS | ||
| _CONFIG_VARS = {} | ||
| @@ -504,10 +514,12 @@ def _init_config_vars(): | ||
| base_prefix = _BASE_PREFIX | ||
| base_exec_prefix = _BASE_EXEC_PREFIX | ||
| try: | ||
| abiflags = sys.abiflags | ||
| except AttributeError: | ||
| abiflags = '' | ||
| # XXX: Remove this context manager in Python 3.16 | ||
| # sys.abiflags will always be available on all platforms since Python 3.16 | ||
| with warnings.catch_warnings(): | ||
| # ignore DeprecationWarning on sys.abiflags change on Windows | ||
XuehaiPan marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| warnings.simplefilter('ignore', DeprecationWarning) | ||
| abiflags = getattr(sys, 'abiflags', '') | ||
| if os.name == 'posix': | ||
| _init_posix(_CONFIG_VARS) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Emit a :exc:`DeprecationWarning` about a future change of :data:`sys.abiflags` availability on Windows. Patch by Xuehai Pan. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.