Skip to content

Commit fe0fd6f

Browse files
author
Erlend E. Aasland
committed
Merge branch 'main' into sqlite-optimise-resets
2 parents cbcd640 + a9640d7 commit fe0fd6f

File tree

15 files changed

+178
-82
lines changed

15 files changed

+178
-82
lines changed

Doc/library/dataclasses.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ Module contents
205205
follows a field with a default value. This is true whether this
206206
occurs in a single class, or as a result of class inheritance.
207207

208-
.. function:: field(*, default=MISSING, default_factory=MISSING, init=True, repr=True, hash=None, compare=True, metadata=None, kw_only=MISSING):
208+
.. function:: field(*, default=MISSING, default_factory=MISSING, init=True, repr=True, hash=None, compare=True, metadata=None, kw_only=MISSING)
209209

210210
For common and simple use cases, no other functionality is
211211
required. There are, however, some dataclass features that

Doc/library/re.rst

+14-4
Original file line numberDiff line numberDiff line change
@@ -824,10 +824,20 @@ form.
824824
.. function:: findall(pattern, string, flags=0)
825825

826826
Return all non-overlapping matches of *pattern* in *string*, as a list of
827-
strings. The *string* is scanned left-to-right, and matches are returned in
828-
the order found. If one or more groups are present in the pattern, return a
829-
list of groups; this will be a list of tuples if the pattern has more than
830-
one group. Empty matches are included in the result.
827+
strings or tuples. The *string* is scanned left-to-right, and matches
828+
are returned in the order found. Empty matches are included in the result.
829+
830+
The result depends on the number of capturing groups in the pattern.
831+
If there are no groups, return a list of strings matching the whole
832+
pattern. If there is exactly one group, return a list of strings
833+
matching that group. If multiple groups are present, return a list
834+
of tuples of strings matching the groups. Non-capturing groups do not
835+
affect the form of the result.
836+
837+
>>> re.findall(r'\bf[a-z]*', 'which foot or hand fell fastest')
838+
['foot', 'fell', 'fastest']
839+
>>> re.findall(r'(\w+)=(\d+)', 'set width=20 and height=10')
840+
[('width', '20'), ('height', '10')]
831841

832842
.. versionchanged:: 3.7
833843
Non-empty matches can now start just after a previous empty match.

Doc/library/typing.rst

+7
Original file line numberDiff line numberDiff line change
@@ -2013,6 +2013,13 @@ Introspection helpers
20132013
'name': Annotated[str, 'some marker']
20142014
}
20152015

2016+
.. note::
2017+
2018+
:func:`get_type_hints` does not work with imported
2019+
:ref:`type aliases <type-aliases>` that include forward references.
2020+
Enabling postponed evaluation of annotations (:pep:`563`) may remove
2021+
the need for most forward references.
2022+
20162023
.. versionchanged:: 3.9
20172024
Added ``include_extras`` parameter as part of :pep:`593`.
20182025

Doc/tutorial/errors.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ programs, however, and result in error messages as shown here::
5353
>>> '2' + 2
5454
Traceback (most recent call last):
5555
File "<stdin>", line 1, in <module>
56-
TypeError: Can't convert 'int' object to str implicitly
56+
TypeError: can only concatenate str (not "int") to str
5757

5858
The last line of the error message indicates what happened. Exceptions come in
5959
different types, and the type is printed as part of the message: the types in

Lib/test/test_asyncio/test_events.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1971,10 +1971,11 @@ def test_subprocess_wait_no_same_group(self):
19711971
functools.partial(MySubprocessProtocol, self.loop),
19721972
'exit 7', stdin=None, stdout=None, stderr=None,
19731973
start_new_session=True)
1974-
_, proto = yield self.loop.run_until_complete(connect)
1974+
transp, proto = self.loop.run_until_complete(connect)
19751975
self.assertIsInstance(proto, MySubprocessProtocol)
19761976
self.loop.run_until_complete(proto.completed)
19771977
self.assertEqual(7, proto.returncode)
1978+
transp.close()
19781979

19791980
def test_subprocess_exec_invalid_args(self):
19801981
async def connect(**kwds):

Lib/test/test_float.py

+14
Original file line numberDiff line numberDiff line change
@@ -1468,6 +1468,20 @@ def test_from_hex(self):
14681468
self.identical(fromHex('0X1.0000000000001fp0'), 1.0+2*EPS)
14691469
self.identical(fromHex('0x1.00000000000020p0'), 1.0+2*EPS)
14701470

1471+
# Regression test for a corner-case bug reported in b.p.o. 44954
1472+
self.identical(fromHex('0x.8p-1074'), 0.0)
1473+
self.identical(fromHex('0x.80p-1074'), 0.0)
1474+
self.identical(fromHex('0x.81p-1074'), TINY)
1475+
self.identical(fromHex('0x8p-1078'), 0.0)
1476+
self.identical(fromHex('0x8.0p-1078'), 0.0)
1477+
self.identical(fromHex('0x8.1p-1078'), TINY)
1478+
self.identical(fromHex('0x80p-1082'), 0.0)
1479+
self.identical(fromHex('0x81p-1082'), TINY)
1480+
self.identical(fromHex('.8p-1074'), 0.0)
1481+
self.identical(fromHex('8p-1078'), 0.0)
1482+
self.identical(fromHex('-.8p-1074'), -0.0)
1483+
self.identical(fromHex('+8p-1078'), 0.0)
1484+
14711485
def test_roundtrip(self):
14721486
def roundtrip(x):
14731487
return fromHex(toHex(x))

Lib/test/test_statistics.py

+16
Original file line numberDiff line numberDiff line change
@@ -2263,6 +2263,22 @@ def test_special_values(self):
22632263
with self.assertRaises(ValueError):
22642264
geometric_mean([Inf, -Inf])
22652265

2266+
def test_mixed_int_and_float(self):
2267+
# Regression test for b.p.o. issue #28327
2268+
geometric_mean = statistics.geometric_mean
2269+
expected_mean = 3.80675409583932
2270+
values = [
2271+
[2, 3, 5, 7],
2272+
[2, 3, 5, 7.0],
2273+
[2, 3, 5.0, 7.0],
2274+
[2, 3.0, 5.0, 7.0],
2275+
[2.0, 3.0, 5.0, 7.0],
2276+
]
2277+
for v in values:
2278+
with self.subTest(v=v):
2279+
actual_mean = geometric_mean(v)
2280+
self.assertAlmostEqual(actual_mean, expected_mean, places=5)
2281+
22662282

22672283
class TestQuantiles(unittest.TestCase):
22682284

Lib/test/test_typing.py

-1
Original file line numberDiff line numberDiff line change
@@ -4929,7 +4929,6 @@ def test_special_attrs(self):
49294929
self.assertEqual(cls.__name__, name, str(cls))
49304930
self.assertEqual(cls.__qualname__, name, str(cls))
49314931
self.assertEqual(cls.__module__, 'typing', str(cls))
4932-
self.assertEqual(getattr(cls, '_name', name), name, str(cls))
49334932
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
49344933
s = pickle.dumps(cls, proto)
49354934
loaded = pickle.loads(s)

Lib/typing.py

+8-11
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ class Starship:
461461
be used with isinstance() or issubclass().
462462
"""
463463
item = _type_check(parameters, f'{self} accepts only single type.')
464-
return _GenericAlias(self, (item,), name="ClassVar")
464+
return _GenericAlias(self, (item,))
465465

466466
@_SpecialForm
467467
def Final(self, parameters):
@@ -482,7 +482,7 @@ class FastConnector(Connection):
482482
There is no runtime checking of these properties.
483483
"""
484484
item = _type_check(parameters, f'{self} accepts only single type.')
485-
return _GenericAlias(self, (item,), name="Final")
485+
return _GenericAlias(self, (item,))
486486

487487
@_SpecialForm
488488
def Union(self, parameters):
@@ -520,12 +520,9 @@ def Union(self, parameters):
520520
parameters = _remove_dups_flatten(parameters)
521521
if len(parameters) == 1:
522522
return parameters[0]
523-
524523
if len(parameters) == 2 and type(None) in parameters:
525-
name = "Optional"
526-
else:
527-
name = "Union"
528-
return _UnionGenericAlias(self, parameters, name=name)
524+
return _UnionGenericAlias(self, parameters, name="Optional")
525+
return _UnionGenericAlias(self, parameters)
529526

530527
@_SpecialForm
531528
def Optional(self, parameters):
@@ -570,7 +567,7 @@ def open_helper(file: str, mode: MODE) -> str:
570567
except TypeError: # unhashable parameters
571568
pass
572569

573-
return _LiteralGenericAlias(self, parameters, name="Literal")
570+
return _LiteralGenericAlias(self, parameters)
574571

575572

576573
@_SpecialForm
@@ -609,7 +606,7 @@ def Concatenate(self, parameters):
609606
"ParamSpec variable.")
610607
msg = "Concatenate[arg, ...]: each arg must be a type."
611608
parameters = tuple(_type_check(p, msg) for p in parameters)
612-
return _ConcatenateGenericAlias(self, parameters, name="Concatenate")
609+
return _ConcatenateGenericAlias(self, parameters)
613610

614611

615612
@_SpecialForm
@@ -657,7 +654,7 @@ def is_str(val: Union[str, float]):
657654
PEP 647 (User-Defined Type Guards).
658655
"""
659656
item = _type_check(parameters, f'{self} accepts only single type.')
660-
return _GenericAlias(self, (item,), name="TypeGuard")
657+
return _GenericAlias(self, (item,))
661658

662659

663660
class ForwardRef(_Final, _root=True):
@@ -962,7 +959,7 @@ def __mro_entries__(self, bases):
962959

963960
def __getattr__(self, attr):
964961
if attr in {'__name__', '__qualname__'}:
965-
return self._name
962+
return self._name or self.__origin__.__name__
966963

967964
# We are careful for copy and pickle.
968965
# Also for simplicity we just don't relay all dunder names

Lib/unittest/case.py

+50-52
Original file line numberDiff line numberDiff line change
@@ -557,73 +557,71 @@ def _callCleanup(self, function, /, *args, **kwargs):
557557
function(*args, **kwargs)
558558

559559
def run(self, result=None):
560-
orig_result = result
561560
if result is None:
562561
result = self.defaultTestResult()
563562
startTestRun = getattr(result, 'startTestRun', None)
563+
stopTestRun = getattr(result, 'stopTestRun', None)
564564
if startTestRun is not None:
565565
startTestRun()
566+
else:
567+
stopTestRun = None
566568

567569
result.startTest(self)
568-
569-
testMethod = getattr(self, self._testMethodName)
570-
if (getattr(self.__class__, "__unittest_skip__", False) or
571-
getattr(testMethod, "__unittest_skip__", False)):
572-
# If the class or method was skipped.
573-
try:
570+
try:
571+
testMethod = getattr(self, self._testMethodName)
572+
if (getattr(self.__class__, "__unittest_skip__", False) or
573+
getattr(testMethod, "__unittest_skip__", False)):
574+
# If the class or method was skipped.
574575
skip_why = (getattr(self.__class__, '__unittest_skip_why__', '')
575576
or getattr(testMethod, '__unittest_skip_why__', ''))
576577
self._addSkip(result, self, skip_why)
577-
finally:
578-
result.stopTest(self)
579-
return
580-
expecting_failure_method = getattr(testMethod,
581-
"__unittest_expecting_failure__", False)
582-
expecting_failure_class = getattr(self,
583-
"__unittest_expecting_failure__", False)
584-
expecting_failure = expecting_failure_class or expecting_failure_method
585-
outcome = _Outcome(result)
586-
try:
587-
self._outcome = outcome
578+
return
579+
580+
expecting_failure = (
581+
getattr(self, "__unittest_expecting_failure__", False) or
582+
getattr(testMethod, "__unittest_expecting_failure__", False)
583+
)
584+
outcome = _Outcome(result)
585+
try:
586+
self._outcome = outcome
588587

589-
with outcome.testPartExecutor(self):
590-
self._callSetUp()
591-
if outcome.success:
592-
outcome.expecting_failure = expecting_failure
593-
with outcome.testPartExecutor(self, isTest=True):
594-
self._callTestMethod(testMethod)
595-
outcome.expecting_failure = False
596588
with outcome.testPartExecutor(self):
597-
self._callTearDown()
598-
599-
self.doCleanups()
600-
for test, reason in outcome.skipped:
601-
self._addSkip(result, test, reason)
602-
self._feedErrorsToResult(result, outcome.errors)
603-
if outcome.success:
604-
if expecting_failure:
605-
if outcome.expectedFailure:
606-
self._addExpectedFailure(result, outcome.expectedFailure)
589+
self._callSetUp()
590+
if outcome.success:
591+
outcome.expecting_failure = expecting_failure
592+
with outcome.testPartExecutor(self, isTest=True):
593+
self._callTestMethod(testMethod)
594+
outcome.expecting_failure = False
595+
with outcome.testPartExecutor(self):
596+
self._callTearDown()
597+
598+
self.doCleanups()
599+
for test, reason in outcome.skipped:
600+
self._addSkip(result, test, reason)
601+
self._feedErrorsToResult(result, outcome.errors)
602+
if outcome.success:
603+
if expecting_failure:
604+
if outcome.expectedFailure:
605+
self._addExpectedFailure(result, outcome.expectedFailure)
606+
else:
607+
self._addUnexpectedSuccess(result)
607608
else:
608-
self._addUnexpectedSuccess(result)
609-
else:
610-
result.addSuccess(self)
611-
return result
609+
result.addSuccess(self)
610+
return result
611+
finally:
612+
# explicitly break reference cycles:
613+
# outcome.errors -> frame -> outcome -> outcome.errors
614+
# outcome.expectedFailure -> frame -> outcome -> outcome.expectedFailure
615+
outcome.errors.clear()
616+
outcome.expectedFailure = None
617+
618+
# clear the outcome, no more needed
619+
self._outcome = None
620+
612621
finally:
613622
result.stopTest(self)
614-
if orig_result is None:
615-
stopTestRun = getattr(result, 'stopTestRun', None)
616-
if stopTestRun is not None:
617-
stopTestRun()
618-
619-
# explicitly break reference cycles:
620-
# outcome.errors -> frame -> outcome -> outcome.errors
621-
# outcome.expectedFailure -> frame -> outcome -> outcome.expectedFailure
622-
outcome.errors.clear()
623-
outcome.expectedFailure = None
624-
625-
# clear the outcome, no more needed
626-
self._outcome = None
623+
if stopTestRun is not None:
624+
stopTestRun()
627625

628626
def doCleanups(self):
629627
"""Execute all cleanup functions. Normally called for you after

0 commit comments

Comments
 (0)