Skip to content

Commit 1b43b32

Browse files
authored
Merge pull request #521 from python/main
Sync Fork from Upstream Repo
2 parents 30ec734 + 2693132 commit 1b43b32

19 files changed

Lines changed: 176 additions & 46 deletions

Doc/library/logging.handlers.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,8 +1014,12 @@ possible, while any potentially slow operations (such as sending an email via
10141014
method is enqueued.
10151015

10161016
The base implementation formats the record to merge the message,
1017-
arguments, and exception information, if present. It also
1018-
removes unpickleable items from the record in-place.
1017+
arguments, and exception information, if present. It also removes
1018+
unpickleable items from the record in-place. Specifically, it overwrites
1019+
the record's :attr:`msg` and :attr:`message` attributes with the merged
1020+
message (obtained by calling the handler's :meth:`format` method), and
1021+
sets the :attr:`args`, :attr:`exc_info` and :attr:`exc_text` attributes
1022+
to ``None``.
10191023

10201024
You might want to override this method if you want to convert
10211025
the record to a dict or JSON string, or send a modified copy

Doc/library/socket.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,8 @@ Constants
381381

382382
.. versionchanged:: 3.10
383383
``IP_RECVTOS`` was added.
384+
Added ``TCP_KEEPALIVE``. On MacOS this constant can be used in the same
385+
way that ``TCP_KEEPIDLE`` is used on Linux.
384386

385387
.. data:: AF_CAN
386388
PF_CAN

Doc/library/sqlite3.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ Cursor Objects
654654
This is a nonstandard convenience method for executing multiple SQL statements
655655
at once. It issues a ``COMMIT`` statement first, then executes the SQL script it
656656
gets as a parameter. This method disregards :attr:`isolation_level`; any
657-
transation control must be added to *sql_script*.
657+
transaction control must be added to *sql_script*.
658658

659659
*sql_script* can be an instance of :class:`str`.
660660

Doc/reference/compound_stmts.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -968,9 +968,9 @@ Syntax:
968968
At most one double star pattern may be in a mapping pattern. The double star
969969
pattern must be the last subpattern in the mapping pattern.
970970

971-
Duplicate key values in mapping patterns are disallowed. (If all key patterns
972-
are literal patterns this is considered a syntax error; otherwise this is a
973-
runtime error and will raise :exc:`ValueError`.)
971+
Duplicate keys in mapping patterns are disallowed. Duplicate literal keys will
972+
raise a :exc:`SyntaxError`. Two keys that otherwise have the same value will
973+
raise a :exc:`ValueError` at runtime.
974974

975975
The following is the logical flow for matching a mapping pattern against a
976976
subject value:
@@ -982,7 +982,8 @@ subject value:
982982
mapping, the mapping pattern succeeds.
983983

984984
#. If duplicate keys are detected in the mapping pattern, the pattern is
985-
considered invalid and :exc:`ValueError` is raised.
985+
considered invalid. A :exc:`SyntaxError` is raised for duplicate literal
986+
values; or a :exc:`ValueError` for named keys of the same value.
986987

987988
.. note:: Key-value pairs are matched using the two-argument form of the mapping
988989
subject's ``get()`` method. Matched key-value pairs must already be present

Doc/whatsnew/3.10.rst

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
:Release: |release|
66
:Date: |today|
7+
:Editor: Pablo Galindo Salgado
78

89
.. Rules for maintenance:
910
@@ -65,7 +66,34 @@ Summary -- Release highlights
6566
6667
.. PEP-sized items next.
6768
68-
* :pep:`644`, require OpenSSL 1.1.1 or newer
69+
New syntax features:
70+
71+
* :pep:`634`, Structural Pattern Matching: Specification
72+
* :pep:`635`, Structural Pattern Matching: Motivation and Rationale
73+
* :pep:`636`, Structural Pattern Matching: Tutorial
74+
* :issue:`12782`, Parenthesized context managers are now officially allowed.
75+
76+
New features in the standard library:
77+
78+
* :pep:`618`, Add Optional Length-Checking To zip.
79+
80+
Interpreter improvements:
81+
82+
* :pep:`626`, Precise line numbers for debugging and other tools.
83+
84+
New typing features:
85+
86+
* :pep:`604`, Allow writing union types as X | Y
87+
* :pep:`613`, Explicit Type Aliases
88+
* :pep:`612`, Parameter Specification Variables
89+
90+
Important deprecations, removals or restrictions:
91+
92+
* :pep:`644`, Require OpenSSL 1.1.1 or newer
93+
* :pep:`632`, Deprecate distutils module.
94+
* :pep:`623`, Deprecate and prepare for the removal of the wstr member in PyUnicodeObject.
95+
* :pep:`624`, Remove Py_UNICODE encoder APIs
96+
* :pep:`597`, Add optional EncodingWarning
6997

7098

7199
New Features

Lib/logging/handlers.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,12 +1399,15 @@ def enqueue(self, record):
13991399

14001400
def prepare(self, record):
14011401
"""
1402-
Prepares a record for queuing. The object returned by this method is
1402+
Prepare a record for queuing. The object returned by this method is
14031403
enqueued.
14041404
1405-
The base implementation formats the record to merge the message
1406-
and arguments, and removes unpickleable items from the record
1407-
in-place.
1405+
The base implementation formats the record to merge the message and
1406+
arguments, and removes unpickleable items from the record in-place.
1407+
Specifically, it overwrites the record's `msg` and
1408+
`message` attributes with the merged message (obtained by
1409+
calling the handler's `format` method), and sets the `args`,
1410+
`exc_info` and `exc_text` attributes to None.
14081411
14091412
You might want to override this method if you want to convert
14101413
the record to a dict or JSON string, or send a modified copy

Lib/test/test_patma.py

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2901,6 +2901,40 @@ def test_wildcard_makes_remaining_patterns_unreachable_5(self):
29012901
pass
29022902
""")
29032903

2904+
def test_mapping_pattern_duplicate_key(self):
2905+
self.assert_syntax_error("""
2906+
match ...:
2907+
case {"a": _, "a": _}:
2908+
pass
2909+
""")
2910+
2911+
def test_mapping_pattern_duplicate_key_edge_case0(self):
2912+
self.assert_syntax_error("""
2913+
match ...:
2914+
case {0: _, False: _}:
2915+
pass
2916+
""")
2917+
2918+
def test_mapping_pattern_duplicate_key_edge_case1(self):
2919+
self.assert_syntax_error("""
2920+
match ...:
2921+
case {0: _, 0.0: _}:
2922+
pass
2923+
""")
2924+
2925+
def test_mapping_pattern_duplicate_key_edge_case2(self):
2926+
self.assert_syntax_error("""
2927+
match ...:
2928+
case {0: _, -0: _}:
2929+
pass
2930+
""")
2931+
2932+
def test_mapping_pattern_duplicate_key_edge_case3(self):
2933+
self.assert_syntax_error("""
2934+
match ...:
2935+
case {0: _, 0j: _}:
2936+
pass
2937+
""")
29042938

29052939
class TestTypeErrors(unittest.TestCase):
29062940

@@ -3008,17 +3042,6 @@ class Class:
30083042

30093043
class TestValueErrors(unittest.TestCase):
30103044

3011-
def test_mapping_pattern_checks_duplicate_key_0(self):
3012-
x = {"a": 0, "b": 1}
3013-
w = y = z = None
3014-
with self.assertRaises(ValueError):
3015-
match x:
3016-
case {"a": y, "a": z}:
3017-
w = 0
3018-
self.assertIs(w, None)
3019-
self.assertIs(y, None)
3020-
self.assertIs(z, None)
3021-
30223045
def test_mapping_pattern_checks_duplicate_key_1(self):
30233046
class Keys:
30243047
KEY = "a"

Lib/test/test_socket.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6446,6 +6446,12 @@ def test_length_restriction(self):
64466446
sock.bind(("type", "n" * 64))
64476447

64486448

6449+
@unittest.skipUnless(sys.platform == 'darwin', 'macOS specific test')
6450+
class TestMacOSTCPFlags(unittest.TestCase):
6451+
def test_tcp_keepalive(self):
6452+
self.assertTrue(socket.TCP_KEEPALIVE)
6453+
6454+
64496455
@unittest.skipUnless(sys.platform.startswith("win"), "requires Windows")
64506456
class TestMSWindowsTCPFlags(unittest.TestCase):
64516457
knownTCPFlags = {
@@ -6704,6 +6710,7 @@ def test_main():
67046710
SendfileUsingSendfileTest,
67056711
])
67066712
tests.append(TestMSWindowsTCPFlags)
6713+
tests.append(TestMacOSTCPFlags)
67076714

67086715
thread_info = threading_helper.threading_setup()
67096716
support.run_unittest(*tests)

Lib/test/test_types.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,8 @@ def test_or_types_operator(self):
612612
self.assertEqual(str | int, typing.Union[int, str])
613613
self.assertEqual(int | None, typing.Union[int, None])
614614
self.assertEqual(None | int, typing.Union[int, None])
615+
self.assertEqual(int | type(None), int | None)
616+
self.assertEqual(type(None) | int, None | int)
615617
self.assertEqual(int | str | list, typing.Union[int, str, list])
616618
self.assertEqual(int | (str | list), typing.Union[int, str, list])
617619
self.assertEqual(str | (int | list), typing.Union[int, str, list])
@@ -699,6 +701,13 @@ def test_or_type_operator_with_TypeVar(self):
699701
assert TV | str == typing.Union[TV, str]
700702
assert str | TV == typing.Union[str, TV]
701703

704+
def test_union_args(self):
705+
self.assertEqual((int | str).__args__, (int, str))
706+
self.assertEqual(((int | str) | list).__args__, (int, str, list))
707+
self.assertEqual((int | (str | list)).__args__, (int, str, list))
708+
self.assertEqual((int | None).__args__, (int, type(None)))
709+
self.assertEqual((int | type(None)).__args__, (int, type(None)))
710+
702711
def test_union_parameter_chaining(self):
703712
T = typing.TypeVar("T")
704713
S = typing.TypeVar("S")
@@ -754,8 +763,13 @@ def test_or_type_operator_with_SpecialForm(self):
754763
assert typing.Union[int, bool] | str == typing.Union[int, bool, str]
755764

756765
def test_or_type_repr(self):
766+
assert repr(int | str) == "int | str"
767+
assert repr((int | str) | list) == "int | str | list"
768+
assert repr(int | (str | list)) == "int | str | list"
757769
assert repr(int | None) == "int | None"
770+
assert repr(int | type(None)) == "int | None"
758771
assert repr(int | typing.GenericAlias(list, int)) == "int | list[int]"
772+
assert repr(int | typing.TypeVar('T')) == "int | ~T"
759773

760774
def test_or_type_operator_with_genericalias(self):
761775
a = list[int]
@@ -792,13 +806,18 @@ def __eq__(self, other):
792806
issubclass(int, type_)
793807

794808
def test_or_type_operator_with_bad_module(self):
795-
class TypeVar:
809+
class BadMeta(type):
810+
__qualname__ = 'TypeVar'
796811
@property
797812
def __module__(self):
798813
1 / 0
814+
TypeVar = BadMeta('TypeVar', (), {})
815+
_SpecialForm = BadMeta('_SpecialForm', (), {})
799816
# Crashes in Issue44483
800817
with self.assertRaises(ZeroDivisionError):
801818
str | TypeVar()
819+
with self.assertRaises(ZeroDivisionError):
820+
str | _SpecialForm()
802821

803822
@cpython_only
804823
def test_or_type_operator_reference_cycle(self):
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Mapping patterns in ``match`` statements with two or more equal literal
2+
keys will now raise a :exc:`SyntaxError` at compile-time.

0 commit comments

Comments
 (0)