Skip to content

Commit c687595

Browse files
[PY312] Add support for ssl.OP_LEGACY_SERVER_CONNECT (#2489)
1 parent ed4276b commit c687595

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

ChangeLog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ Release date: TBA
1919

2020
* Implement inference for JoinedStr and FormattedValue
2121

22+
* Add support for ``ssl.OP_LEGACY_SERVER_CONNECT`` (new in Python 3.12).
23+
24+
Closes pylint-dev/pylint#9849
2225

2326

2427
What's New in astroid 3.2.5?

astroid/brain/brain_ssl.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from astroid import parse
88
from astroid.brain.helpers import register_module_extender
9-
from astroid.const import PY310_PLUS
9+
from astroid.const import PY310_PLUS, PY312_PLUS
1010
from astroid.manager import AstroidManager
1111

1212

@@ -42,13 +42,16 @@ class Options(_IntFlag):
4242
OP_NO_COMPRESSION = 11
4343
OP_NO_TICKET = 12
4444
OP_NO_RENEGOTIATION = 13
45-
OP_ENABLE_MIDDLEBOX_COMPAT = 14"""
45+
OP_ENABLE_MIDDLEBOX_COMPAT = 14
46+
"""
47+
if PY312_PLUS:
48+
enum += "OP_LEGACY_SERVER_CONNECT = 15"
4649
return enum
4750

4851

4952
def ssl_transform():
5053
return parse(
51-
"""
54+
f"""
5255
# Import necessary for conversion of objects defined in C into enums
5356
from enum import IntEnum as _IntEnum, IntFlag as _IntFlag
5457
@@ -71,6 +74,8 @@ def ssl_transform():
7174
OP_NO_TLSv1, OP_NO_TLSv1_1, OP_NO_TLSv1_2,
7275
OP_SINGLE_DH_USE, OP_SINGLE_ECDH_USE)
7376
77+
{"from _ssl import OP_LEGACY_SERVER_CONNECT" if PY312_PLUS else ""}
78+
7479
from _ssl import (ALERT_DESCRIPTION_ACCESS_DENIED, ALERT_DESCRIPTION_BAD_CERTIFICATE,
7580
ALERT_DESCRIPTION_BAD_CERTIFICATE_HASH_VALUE,
7681
ALERT_DESCRIPTION_BAD_CERTIFICATE_STATUS_RESPONSE,

tests/brain/test_ssl.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44

55
"""Tests for the ssl brain."""
66

7+
import pytest
8+
79
from astroid import bases, nodes, parse
10+
from astroid.const import PY312_PLUS
811

912

1013
def test_ssl_brain() -> None:
@@ -41,3 +44,21 @@ def test_ssl_brain() -> None:
4144
inferred_cert_required = next(module.body[4].value.infer())
4245
assert isinstance(inferred_cert_required, bases.Instance)
4346
assert inferred_cert_required._proxied.name == "CERT_REQUIRED"
47+
48+
49+
@pytest.mark.skipif(not PY312_PLUS, reason="Uses new 3.12 constant")
50+
def test_ssl_brain_py312() -> None:
51+
"""Test ssl brain transform."""
52+
module = parse(
53+
"""
54+
import ssl
55+
ssl.OP_LEGACY_SERVER_CONNECT
56+
ssl.Options.OP_LEGACY_SERVER_CONNECT
57+
"""
58+
)
59+
60+
inferred_constant = next(module.body[1].value.infer())
61+
assert isinstance(inferred_constant, nodes.Const)
62+
63+
inferred_instance = next(module.body[2].value.infer())
64+
assert isinstance(inferred_instance, bases.Instance)

0 commit comments

Comments
 (0)