Skip to content
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

Support Python 3.12 #3691

Merged
merged 4 commits into from
Nov 7, 2023
Merged

Support Python 3.12 #3691

merged 4 commits into from
Nov 7, 2023

Conversation

jstvz
Copy link
Contributor

@jstvz jstvz commented Oct 27, 2023

Changes needed to get 3.12 working:

Replace deprecated ssl.wrap_socket in OAuth client

ssl.wrap_socket() has been discouraged since Python 3.2, deprecated since 3.7, and finally removed in 3.12. In this PR, the ssl.wrap_socket function has been removed and replaced with the recommended approach using ssl.SSLContext. Previously, ssl.wrap_socket internally set up the SSL context, including loading certificates. Now, we're doing that explicitly with ssl.SSLContext. This is a substantive, but low-risk, change.

On the testing side, the previous workaround for suppressing the CERTIFICATE_VERIFY_FAILED error has been adapted to utilize the context creation method.

Remove invalid assertions

called_once and called_once_with are not valid assertions on mock objects, meaning an instance of mock.Mock is returned. Because instances of mock.Mock evaluate to true, the assertion is equivalent to assert True. Those invalid assertions throw an AttributeError in Python 3.12, so this PR replaces them with valid assertions and updates some of the expected calls.

@jstvz jstvz changed the base branch from main to remove-rflint-task November 3, 2023 23:01
Base automatically changed from remove-rflint-task to main November 7, 2023 17:03
@jstvz jstvz marked this pull request as ready for review November 7, 2023 17:09
@jstvz jstvz requested a review from a team as a code owner November 7, 2023 17:09
jstvz added 4 commits November 7, 2023 09:11
`called_once_with` is not a valid (assertion) method and therefore an
instance of mock.Mock is returned. Because instances of mock.Mock
evaluate to true, the assertion is equivalent to assert True.

See: https://discuss.python.org/t/include-prefix-called-in-list-of-forbidden-method-prefixes-for-mock-objects-in-unsafe-mode/22249/4
`ssl.wrap_socket()` has been discouraged since Python 3.2, deprecated
since 3.7, and finally removed in 3.12. In this commit, the
ssl.wrap_socket function has been removed and replaced with the
recommended approach using ssl.SSLContext.  Previously, ssl.wrap_socket
internally set up the SSL context, including loading certificates. Now,
we're doing that explicitly with ssl.SSLContext.

On the testing side, the previous workaround for suppressing the
CERTIFICATE_VERIFY_FAILED error has been adapted to utilize the
context creation method.

A note (FIXME): We're currently using ssl.PROTOCOL_TLS for
compatibility, but once we drop Python 3.8 support, we should shift to
ssl.PROTOCOL_TLS_SERVER, as Python 3.10 no longer includes the generic
one.
@jstvz jstvz enabled auto-merge (rebase) November 7, 2023 17:13
@jstvz jstvz merged commit 6e19932 into main Nov 7, 2023
21 checks passed
@jstvz jstvz deleted the ci-updates branch November 7, 2023 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants