Skip to content

gh-126483: disable warnings filters mutation in concurrent test_check… #132694

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

graingert
Copy link
Contributor

@graingert graingert commented Apr 18, 2025

…_check_hostname_idn use by test_ssl_in_multiple_threads
@graingert graingert added 3.13 bugs and security fixes 3.14 new features, bugs and security fixes needs backport to 3.13 bugs and security fixes and removed 3.14 new features, bugs and security fixes 3.13 bugs and security fixes labels Apr 18, 2025
@graingert graingert marked this pull request as ready for review April 18, 2025 18:20
Comment on lines 3160 to 3179
with (
ThreadedEchoServer(context=server_context, chatty=True) as server,
warnings_helper.check_no_resource_warning(self)
if warnings_filters
else nullcontext(),
self.assertRaises(UnicodeError),
):
context.wrap_socket(socket.socket(), server_hostname='.pythontest.net')

with (
ThreadedEchoServer(context=server_context, chatty=True) as server,
warnings_helper.check_no_resource_warning(self)
if warnings_filters
else nullcontext(),
self.assertRaises(UnicodeDecodeError),
):
context.wrap_socket(
socket.socket(),
server_hostname=b'k\xf6nig.idn.pythontest.net',
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest the following:

def get_warnings_filter_context(self, warnings_filter):
    if warnings_filters:
        return warnings_helper.check_no_resource_warning(self)
    return nullcontext()

so that it can be used as follows:

        with (
            ThreadedEchoServer(context=server_context, chatty=True) as server,
            self.get_warnings_filter_context(warnings_filters),
            self.assertRaises(UnicodeError),
        ):
            context.wrap_socket(socket.socket(), server_hostname='.pythontest.net')

        with (
            ThreadedEchoServer(context=server_context, chatty=True) as server,
            self.get_warnings_filter_context(warnings_filters),
            self.assertRaises(UnicodeDecodeError),
        ):
            context.wrap_socket(
                socket.socket(),
                server_hostname=b'k\xf6nig.idn.pythontest.net',
            )

It took me a while to see the ternary if-else

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add some extra parenthesis, like ruff would

Copy link
Member

@picnixz picnixz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a good alternative. As I'm on mobile I'll let @gpshead do the merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting merge needs backport to 3.13 bugs and security fixes skip news tests Tests in the Lib/test dir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants