Skip to content

gh-94598: Remove deprecated ssl modules features#94599

Draft
tiran wants to merge 7 commits into
python:mainfrom
tiran:py312_ssl_removal
Draft

gh-94598: Remove deprecated ssl modules features#94599
tiran wants to merge 7 commits into
python:mainfrom
tiran:py312_ssl_removal

Conversation

@tiran

@tiran tiran commented Jul 6, 2022

Copy link
Copy Markdown
Member

@tiran

tiran commented Jul 6, 2022

Copy link
Copy Markdown
Member Author
  • documentation updates are still work in progress
  • update whatsnew in 3.12 and porting to 3.12

@tiran
tiran force-pushed the py312_ssl_removal branch 3 times, most recently from ae51bdc to cfe4777 Compare July 8, 2022 13:30
@tiran
tiran force-pushed the py312_ssl_removal branch from cfe4777 to 72c5941 Compare July 20, 2022 08:01
@graingert

graingert commented Jul 20, 2022

Copy link
Copy Markdown
Contributor

Can you make these attributes warn on access in 3.11? using the approach here

def __getattr__(name):
"""
For backwards compatibility, continue to make names
from _resources_abc available through this module. #93963
"""
if name in _resources_abc.__all__:
obj = getattr(_resources_abc, name)
warnings._deprecated(f"{__name__}.{name}", remove=(3, 14))
globals()[name] = obj
return obj
raise AttributeError(f'module {__name__!r} has no attribute {name!r}')

Currently they only warn at use, and it would make testing this change much easier if they warn on access

@tiran

tiran commented Jul 21, 2022

Copy link
Copy Markdown
Member Author

Enum's convert helper gets in the way. It adds the variables to global name space unconditionally.

@graingert

Copy link
Copy Markdown
Contributor

Could you del the globals, adding them back with __getattr__?

@tiran

tiran commented Jul 21, 2022

Copy link
Copy Markdown
Member Author

That's ugly.

@hugovk

hugovk commented Jul 27, 2022

Copy link
Copy Markdown
Member

It's ugly but it would give users a heads-up this is going to be removed.

@tiran

tiran commented Jul 27, 2022

Copy link
Copy Markdown
Member Author

It's ugly but it would give users a heads-up this is going to be removed.

The ssl module has been warning about deprecated features since 3.10:

$ python3.10 -Werror -c 'import ssl; ssl.SSLContext(ssl.PROTOCOL_TLS)'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib64/python3.10/ssl.py", line 496, in __new__
    self = _SSLContext.__new__(cls, protocol)
DeprecationWarning: ssl.PROTOCOL_TLS is deprecated

Functions and methods don't warn on attribute access either. They typically warn when they are called (used).

@tiran
tiran force-pushed the py312_ssl_removal branch from 72c5941 to 9f709b0 Compare July 27, 2022 09:36
@tiran

tiran commented Jul 27, 2022

Copy link
Copy Markdown
Member Author

Compromise: 3.11 is at the end of its beta phase. I don't want to add ugly code to it. Instead I'm going to add warnings for the deprecated module constants to 3.12 and remove them in 3.13. They won't work in 3.12, though. Attribute access won't raise an AttributeError.

$ ./python -Wonce -c "import ssl; print(ssl.PROTOCOL_TLS)"
<string>:1: DeprecationWarning: ssl.PROTOCOL_TLS is no longer supported. The constants will be removed in 3.13. Use ssl.PROTOCOL_TLS_CLIENT or ssl.PROTOCOL_TLS_SERVER instead.
NotImplemented
$ ./python -Wonce -c "import ssl; print(ssl.OP_NO_TLSv1)"
<string>:1: DeprecationWarning: ssl.OP_NO_TLSv1 is no longer supported. The constants will be removed in 3.13. Use SSLContext's 'minimum_version' and 'maximum_version' properties instead.
67108864

Comment thread Lib/ssl.py
sslsocket_class = None # SSLSocket is assigned later.
sslobject_class = None # SSLObject is assigned later.

def __new__(cls, protocol=None, *args, **kwargs):

This comment was marked as outdated.

@arhadthedev

Copy link
Copy Markdown
Member

Deprecated :mod:`ssl` features have been removed

  • support for SSL 3.0, TLS 1.0, and TLS 1.1
  • all ``PROTOCOL_*`` constants except ``PROTOCOL_TLS_CLIENT`` and ``PROTOCOL_TLS_SERVER``
  • all ``OP_NO_SSL*`` and ``OP_NO_TLS*`` option flags
  • ``TLSVersion.SSLv3``, ``TLSVersion.TLSv1``, and ``TLSVersion.TLSv1_1``
  • :class:`ssl.SSLContext` now requires a protocol argument

Is there any chance to get it into 3.12b1?

cc @dstufft, @alex

@arhadthedev arhadthedev added stdlib Standard Library Python modules in the Lib/ directory topic-SSL labels May 5, 2023
@erlend-aasland

Copy link
Copy Markdown
Contributor

Is there any chance to get it into 3.12b1?

Feel free to pick it up and prepare it for the next 3.13 alpha.

@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Apr 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting core review stale Stale PR or inactive for long period of time. stdlib Standard Library Python modules in the Lib/ directory topic-SSL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants